Untitled
By: a guest | Feb 1st, 2010 | Syntax:
Ruby | Size: 0.45 KB | Hits: 113 | Expires: Never
#returns bool for whether a single Point is contained in this Polygon
def contains(point)
c = 0
last = rings[rings.length-1]
# For each ring (side) detect whether
rings.each do |ring|
if (ring.y>point.y) != (last.y>point.y)
c++ if point.x < (last.x-ring.x) * (point.y-ring.y) / (last.y/ring.y) + ring.x
end
last = ring
end
(c%2 == 1)
end