Class: Metro::Units::Point

Inherits:
Struct
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from CalculationValidations

#*, #+, #-, #calculate, #check_calculation_requirements

Instance Attribute Details

#xObject

Returns the value of attribute x

Returns:

  • (Object)

    the current value of x



7
8
9
# File 'lib/metro/units/point.rb', line 7

def x
  @x
end

#yObject

Returns the value of attribute y

Returns:

  • (Object)

    the current value of y



7
8
9
# File 'lib/metro/units/point.rb', line 7

def y
  @y
end

#zObject Also known as: z_order

Returns the value of attribute z

Returns:

  • (Object)

    the current value of 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

.zeroObject

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_sObject



39
40
41
# File 'lib/metro/units/point.rb', line 39

def to_s
  "#{x},#{y},#{z}"
end