Class: Rays::Point
- Inherits:
-
Object
- Object
- Rays::Point
- Includes:
- Comparable, Enumerable
- Defined in:
- lib/rays/point.rb
Instance Method Summary collapse
- #<=>(o) ⇒ Object
- #each(&block) ⇒ Object
- #inspect ⇒ Object
- #move_by(*args) ⇒ Object
- #move_to(*args) ⇒ Object
- #to_a(dimension = 2) ⇒ Object
- #to_s(dimension = 2) ⇒ Object
- #zero? ⇒ Boolean
Instance Method Details
#<=>(o) ⇒ Object
45 46 47 48 49 |
# File 'lib/rays/point.rb', line 45 def <=>(o) ret = x <=> o.x; return ret if ret != 0 ret = y <=> o.y; return ret if ret != 0 z <=> o.z end |
#each(&block) ⇒ Object
27 28 29 |
# File 'lib/rays/point.rb', line 27 def each(&block) to_a.each(&block) end |
#inspect ⇒ Object
51 52 53 |
# File 'lib/rays/point.rb', line 51 def inspect() "#<Rays::Point #{to_a(3).join ', '}>" end |
#move_by(*args) ⇒ Object
19 20 21 |
# File 'lib/rays/point.rb', line 19 def move_by(*args) dup.move_by!(*args) end |
#move_to(*args) ⇒ Object
15 16 17 |
# File 'lib/rays/point.rb', line 15 def move_to(*args) dup.move_to!(*args) end |
#to_a(dimension = 2) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/rays/point.rb', line 31 def to_a(dimension = 2) case dimension when 1 then [x] when 2 then [x, y] when 3 then [x, y, z] when 4 then [x, y, z, 1.0] else raise ArgumentError end end |
#to_s(dimension = 2) ⇒ Object
41 42 43 |
# File 'lib/rays/point.rb', line 41 def to_s(dimension = 2) to_a(dimension).to_s end |
#zero? ⇒ Boolean
23 24 25 |
# File 'lib/rays/point.rb', line 23 def zero?() length == 0 end |