module Dieses::Application::Pen::Draw::Elements

Public Instance Methods

cline(*tags, angle:, style: Undefined) click to toggle source
# File lib/dieses/application/pen.rb, line 74
def cline(*tags, angle:, style: Undefined)
  add perfect.intersect(Geometry::Equation.slant_from_direction(point: pos, angle: -angle)), tags, style
end
hline(*tags, length: Undefined, style: Undefined) click to toggle source
# File lib/dieses/application/pen.rb, line 64
def hline(*tags, length: Undefined, style: Undefined)
  length = Undefined.equal?(length) ? perfect.width : ruler.measure(length)
  add Geometry::Line.new(pos, pos.translate(x: length)), tags, style
end
rect(*tags, width:, height:, style: Undefined) click to toggle source
# File lib/dieses/application/pen.rb, line 78
def rect(*tags, width:, height:, style: Undefined)
  width, height = ruler.measure(width), ruler.measure(height)
  style = { fill: 'none' }.merge Undefined.default(style, EMPTY_HASH).to_h
  add Geometry::Rect.new(width, height, position: pos), tags, style
end
square(*tags, width:, style: Undefined) click to toggle source
# File lib/dieses/application/pen.rb, line 84
def square(*tags, width:, style: Undefined)
  rect(tags, width: width, height: width, style: style)
end
vline(*tags, length: Undefined, style: Undefined) click to toggle source
# File lib/dieses/application/pen.rb, line 69
def vline(*tags, length: Undefined, style: Undefined)
  length = Undefined.equal?(length) ? perfect.height : ruler.measure(length)
  add Geometry::Line.new(pos, pos.translate(y: length)), tags, style
end

Private Instance Methods

add(element, tags, style) click to toggle source
# File lib/dieses/application/pen.rb, line 90
def add(element, tags, style)
  raise Offsite unless element && perfect.cover?(element)

  element.tap do
    buffer << element.classify(tags, **Undefined.default(style, EMPTY_HASH).to_h)
  end
end
put() click to toggle source
# File lib/dieses/application/pen.rb, line 98
def put
  canvas.tap do
    buffer.each { |element| canvas << element }
  end
end