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.
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
#x ⇒ Object
Returns the value of attribute x.
4 5 6 |
# File 'lib/triangular/point.rb', line 4 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
4 5 6 |
# File 'lib/triangular/point.rb', line 4 def y @y end |
#z ⇒ Object
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 |
.pattern ⇒ Object
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_s ⇒ Object
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 |