Class: Laser::Cutter::Sloped::Placement

Inherits:
Object
  • Object
show all
Defined in:
lib/laser/cutter/sloped/placement.rb

Overview

Where a panel goes on the sheet: its own origin moved to a point, and the panel turned over within its own size when asked. Flipping x draws the mirror image, which the second side wall is; flipping both turns the panel half way round.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(origin, size:, flip_x: false, flip_y: false) ⇒ Placement

Returns a new instance of Placement.

Parameters:

  • origin (Geometry::Point) —

    where the origin of the panel lands

  • size (Array(Numeric, Numeric)) —

    the width and length a flip turns the panel within

  • flip_x (Boolean) (defaults to: false) —

    whether x runs from the far side back

  • flip_y (Boolean) (defaults to: false) —

    whether y runs from the far side back



18
19
20
21
22
23
24
# File 'lib/laser/cutter/sloped/placement.rb', line 18

def initialize(origin, size:, flip_x: false, flip_y: false)
  @origin = origin.clone
  @size = size.map(&:to_f).freeze
  @flip_x = flip_x
  @flip_y = flip_y
  freeze
end

Instance Attribute Details

#origin ⇒ Geometry::Point (readonly)

Returns where the origin of the panel lands.

Returns:



12
13
14
# File 'lib/laser/cutter/sloped/placement.rb', line 12

def origin
  @origin
end

Instance Method Details

#apply(point) ⇒ Geometry::Point

Returns on the sheet.

Parameters:

Returns:



28
29
30
31
32
# File 'lib/laser/cutter/sloped/placement.rb', line 28

def apply(point)
  x = @flip_x ? @size[0] - point.x : point.x
  y = @flip_y ? @size[1] - point.y : point.y
  Geometry::Point[@origin.x + x, @origin.y + y]
end