class Laser::Cutter::Geometry::Rect

Attributes

sides[RW]
vertices[RW]

Public Class Methods

[](p1, p2) click to toggle source
# File lib/laser-cutter/geometry/shape/rect.rb, line 8
def self.[] p1, p2
  Rect.new(p1, p2)
end
create(point, w, h, name = nil) click to toggle source
# File lib/laser-cutter/geometry/shape/rect.rb, line 12
def self.create(point, w, h, name = nil)
  r = Rect.new(point, Point[point.x + w, point.y + h])
  r.name = name
  r
end
from_line(line) click to toggle source
# File lib/laser-cutter/geometry/shape/rect.rb, line 18
def self.from_line(line)
  Rect.new(line.p1, line.p2)
end
new(*args) click to toggle source
Calls superclass method Laser::Cutter::Geometry::Line::new
# File lib/laser-cutter/geometry/shape/rect.rb, line 22
def initialize(*args)
  super(*args)
  relocate!
end

Public Instance Methods

h() click to toggle source
# File lib/laser-cutter/geometry/shape/rect.rb, line 45
def h
  p2.y - p1.y
end
relocate!() click to toggle source
Calls superclass method Laser::Cutter::Geometry::Line#relocate!
# File lib/laser-cutter/geometry/shape/rect.rb, line 27
def relocate!
  super
  self.vertices = []
  vertices << p1
  vertices << p1.plus(w, 0)
  vertices << p2
  vertices << p1.plus(0, h)
  self.sides = []
  vertices.each_with_index do |v, index|
    sides << Line.new(v, vertices[(index + 1) % vertices.size])
  end
  self
end
to_a() click to toggle source
# File lib/laser-cutter/geometry/shape/rect.rb, line 53
def to_a
  [[p1.x, p1.y], [p2.x, p2.y]]
end
to_s() click to toggle source
# File lib/laser-cutter/geometry/shape/rect.rb, line 49
def to_s
  "#{sprintf "%3d", w}(w)x#{sprintf "%3d", h}(h) @ #{position.to_s}"
end
w() click to toggle source
# File lib/laser-cutter/geometry/shape/rect.rb, line 41
def w
  p2.x - p1.x
end