Class: Draught::PathBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/draught/path_builder.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePathBuilder

Returns a new instance of PathBuilder.



26
27
28
# File 'lib/draught/path_builder.rb', line 26

def initialize
  @path = Path.new
end

Class Method Details

.build {|builder| ... } ⇒ Object

Yields:

  • (builder)


5
6
7
8
9
# File 'lib/draught/path_builder.rb', line 5

def self.build
  builder = new
  yield(builder)
  builder.send(:path)
end

.connect(*paths) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/draught/path_builder.rb', line 11

def self.connect(*paths)
  paths = paths.reject(&:empty?)
  build { |p|
    p << paths.shift
    paths.inject(p.last) { |point, path|
      translation = Vector.translation_between(path.first, point)
      p << path.translate(translation)[1..-1]
      p.last
    }
  }
end

Instance Method Details

#<<(path_or_point) ⇒ Object



30
31
32
33
# File 'lib/draught/path_builder.rb', line 30

def <<(path_or_point)
  @path = path << path_or_point
  self
end

#lastObject



35
36
37
# File 'lib/draught/path_builder.rb', line 35

def last
  path.last
end