Sha256: a6f8dd810d528b9e675c10d1c6e1f013314027f8ade1d4a6f11cba665e6a5ab4

Contents?: true

Size: 694 Bytes

Versions: 1

Compression:

Stored size: 694 Bytes

Contents

require_relative 'path'

module Draught
  class PathBuilder
    def self.build
      builder = new
      yield(builder)
      builder.send(:path)
    end

    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

    attr_reader :path
    private :path

    def initialize
      @path = Path.new
    end

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

    def last
      path.last
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
draught-0.1.0 lib/draught/path_builder.rb