Sha256: d99032f0c9ad629ef865e3b52ac19a232257bf08740a3611b5baa4b18e779a1b

Contents?: true

Size: 1.02 KB

Versions: 4

Compression:

Stored size: 1.02 KB

Contents

module Terraformer
  class Circle
    extend Forwardable

    attr_accessor :polygon
    attr_reader :center, :radius, :resolution
    def_delegators :@polygon, :bbox, :contains?, :within?, :intersects?, :to_feature, :to_json, :to_hash

    def initialize c, r, res = DEFAULT_BUFFER_RESOLUTION
      self.center = c
      self.radius = r
      self.resolution = res
      recalculate
    end

    def recalculate
      @polygon = @center.buffer @radius, @resolution
      @dirty = false
      self
    end

    def center= c
      c = Coordinate.from_array c if Array === c and Numeric === c[0]
      c = c.coordinates if Point === c
      raise ArgumentError unless Coordinate === c
      @center = c
      @dirty = true
      self
    end

    def radius= r
      raise ArgumentError unless Numeric === r
      @radius = r
      @dirty = true
      self
    end

    def resolution= res
      raise ArgumentError unless Fixnum === res
      @resolution = res
      @dirty = true
      self
    end

    def dirty?
      @dirty
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
terraformer-0.2.1 lib/terraformer/circle.rb
terraformer-0.2.0 lib/terraformer/circle.rb
terraformer-0.1.0 lib/terraformer/circle.rb
terraformer-0.0.9 lib/terraformer/circle.rb