Class: Mageo::Axes
- Inherits:
-
Object
- Object
- Mageo::Axes
- Defined in:
- lib/mageo/axes.rb
Overview
n 次元空間における座標系を表現する n 本のベクトルを扱うクラス。
Defined Under Namespace
Classes: InitializeError
Instance Attribute Summary collapse
-
#axes ⇒ Object
readonly
Returns the value of attribute axes.
Class Method Summary collapse
-
.dependent?(axes) ⇒ Boolean
Return true is the vector is not independent.
- .independent?(axes) ⇒ Boolean
Instance Method Summary collapse
-
#==(other) ⇒ Object
Check equal.
-
#[](index) ⇒ Object
Item access for three axes in cartesian coordinates.
- #dependent? ⇒ Boolean
-
#each ⇒ Object
Iterate each vector of axes.
- #independent? ⇒ Boolean
-
#initialize(vectors) ⇒ Axes
constructor
要素数が nxn でなければ例外。0x0 も例外。 角各要素は to_f メソッドを持たなければならない。.
-
#size ⇒ Object
Return a number of vectors in axes, always three.
-
#to_a ⇒ Object
Convert to Array.
Constructor Details
#initialize(vectors) ⇒ Axes
要素数が nxn でなければ例外。0x0 も例外。 角各要素は to_f メソッドを持たなければならない。
13 14 15 16 17 18 19 20 21 |
# File 'lib/mageo/axes.rb', line 13 def initialize(vectors) raise InitializeError if vectors.size == 0 @axes = vectors.map{|vector| Vector[*vector]} #raise InitializeError unless @axes.regular? # この判定はうまくいかない。バグ? @axes.each do |vector| raise InitializeError unless @axes.size == vector.size end end |
Instance Attribute Details
#axes ⇒ Object (readonly)
Returns the value of attribute axes.
6 7 8 |
# File 'lib/mageo/axes.rb', line 6 def axes @axes end |
Class Method Details
.dependent?(axes) ⇒ Boolean
Return true is the vector is not independent.
28 29 30 |
# File 'lib/mageo/axes.rb', line 28 def self.dependent?(axes) return ! (self.independent?(axes)) end |
.independent?(axes) ⇒ Boolean
23 24 25 |
# File 'lib/mageo/axes.rb', line 23 def self.independent?(axes) return Matrix[* axes.map{|i| i.to_a}].regular? end |
Instance Method Details
#==(other) ⇒ Object
Check equal. Usually, this method should not be used, except for tests.
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/mageo/axes.rb', line 40 def ==(other) result = true size.times do |i| size.times do |j| result = false if @axes[i][j] != other.axes[i][j] end end return result end |
#[](index) ⇒ Object
Item access for three axes in cartesian coordinates. Note: []= method is not provided.
70 71 72 |
# File 'lib/mageo/axes.rb', line 70 def [](index) @axes[ index ] end |
#dependent? ⇒ Boolean
51 52 53 |
# File 'lib/mageo/axes.rb', line 51 def dependent? self.class.dependent?(@axes) end |
#each ⇒ Object
Iterate each vector of axes.
75 76 77 |
# File 'lib/mageo/axes.rb', line 75 def each @axes.each { |i| yield(i) } end |
#independent? ⇒ Boolean
55 56 57 |
# File 'lib/mageo/axes.rb', line 55 def independent? self.class.independent?(@axes) end |
#size ⇒ Object
Return a number of vectors in axes, always three. Mimic for Array.
34 35 36 |
# File 'lib/mageo/axes.rb', line 34 def size return @axes.size end |
#to_a ⇒ Object
Convert to Array. Non-destructive.
80 81 82 83 84 85 86 87 |
# File 'lib/mageo/axes.rb', line 80 def to_a result = [ @axes[0].to_a, @axes[1].to_a, @axes[2].to_a, ] return result end |