Class: Triangular::Point
- Inherits:
-
Object
- Object
- Triangular::Point
- Defined in:
- lib/triangular/point.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
-
#z ⇒ Object
Returns the value of attribute z.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(x, y, z) ⇒ Point
constructor
A new instance of Point.
- #to_s ⇒ Object
- #translate!(x, y, z) ⇒ Object
Constructor Details
#initialize(x, y, z) ⇒ Point
Returns a new instance of Point.
7 8 9 10 11 |
# File 'lib/triangular/point.rb', line 7 def initialize(x, y, z) @x = x @y = y @z = z end |
Instance Attribute Details
#x ⇒ Object
Returns the value of attribute x.
5 6 7 |
# File 'lib/triangular/point.rb', line 5 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
5 6 7 |
# File 'lib/triangular/point.rb', line 5 def y @y end |
#z ⇒ Object
Returns the value of attribute z.
5 6 7 |
# File 'lib/triangular/point.rb', line 5 def z @z end |
Class Method Details
.parse(string) ⇒ Object
29 30 31 32 33 |
# File 'lib/triangular/point.rb', line 29 def self.parse(string) match_data = string.strip.match(pattern) new(match_data[:x].to_f, match_data[:y].to_f, match_data[:z].to_f) end |
.pattern ⇒ Object
35 36 37 |
# File 'lib/triangular/point.rb', line 35 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
23 24 25 26 27 |
# File 'lib/triangular/point.rb', line 23 def ==(other) return false unless other.is_a?(Point) x == other.x && y == other.y && z == other.z end |
#to_s ⇒ Object
13 14 15 |
# File 'lib/triangular/point.rb', line 13 def to_s "#{@x.to_f} #{@y.to_f} #{@z.to_f}" end |
#translate!(x, y, z) ⇒ Object
17 18 19 20 21 |
# File 'lib/triangular/point.rb', line 17 def translate!(x, y, z) @x += x @y += y @z += z end |