Class: Transform
- Inherits:
-
Object
- Object
- Transform
- Defined in:
- lib/transform.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#origin ⇒ Object
Returns the value of attribute origin.
-
#scale ⇒ Object
Returns the value of attribute scale.
Instance Method Summary collapse
- #apply(p) ⇒ Object
-
#initialize(scale, origin) ⇒ Transform
constructor
A new instance of Transform.
- #signed ⇒ Object
- #unapply(p) ⇒ Object
Constructor Details
#initialize(scale, origin) ⇒ Transform
Returns a new instance of Transform.
3 4 5 6 |
# File 'lib/transform.rb', line 3 def initialize(scale, origin) @origin = origin @scale = scale end |
Instance Attribute Details
#origin ⇒ Object
Returns the value of attribute origin.
2 3 4 |
# File 'lib/transform.rb', line 2 def origin @origin end |
#scale ⇒ Object
Returns the value of attribute scale.
2 3 4 |
# File 'lib/transform.rb', line 2 def scale @scale end |
Instance Method Details
#apply(p) ⇒ Object
8 9 10 |
# File 'lib/transform.rb', line 8 def apply(p) { :x => @origin[:x] + p[:x] * @scale[:x], :y => @origin[:y] + p[:y] * @scale[:y]} end |
#signed ⇒ Object
16 17 18 |
# File 'lib/transform.rb', line 16 def signed Transform.new({:x => (@scale[:x]<=>0.0).to_i, :y => (@scale[:y]<=>0.0).to_i}, @origin) end |
#unapply(p) ⇒ Object
12 13 14 |
# File 'lib/transform.rb', line 12 def unapply(p) { :x => (p[:x] - @origin[:x]) / @scale[:x], :y => (p[:y] - @origin[:y]) / @scale[:y]} end |