Class: Rays::Point

Inherits:
Object
  • Object
show all
Includes:
Comparable, Enumerable
Defined in:
lib/rays/point.rb

Instance Method Summary collapse

Instance Method Details

#<=>(o) ⇒ Object



42
43
44
45
46
47
# File 'lib/rays/point.rb', line 42

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



24
25
26
# File 'lib/rays/point.rb', line 24

def each(&block)
  to_a.each(&block)
end

#inspectObject



49
50
51
# File 'lib/rays/point.rb', line 49

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

#to_a(dimension = 2) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/rays/point.rb', line 28

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



38
39
40
# File 'lib/rays/point.rb', line 38

def to_s(dimension = 2)
  to_a(dimension).to_s
end

#zero?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/rays/point.rb', line 20

def zero?()
  length == 0
end