Method: RMath3D::RMtx2#initialize
- Defined in:
- lib/rmath3d/rmath3d_plain.rb
#initialize(*a) ⇒ RMtx2
call-seq:
RMtx2.new -> ((1,0),(0,1))
RMtx2.new(e) -> ((e,e), (e,e))
RMtx2.new( other ) : Copy Constructor
RMtx2.new( e0, e1, e2, e3 ) -> ((e0,e1), (e2,e3))
Creates a new 2x2 matrix.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/rmath3d/rmath3d_plain.rb', line 23 def initialize( *a ) # [NOTE] elemetns are stored in column-major order. @e = [] case a.length when 0 @e = [ 0.0, 0.0, 0.0, 0.0 ] when 1 case a[0] when Fixnum, Float @e = [ a[0], a[0], a[0], a[0] ] when RMtx2 # Copy Constructor @e = [ a[0].e00, a[0].e10, a[0].e01, a[0].e11 ] else raise TypeError, "RMtx2#initialize : Unknown type #{a[0].class}." return nil end when 4 # Element-wise setter for row in 0...2 do for col in 0...2 do index = 2*row + col case a[index] when Fixnum, Float setElement( row, col, a[index] ) else raise TypeError, "RMtx2#initialize : Unknown type #{a[0].class}." return nil end end end else raise RuntimeError, "RMtx2#initialize : wrong # of arguments (#{a.length})" return nil end return self end |