Class: Laser::Cutter::Geometry::Transform
- Inherits:
-
Object
- Object
- Laser::Cutter::Geometry::Transform
- Defined in:
- lib/laser/cutter/geometry/transform.rb
Overview
A rotation followed by a move, from a local frame into the page.
Notches are drawn along the x axis of a local frame, where every side is horizontal and the axis-aligned notching code applies unchanged. A Transform then turns and moves the result onto a side at any angle.
Instance Attribute Summary collapse
-
#angle ⇒ Float
readonly
The turn, in radians, counter-clockwise.
-
#origin ⇒ Point
readonly
Where the local origin lands.
Class Method Summary collapse
-
.along(from, to) ⇒ Transform
The frame whose x axis runs from one point towards another, with its origin on the first.
Instance Method Summary collapse
-
#apply(shape) ⇒ Point, Line
A new shape, on the page.
-
#initialize(origin, angle) ⇒ Transform
constructor
A new instance of Transform.
Constructor Details
#initialize(origin, angle) ⇒ Transform
Returns a new instance of Transform.
30 31 32 33 34 35 36 |
# File 'lib/laser/cutter/geometry/transform.rb', line 30 def initialize(origin, angle) @origin = origin.clone.freeze @angle = angle.to_f @cos = Math.cos(@angle) @sin = Math.sin(@angle) freeze end |
Instance Attribute Details
#angle ⇒ Float (readonly)
Returns the turn, in radians, counter-clockwise.
16 17 18 |
# File 'lib/laser/cutter/geometry/transform.rb', line 16 def angle @angle end |
#origin ⇒ Point (readonly)
Returns where the local origin lands.
13 14 15 |
# File 'lib/laser/cutter/geometry/transform.rb', line 13 def origin @origin end |
Class Method Details
.along(from, to) ⇒ Transform
The frame whose x axis runs from one point towards another, with its origin on the first. Its y axis points to the left of that run.
24 25 26 |
# File 'lib/laser/cutter/geometry/transform.rb', line 24 def self.along(from, to) new(from, Math.atan2(to.y - from.y, to.x - from.x)) end |
Instance Method Details
#apply(shape) ⇒ Point, Line
Returns a new shape, on the page.
40 41 42 43 44 45 46 |
# File 'lib/laser/cutter/geometry/transform.rb', line 40 def apply(shape) case shape when Line then Line.new(apply(shape.p1), apply(shape.p2)) when Point then Point[origin.x + (shape.x * @cos) - (shape.y * @sin), origin.y + (shape.x * @sin) + (shape.y * @cos)] else raise ArgumentError, "cannot transform #{shape.class}" end end |