Class: RTKIT::Coordinate
- Inherits:
-
Object
- Object
- RTKIT::Coordinate
- Defined in:
- lib/rtkit/coordinate.rb
Overview
Contains a X,Y,Z triplet, which along with other Coordinates, defines a Contour.
Relations
-
The Coordinate belongs to a Contour.
Instance Attribute Summary collapse
-
#contour ⇒ Object
readonly
The Contour that the Coordinate belongs to.
-
#x ⇒ Object
readonly
The X location (in units of mm).
-
#y ⇒ Object
readonly
The Y location (in units of mm).
-
#z ⇒ Object
readonly
The Z location (in units of mm).
Instance Method Summary collapse
-
#==(other) ⇒ Object
(also: #eql?)
Returns true if the argument is an instance with attributes equal to self.
-
#hash ⇒ Object
Generates a Fixnum hash value for this instance.
-
#initialize(x, y, z, contour = nil) ⇒ Coordinate
constructor
Creates a new Coordinate instance.
-
#to_coordinate ⇒ Object
Returns self.
-
#to_s ⇒ Object
Returns a string where the x, y & z values are separated by a ‘'.
Constructor Details
#initialize(x, y, z, contour = nil) ⇒ Coordinate
Creates a new Coordinate instance.
Parameters
-
x
– Float. The location of the Contour point along the x-axis (in units of mm). -
y
– Float. The location of the Contour point along the y-axis (in units of mm). -
z
– Float. The location of the Contour point along the z-axis (in units of mm). -
contour
– The Contour instance (if any) that this Coordinate belongs to.
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rtkit/coordinate.rb', line 29 def initialize(x, y, z, contour=nil) raise ArgumentError, "Invalid argument 'x'. Expected Float, got #{x.class}." unless x.is_a?(Float) raise ArgumentError, "Invalid argument 'y'. Expected Float, got #{y.class}." unless y.is_a?(Float) raise ArgumentError, "Invalid argument 'z'. Expected Float, got #{z.class}." unless z.is_a?(Float) raise ArgumentError, "Invalid argument 'contour'. Expected Contour (or nil), got #{contour.class}." if contour && !contour.is_a?(Contour) @contour = contour @x = x @y = y @z = z # Register ourselves with the Contour: @contour.add_coordinate(self) if contour end |
Instance Attribute Details
#contour ⇒ Object (readonly)
The Contour that the Coordinate belongs to.
12 13 14 |
# File 'lib/rtkit/coordinate.rb', line 12 def contour @contour end |
#x ⇒ Object (readonly)
The X location (in units of mm).
14 15 16 |
# File 'lib/rtkit/coordinate.rb', line 14 def x @x end |
#y ⇒ Object (readonly)
The Y location (in units of mm).
16 17 18 |
# File 'lib/rtkit/coordinate.rb', line 16 def y @y end |
#z ⇒ Object (readonly)
The Z location (in units of mm).
18 19 20 |
# File 'lib/rtkit/coordinate.rb', line 18 def z @z end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
Returns true if the argument is an instance with attributes equal to self.
44 45 46 47 48 |
# File 'lib/rtkit/coordinate.rb', line 44 def ==(other) if other.respond_to?(:to_coordinate) other.send(:state) == state end end |
#hash ⇒ Object
Generates a Fixnum hash value for this instance.
54 55 56 |
# File 'lib/rtkit/coordinate.rb', line 54 def hash state.hash end |
#to_coordinate ⇒ Object
Returns self.
60 61 62 |
# File 'lib/rtkit/coordinate.rb', line 60 def to_coordinate self end |
#to_s ⇒ Object
Returns a string where the x, y & z values are separated by a ‘'.
67 68 69 |
# File 'lib/rtkit/coordinate.rb', line 67 def to_s [@x, @y, @z].join("\\") end |