Sha256: 13a7fcd7671e8bd5358983d888aada205b74476136aebb8adf1663bb4be41245

Contents?: true

Size: 671 Bytes

Versions: 1

Compression:

Stored size: 671 Bytes

Contents

module Straightedge
  # TODO extend, make into just an arbitrary tiling Figure 
  #      so we can do sexy hexagons!
  #
  class Grid < Figure
    extend Forwardable
    include Enumerable

    def_delegator :lines, :x, :width
    def_delegator :lines, :y, :height

    DEFAULT_SIZE = 1_000

    def initialize(axes=[DEFAULT_SIZE,DEFAULT_SIZE])
      super([], lines: axes)
      @marks = Array.new(width) do |x|
	Array.new(height) do |y|
	  [x,y]
	end
      end.flatten(1)
    end

    def each
      @marks.each { |p| yield(p) }
    end

    def clip(xys=[])
      xys.reject do |xy|
	x,y = *xy
	x < 0 || y < 0 || x >= width || y >= height
      end 
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
straightedge-0.1.0 lib/straightedge/grid.rb