Class: EpiMath::Point
- Inherits:
-
Object
- Object
- EpiMath::Point
- Defined in:
- lib/epimath100/point.class.rb
Instance Method Summary collapse
- #*(p) ⇒ Object
- #+(p) ⇒ Object
-
#initialize(x, y, z) ⇒ Point
constructor
A new instance of Point.
- #to_s ⇒ Object
- #x ⇒ Object
- #y ⇒ Object
- #z ⇒ Object
Constructor Details
#initialize(x, y, z) ⇒ Point
Returns a new instance of Point.
7 8 9 10 11 12 |
# File 'lib/epimath100/point.class.rb', line 7 def initialize x, y, z if !x.is_a?Numeric or !y.is_a?Numeric or !z.is_a?Numeric Error.call "Point::new : a passed argument is not a valid number" end @coord = {:x => x.to_f, :y => y.to_f, :z => z.to_f} end |
Instance Method Details
#*(p) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/epimath100/point.class.rb', line 28 def *(p) Error.call "Point::+ : passed argument is invalid" if !p.is_a?Numeric @coord.x *= p @coord.y *= p @coord.z *= p end |
#+(p) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/epimath100/point.class.rb', line 14 def +(p) if p.is_a?Point @coord.x += p.x @coord.y += p.y @coord.z += p.z elsif p.is_a?Numeric @coord.x += p @coord.y += p @coord.z += p else Error.call "Point::+ : passed argument is invalid" end end |
#to_s ⇒ Object
36 37 38 |
# File 'lib/epimath100/point.class.rb', line 36 def to_s "(#{self.x}; #{self.y}; #{self.z})" end |
#x ⇒ Object
40 41 42 |
# File 'lib/epimath100/point.class.rb', line 40 def x @coord[:x] end |
#y ⇒ Object
44 45 46 |
# File 'lib/epimath100/point.class.rb', line 44 def y @coord[:y] end |
#z ⇒ Object
48 49 50 |
# File 'lib/epimath100/point.class.rb', line 48 def z @coord[:z] end |