class Dieses::Geometry::Line

Attributes

ending[R]
equation[R]
starting[R]

Public Class Methods

new(starting, ending) click to toggle source
Calls superclass method Dieses::Geometry::Element::new
# File lib/dieses/geometry/line.rb, line 14
def initialize(starting, ending)
  @starting, @ending = Point.cast(starting), Point.cast(ending)
  @equation = Equation.from_line(self)

  super()
end

Public Instance Methods

bbox() click to toggle source
# File lib/dieses/geometry/line.rb, line 62
def bbox
  BoundingBox.new([starting, ending].min, [starting, ending].max)
end
duplicate(x: nil, y: nil, count: 1) click to toggle source
# File lib/dieses/geometry/line.rb, line 26
def duplicate(x: nil, y: nil, count: 1)
  lines, line = [], self

  count.times do
    lines << line
    line = line.translate(x: x, y: y)
  end

  [lines, line]
end
duplicates(x: nil, y: nil, count: 1) click to toggle source
# File lib/dieses/geometry/line.rb, line 37
def duplicates(x: nil, y: nil, count: 1)
  lines, = duplicate(x: x, y: y, count: count)
  lines
end
onto?(point) click to toggle source
# File lib/dieses/geometry/line.rb, line 42
def onto?(point)
  equation.onto?(point) && point >= starting && point <= ending
end
to_h() click to toggle source
# File lib/dieses/geometry/line.rb, line 58
def to_h
  { starting: starting, ending: ending }
end
to_s() click to toggle source
# File lib/dieses/geometry/line.rb, line 54
def to_s
  "L(#{starting}, #{ending})"
end
to_svgf() click to toggle source
# File lib/dieses/geometry/line.rb, line 46
      def to_svgf
        x1, y1, x2, y2 = [*starting.to_a, *ending.to_a].map { |value| Support.approx(value) }

        <<~SVG
          <line x1="#{x1}" y1="#{y1}" x2="#{x2}" y2="#{y2}" %{attributes}/>
        SVG
      end
translate(x: nil, y: nil) click to toggle source
# File lib/dieses/geometry/line.rb, line 21
def translate(x: nil, y: nil)
  starting, ending = [self.starting, self.ending].map { |point| point.translate(x: x, y: y) }
  self.class.new starting, ending
end