Class: Metro::Units::Point
- Inherits:
-
Struct
- Object
- Struct
- Metro::Units::Point
- Includes:
- CalculationValidations
- Defined in:
- lib/metro/units/point.rb
Overview
Represents and object that contains the x, y, and z position.
Instance Attribute Summary collapse
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
-
#z ⇒ Object
(also: #z_order)
Returns the value of attribute z.
Class Method Summary collapse
-
.at(x = 0.0, y = 0.0, z = 0.0) ⇒ Object
An alternate way of creating a point.
-
.parse(string) ⇒ Object
Parse a string representation of a point object.
-
.zero ⇒ Object
Generate a point at 0,0,0.
Instance Method Summary collapse
Methods included from CalculationValidations
#*, #+, #-, #calculate, #check_calculation_requirements
Instance Attribute Details
#x ⇒ Object
Returns the value of attribute x
7 8 9 |
# File 'lib/metro/units/point.rb', line 7 def x @x end |
#y ⇒ Object
Returns the value of attribute y
7 8 9 |
# File 'lib/metro/units/point.rb', line 7 def y @y end |
#z ⇒ Object Also known as: z_order
Returns the value of attribute z
7 8 9 |
# File 'lib/metro/units/point.rb', line 7 def z @z end |
Class Method Details
.at(x = 0.0, y = 0.0, z = 0.0) ⇒ Object
An alternate way of creating a point. Creation here converts all inputs to floating point and assumes that the z-value is zero (as this is a 2D universe).
22 23 24 |
# File 'lib/metro/units/point.rb', line 22 def self.at(x=0.0,y=0.0,z=0.0) new x.to_f, y.to_f, z.to_f end |
.parse(string) ⇒ Object
Parse a string representation of a point object. The supported formated is a comma-delimited string that contains either “x,y” or “x,y,z”.
31 32 33 |
# File 'lib/metro/units/point.rb', line 31 def self.parse(string) at *string.to_s.split(",",3).map(&:to_f) end |
.zero ⇒ Object
Generate a point at 0,0,0.
13 14 15 |
# File 'lib/metro/units/point.rb', line 13 def self.zero new 0.0, 0.0, 0.0 end |
Instance Method Details
#to_s ⇒ Object
39 40 41 |
# File 'lib/metro/units/point.rb', line 39 def to_s "#{x},#{y},#{z}" end |