Class: Transform

Inherits:
Object
  • Object
show all
Defined in:
lib/transform.rb

Direct Known Subclasses

SignedTransform

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#originObject

Returns the value of attribute origin.



2
3
4
# File 'lib/transform.rb', line 2

def origin
  @origin
end

#scaleObject

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

#signedObject



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