class Draught::Path

Attributes

points[R]

Public Class Methods

new(points = []) click to toggle source
# File lib/draught/path.rb, line 12
def initialize(points = [])
  @points = points.dup.freeze
end

Public Instance Methods

<<(point) click to toggle source
# File lib/draught/path.rb, line 16
def <<(point)
  append(point)
end
[](index_start_or_range, length = nil) click to toggle source
# File lib/draught/path.rb, line 30
def [](index_start_or_range, length = nil)
  if length.nil?
    case index_start_or_range
    when Range
      self.class.new(points[index_start_or_range])
    when Numeric
      points[index_start_or_range]
    else
      raise TypeError, "requires a Range or Numeric in single-arg form"
    end
  else
    self.class.new(points[index_start_or_range, length])
  end
end
append(*paths_or_points) click to toggle source
# File lib/draught/path.rb, line 20
def append(*paths_or_points)
  paths_or_points.inject(self) { |path, point_or_path| path.add_points(point_or_path.points) }
end
height() click to toggle source
# File lib/draught/path.rb, line 53
def height
  @height ||= y_max - y_min
end
lower_left() click to toggle source
# File lib/draught/path.rb, line 45
def lower_left
  @lower_left ||= Point.new(x_min, y_min)
end
prepend(*paths_or_points) click to toggle source
# File lib/draught/path.rb, line 24
def prepend(*paths_or_points)
  paths_or_points.inject(Path.new) { |path, point_or_path|
    path.add_points(point_or_path.points)
  }.add_points(self.points)
end
transform(transformer) click to toggle source
# File lib/draught/path.rb, line 61
def transform(transformer)
  self.class.new(points.map { |p| p.transform(transformer) })
end
translate(vector) click to toggle source
# File lib/draught/path.rb, line 57
def translate(vector)
  self.class.new(points.map { |p| p.translate(vector) })
end
width() click to toggle source
# File lib/draught/path.rb, line 49
def width
  @width ||= x_max - x_min
end

Protected Instance Methods

add_points(points) click to toggle source
# File lib/draught/path.rb, line 67
def add_points(points)
  self.class.new(@points + points)
end

Private Instance Methods

x_max() click to toggle source
# File lib/draught/path.rb, line 73
def x_max
  @x_max ||= points.map(&:x).max || 0
end
x_min() click to toggle source
# File lib/draught/path.rb, line 77
def x_min
  @x_min ||= points.map(&:x).min || 0
end
y_max() click to toggle source
# File lib/draught/path.rb, line 81
def y_max
  @y_max ||= points.map(&:y).max || 0
end
y_min() click to toggle source
# File lib/draught/path.rb, line 85
def y_min
  @y_min ||= points.map(&:y).min || 0
end