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
- #rotate(degree) ⇒ Object
- #to_a(dimension = 2) ⇒ Object
- #to_s(dimension = 2) ⇒ Object
- #zero? ⇒ Boolean
Instance Method Details
#<=>(o) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/rays/point.rb', line 46 def <=>(o) return nil unless 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
28 29 30 |
# File 'lib/rays/point.rb', line 28 def each(&block) to_a.each(&block) end |
#inspect ⇒ Object
53 54 55 |
# File 'lib/rays/point.rb', line 53 def inspect() "#<Rays::Point #{to_a(3).join ' '}>" end |
#move_by(*args) ⇒ Object
16 17 18 |
# File 'lib/rays/point.rb', line 16 def move_by(*args) dup.move_by!(*args) end |
#move_to(*args) ⇒ Object
12 13 14 |
# File 'lib/rays/point.rb', line 12 def move_to(*args) dup.move_to!(*args) end |
#rotate(degree) ⇒ Object
20 21 22 |
# File 'lib/rays/point.rb', line 20 def rotate(degree) dup.rotate!(degree) end |
#to_a(dimension = 2) ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/rays/point.rb', line 32 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
42 43 44 |
# File 'lib/rays/point.rb', line 42 def to_s(dimension = 2) to_a(dimension).to_s end |
#zero? ⇒ Boolean
24 25 26 |
# File 'lib/rays/point.rb', line 24 def zero?() length == 0 end |