Parent

Methods

Geokit::Polygon

A complex polygon made of multiple points. End point must equal start point to close the poly.

Attributes

points[RW]

Public Class Methods

new(points) click to toggle source

Pass in an array of Geokit::LatLng

# File lib/geokit/polygon.rb, line 8
def initialize(points)
  @points = points
  
  # A Polygon must be 'closed', the last point equal to the first point
  # Append the first point to the array to close the polygon
  @points << points[0] if points[0] != points[-1]
end

Public Instance Methods

contains?(point) click to toggle source
# File lib/geokit/polygon.rb, line 16
def contains?(point)
  last_point = @points[-1]
  oddNodes = false
  x = point.lng
  y = point.lat

  for p in @points
    yi = p.lat
    xi = p.lng
    yj = last_point.lat
    xj = last_point.lng
    if (yi < y && yj >= y ||
        yj < y && yi >= y)
      if (xi + (y - yi) / (yj - yi) * (xj - xi) < x)
        oddNodes = !oddNodes
      end
    end
 
    last_point = p
  end

  oddNodes
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.