Class: Geometry::Transformation::Composition
- Inherits:
-
Object
- Object
- Geometry::Transformation::Composition
- Defined in:
- lib/geometry/transformation/composition.rb
Instance Attribute Summary collapse
-
#transformations ⇒ Object
readonly
Returns the value of attribute transformations.
Accessors collapse
-
#has_rotation? ⇒ Boolean
!@attribute [r] has_rotation? @return [Bool] true if the transformation has any rotation components.
-
#size ⇒ Object
!@attribute [r] size @return [Number] the number of composed Geometry::Transformations.
Instance Method Summary collapse
- #+(other) ⇒ Object
-
#initialize(*args) ⇒ Composition
constructor
A new instance of Composition.
- #transform(point) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Composition
Returns a new instance of Composition.
6 7 8 9 |
# File 'lib/geometry/transformation/composition.rb', line 6 def initialize(*args) raise TypeError unless args.all? {|a| a.is_a? Transformation } @transformations = *args end |
Instance Attribute Details
#transformations ⇒ Object (readonly)
Returns the value of attribute transformations.
4 5 6 |
# File 'lib/geometry/transformation/composition.rb', line 4 def transformations @transformations end |
Instance Method Details
#+(other) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/geometry/transformation/composition.rb', line 11 def +(other) case other when Transformation Composition.new(*transformations, other) when Composition Composition.new(*transformations, *other.transformations) end end |
#has_rotation? ⇒ Boolean
!@attribute [r] has_rotation?
@return [Bool] true if the transformation has any rotation components
23 24 25 |
# File 'lib/geometry/transformation/composition.rb', line 23 def has_rotation? transformations.any? {|t| t.is_a?(Rotation) || t.has_rotation? } end |
#size ⇒ Object
!@attribute [r] size
@return [Number] the number of composed {Transformation}s
29 30 31 |
# File 'lib/geometry/transformation/composition.rb', line 29 def size transformations.size end |
#transform(point) ⇒ Object
34 35 36 |
# File 'lib/geometry/transformation/composition.rb', line 34 def transform(point) transformations.reverse.reduce(point) {|point, transformation| transformation.transform(point) } end |