Class: Laser::Cutter::Geometry::Shape

Inherits:
Object
  • Object
show all
Defined in:
lib/laser/cutter/geometry/shape.rb

Overview

The base of a shape that sits at a position and can be moved there.

Direct Known Subclasses

Line

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#name ⇒ String, ...

Returns the name of the shape, such as the face of a box.

Returns:

  • (String, Symbol, nil) —

    the name of the shape, such as the face of a box



10
# File 'lib/laser/cutter/geometry/shape.rb', line 10

attr_accessor :position, :name

#position ⇒ Point

Returns where the shape sits, the origin until set.

Returns:

  • (Point) —

    where the shape sits, the origin until set



10
11
12
# File 'lib/laser/cutter/geometry/shape.rb', line 10

def position
  @position
end

Instance Method Details

#move_to(new_point) ⇒ Shape

Moves the shape so that its position is the point.

Parameters:

Returns:



43
44
45
46
47
# File 'lib/laser/cutter/geometry/shape.rb', line 43

def move_to(new_point)
  self.position = new_point
  relocate!
  self
end

#relocate! ⇒ void

This method returns an undefined value.

Moves the shape's own coordinates to its position. Each shape implements it.

Raises:

  • (RuntimeError) —

    when the shape does not implement it



54
55
56
# File 'lib/laser/cutter/geometry/shape.rb', line 54

def relocate!
  raise 'Abstract method'
end

#x ⇒ Float

Returns the x of the position.

Returns:

  • (Float) —

    the x of the position



24
25
26
# File 'lib/laser/cutter/geometry/shape.rb', line 24

def x
  position.x
end

#x=(value) ⇒ Float

Returns the value.

Parameters:

  • value (Float) —

    the new x of the position

Returns:

  • (Float) —

    the value



19
20
21
# File 'lib/laser/cutter/geometry/shape.rb', line 19

def x=(value)
  position.x = value
end

#y ⇒ Float

Returns the y of the position.

Returns:

  • (Float) —

    the y of the position



35
36
37
# File 'lib/laser/cutter/geometry/shape.rb', line 35

def y
  position.y
end

#y=(value) ⇒ Float

Returns the value.

Parameters:

  • value (Float) —

    the new y of the position

Returns:

  • (Float) —

    the value



30
31
32
# File 'lib/laser/cutter/geometry/shape.rb', line 30

def y=(value)
  position.y = value
end