Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Feb 1st, 2010 | Syntax: Ruby | Size: 0.45 KB | Hits: 113 | Expires: Never
This paste has a previous version, view the difference. Copy text to clipboard
  1.       #returns bool for whether a single Point is contained in this Polygon
  2.       def contains(point)
  3.         c = 0
  4.         last = rings[rings.length-1]
  5.  
  6.         # For each ring (side) detect whether
  7.         rings.each do |ring|
  8.           if (ring.y>point.y) != (last.y>point.y)
  9.             c++ if point.x < (last.x-ring.x) * (point.y-ring.y) / (last.y/ring.y) + ring.x
  10.           end
  11.           last = ring
  12.         end
  13.  
  14.         (c%2 == 1)
  15.       end