Class: Emf::Model::Geometry::Matrix

Inherits:
Object
  • Object
show all
Defined in:
lib/emf/model/geometry/matrix.rb

Constant Summary collapse

IDENTITY =
{
  m11: 1.0, m12: 0.0, m21: 0.0, m22: 1.0, dx: 0.0, dy: 0.0
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(m11:, m12:, m21:, m22:, dx:, dy:) ⇒ Matrix

Returns a new instance of Matrix.



11
12
13
14
15
16
17
18
# File 'lib/emf/model/geometry/matrix.rb', line 11

def initialize(m11:, m12:, m21:, m22:, dx:, dy:)
  @m11 = m11.to_f
  @m12 = m12.to_f
  @m21 = m21.to_f
  @m22 = m22.to_f
  @dx = dx.to_f
  @dy = dy.to_f
end

Instance Attribute Details

#dxObject (readonly)

Returns the value of attribute dx.



20
21
22
# File 'lib/emf/model/geometry/matrix.rb', line 20

def dx
  @dx
end

#dyObject (readonly)

Returns the value of attribute dy.



20
21
22
# File 'lib/emf/model/geometry/matrix.rb', line 20

def dy
  @dy
end

#m11Object (readonly)

Returns the value of attribute m11.



20
21
22
# File 'lib/emf/model/geometry/matrix.rb', line 20

def m11
  @m11
end

#m12Object (readonly)

Returns the value of attribute m12.



20
21
22
# File 'lib/emf/model/geometry/matrix.rb', line 20

def m12
  @m12
end

#m21Object (readonly)

Returns the value of attribute m21.



20
21
22
# File 'lib/emf/model/geometry/matrix.rb', line 20

def m21
  @m21
end

#m22Object (readonly)

Returns the value of attribute m22.



20
21
22
# File 'lib/emf/model/geometry/matrix.rb', line 20

def m22
  @m22
end

Class Method Details

.from_wire(wire) ⇒ Object



22
23
24
# File 'lib/emf/model/geometry/matrix.rb', line 22

def self.from_wire(wire)
  new(m11: wire.m11, m12: wire.m12, m21: wire.m21, m22: wire.m22, dx: wire.dx, dy: wire.dy)
end

.identityObject



30
31
32
# File 'lib/emf/model/geometry/matrix.rb', line 30

def self.identity
  new(**IDENTITY)
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



38
39
40
41
42
43
# File 'lib/emf/model/geometry/matrix.rb', line 38

def ==(other)
  other.is_a?(self.class) &&
    m11 == other.m11 && m12 == other.m12 &&
    m21 == other.m21 && m22 == other.m22 &&
    dx == other.dx && dy == other.dy
end

#hashObject



46
47
48
# File 'lib/emf/model/geometry/matrix.rb', line 46

def hash
  [self.class, m11, m12, m21, m22, dx, dy].hash
end

#identity?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/emf/model/geometry/matrix.rb', line 34

def identity?
  m11 == 1.0 && m12 == 0.0 && m21 == 0.0 && m22 == 1.0 && dx == 0.0 && dy == 0.0
end

#to_wireObject



26
27
28
# File 'lib/emf/model/geometry/matrix.rb', line 26

def to_wire
  Binary::Types::XForm.new(m11: m11, m12: m12, m21: m21, m22: m22, dx: dx, dy: dy)
end