Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def contains? y, x
- y = y.to_f if y.is_a?(String)
- x = x.to_f if x.is_a?(String)
- lats = coordinates.collect{|c| c[0].to_f}
- longs = coordinates.collect{|c| c[1].to_f}
- within = false
- j = lats.size - 1
- lats.each_with_index do |lat,i|
- long = longs[i]
- next_lat = lats[j]
- next_long = longs[j]
- if ( (lat <= y) && (y < next_lat) ) || ( (next_lat <= y) && (y < lat) )
- if( (next_long - long) * (y-lat) / (next_lat - lat) + long ) > x
- within = !within
- end
- end
- j = i
- end
- within
- end
Add Comment
Please, Sign In to add comment