Module: Vector2d::Transformations
Instance Method Summary collapse
- #ceil ⇒ Object
- #floor ⇒ Object
- #normalize ⇒ Object
- #perpendicular ⇒ Object
- #resize(new_length) ⇒ Object
- #reverse ⇒ Object
- #rotate(angle) ⇒ Object
- #round(digits = 0) ⇒ Object
- #truncate(max) ⇒ Object
Instance Method Details
#ceil ⇒ Object
12 13 14 |
# File 'lib/vector2d/transformations.rb', line 12 def ceil self.class.new(x.ceil, y.ceil) end |
#floor ⇒ Object
21 22 23 |
# File 'lib/vector2d/transformations.rb', line 21 def floor self.class.new(x.floor, y.floor) end |
#normalize ⇒ Object
32 33 34 |
# File 'lib/vector2d/transformations.rb', line 32 def normalize resize(1.0) end |
#perpendicular ⇒ Object
41 42 43 |
# File 'lib/vector2d/transformations.rb', line 41 def perpendicular Vector2d.new(-y, x) end |
#resize(new_length) ⇒ Object
50 51 52 |
# File 'lib/vector2d/transformations.rb', line 50 def resize(new_length) self * (new_length / self.length) end |
#reverse ⇒ Object
59 60 61 |
# File 'lib/vector2d/transformations.rb', line 59 def reverse self.class.new(-x, -y) end |
#rotate(angle) ⇒ Object
68 69 70 71 72 73 |
# File 'lib/vector2d/transformations.rb', line 68 def rotate(angle) Vector2d.new( x * Math.cos(angle) - y * Math.sin(angle), x * Math.sin(angle) + y * Math.cos(angle) ) end |
#round(digits = 0) ⇒ Object
81 82 83 |
# File 'lib/vector2d/transformations.rb', line 81 def round(digits=0) self.class.new(x.round(digits), y.round(digits)) end |
#truncate(max) ⇒ Object
92 93 94 |
# File 'lib/vector2d/transformations.rb', line 92 def truncate(max) resize([max, self.length].min) end |