Class: Draught::Path

Inherits:
Object
  • Object
show all
Includes:
Boxlike, Pathlike
Defined in:
lib/draught/path.rb

Constant Summary

Constants included from Boxlike

Boxlike::POSITION_METHODS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Pathlike

#==, #approximates?, #box_type, #containers, #empty?, #first, #last, #number_of_points, #paths

Methods included from Boxlike

#bottom_edge, #box_type, #centre, #centre_left, #centre_right, #containers, #corners, #disjoint?, #include_point?, #left_edge, #lower_centre, #lower_right, #min_gap, #move_to, #overlaps?, #paths, #right_edge, #top_edge, #upper_centre, #upper_left, #upper_right

Constructor Details

#initialize(points = []) ⇒ Path

Returns a new instance of Path.



12
13
14
# File 'lib/draught/path.rb', line 12

def initialize(points = [])
  @points = points.dup.freeze
end

Instance Attribute Details

#pointsObject (readonly)

Returns the value of attribute points.



10
11
12
# File 'lib/draught/path.rb', line 10

def points
  @points
end

Instance Method Details

#<<(point) ⇒ Object



16
17
18
# File 'lib/draught/path.rb', line 16

def <<(point)
  append(point)
end

#[](index_start_or_range, length = nil) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# 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) ⇒ Object



20
21
22
# 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

#heightObject



53
54
55
# File 'lib/draught/path.rb', line 53

def height
  @height ||= y_max - y_min
end

#lower_leftObject



45
46
47
# File 'lib/draught/path.rb', line 45

def lower_left
  @lower_left ||= Point.new(x_min, y_min)
end

#prepend(*paths_or_points) ⇒ Object



24
25
26
27
28
# 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) ⇒ Object



61
62
63
# File 'lib/draught/path.rb', line 61

def transform(transformer)
  self.class.new(points.map { |p| p.transform(transformer) })
end

#translate(vector) ⇒ Object



57
58
59
# File 'lib/draught/path.rb', line 57

def translate(vector)
  self.class.new(points.map { |p| p.translate(vector) })
end

#widthObject



49
50
51
# File 'lib/draught/path.rb', line 49

def width
  @width ||= x_max - x_min
end