Sha256: 8d285f3204b0c8298290bcea8f2b5b73462f40ab5c4168383338d6ae891f1e6f

Contents?: true

Size: 1.22 KB

Versions: 1

Compression:

Stored size: 1.22 KB

Contents

module Terraformer

  class Point < Geometry

    def first_coordinate
      coordinates
    end

    def distance_and_bearing_to obj
      case obj
      when Point
        first_coordinate.distance_and_bearing_to obj.first_coordinate

      # todo other cases
      end
    end

    def distance_to obj
      distance_and_bearing_to(obj)[:distance]
    end

    def initial_bearing_to obj
      distance_and_bearing_to(obj)[:bearing][:initial]
    end

    def final_bearing_to obj
      distance_and_bearing_to(obj)[:bearing][:final]
    end

    def contains? obj
      case obj
      when Point
        self == obj
      else
        raise ArgumentError.new "unsupported type: #{obj.type rescue obj.class}"
      end
    end

    def within? obj
      case obj
      when Point
        self == obj
      when MultiPoint
        obj.coordinates.any? {|c| self.coordinates == c}
      when LineString
        obj.coordinates.any? {|c| self.coordinates == c}
      when MultiLineString
        obj.line_strings.any? {|ls| within? ls}
      when Polygon
        obj.contains? self
      when MultiPolygon
        obj.polygons.any? {|p| p.contains? self}
      else
        raise ArgumentError unless Geometry === obj
      end
    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
terraformer-0.0.2 lib/terraformer/point.rb