Class: Triangular::Point

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

Direct Known Subclasses

Vector

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(x, y, z) ⇒ Point

Returns a new instance of Point.



6
7
8
9
10
# File 'lib/triangular/point.rb', line 6

def initialize(x, y, z)
  @x = x
  @y = y
  @z = z      
end

Instance Attribute Details

#xObject

Returns the value of attribute x.



4
5
6
# File 'lib/triangular/point.rb', line 4

def x
  @x
end

#yObject

Returns the value of attribute y.



4
5
6
# File 'lib/triangular/point.rb', line 4

def y
  @y
end

#zObject

Returns the value of attribute z.



4
5
6
# File 'lib/triangular/point.rb', line 4

def z
  @z
end

Class Method Details

.parse(string) ⇒ Object



27
28
29
30
31
32
# File 'lib/triangular/point.rb', line 27

def self.parse(string)
  string.strip!
  match_data = string.match(self.pattern)
  
  self.new(match_data[:x].to_f, match_data[:y].to_f, match_data[:z].to_f)
end

.patternObject



34
35
36
# File 'lib/triangular/point.rb', line 34

def self.pattern
  /(?<x>-?\d+.\d+(e\-?\d+)?)\s(?<y>-?\d+.\d+(e\-?\d+)?)\s(?<z>-?\d+.\d+(e\-?\d+)?)/
end

Instance Method Details

#==(other) ⇒ Object



22
23
24
25
# File 'lib/triangular/point.rb', line 22

def ==(other)
  return false unless other.is_a?(Point)
  self.x == other.x && self.y == other.y && self.z == other.z
end

#to_sObject



12
13
14
# File 'lib/triangular/point.rb', line 12

def to_s
  "#{@x.to_f} #{@y.to_f} #{@z.to_f}"
end

#translate!(x, y, z) ⇒ Object



16
17
18
19
20
# File 'lib/triangular/point.rb', line 16

def translate!(x, y, z)
  @x += x
  @y += y
  @z += z
end