Class: RTKIT::Coordinate

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

Instance Method Summary collapse

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.

Raises:

  • (ArgumentError)


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

#contourObject (readonly)

The Contour that the Coordinate belongs to.



12
13
14
# File 'lib/rtkit/coordinate.rb', line 12

def contour
  @contour
end

#xObject (readonly)

The X location (in units of mm).



14
15
16
# File 'lib/rtkit/coordinate.rb', line 14

def x
  @x
end

#yObject (readonly)

The Y location (in units of mm).



16
17
18
# File 'lib/rtkit/coordinate.rb', line 16

def y
  @y
end

#zObject (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

#hashObject

Generates a Fixnum hash value for this instance.



54
55
56
# File 'lib/rtkit/coordinate.rb', line 54

def hash
  state.hash
end

#to_coordinateObject

Returns self.



60
61
62
# File 'lib/rtkit/coordinate.rb', line 60

def to_coordinate
  self
end

#to_sObject

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