Class: Geom3d::Point
- Inherits:
-
Object
- Object
- Geom3d::Point
- Defined in:
- lib/geom3d/point.rb
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.
Instance Method Summary collapse
- #+(other) ⇒ Object
- #-(other) ⇒ Object
- #==(other) ⇒ Object
- #flatten ⇒ Object
-
#initialize(*args) ⇒ Point
constructor
A new instance of Point.
-
#to_ary ⇒ Object
Allows recursive flatten and multiple assignment to work with this class.
- #to_s ⇒ Object
Constructor Details
#initialize(*args) ⇒ Point
Returns a new instance of Point.
8 9 10 |
# File 'lib/geom3d/point.rb', line 8 def initialize *args @x, @y, @z = args.flatten end |
Instance Attribute Details
#x ⇒ Object
Returns the value of attribute x.
6 7 8 |
# File 'lib/geom3d/point.rb', line 6 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
6 7 8 |
# File 'lib/geom3d/point.rb', line 6 def y @y end |
#z ⇒ Object
Returns the value of attribute z.
6 7 8 |
# File 'lib/geom3d/point.rb', line 6 def z @z end |
Instance Method Details
#+(other) ⇒ Object
23 24 25 |
# File 'lib/geom3d/point.rb', line 23 def + other Point.new(@x + other.dx, @y + other.dy, @z + other.dz) end |
#-(other) ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/geom3d/point.rb', line 12 def - other case other when Point Vector.new(@x - other.x, @y - other.y, @z - other.z) when Vector Point.new(@x - other.dx, @y - other.dy, @z - other.dz) else throw ArgumentError end end |
#==(other) ⇒ Object
27 28 29 |
# File 'lib/geom3d/point.rb', line 27 def == other (@x - other.x) < EPS && (@y - other.y) < EPS && (@z - other.z) < EPS end |
#flatten ⇒ Object
40 41 42 |
# File 'lib/geom3d/point.rb', line 40 def flatten to_ary.flatten end |
#to_ary ⇒ Object
Allows recursive flatten and multiple assignment to work with this class
36 37 38 |
# File 'lib/geom3d/point.rb', line 36 def to_ary [@x, @y, @z] end |
#to_s ⇒ Object
31 32 33 |
# File 'lib/geom3d/point.rb', line 31 def to_s "Point3(%.3f,%.3f,%.3f)" % [@x, @y, @z] end |