Guest User

Untitled

a guest
Jan 21st, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. def contains? y, x
  2. y = y.to_f if y.is_a?(String)
  3. x = x.to_f if x.is_a?(String)
  4. lats = coordinates.collect{|c| c[0].to_f}
  5. longs = coordinates.collect{|c| c[1].to_f}
  6. within = false
  7. j = lats.size - 1
  8. lats.each_with_index do |lat,i|
  9. long = longs[i]
  10. next_lat = lats[j]
  11. next_long = longs[j]
  12. if ( (lat <= y) && (y < next_lat) ) || ( (next_lat <= y) && (y < lat) )
  13. if( (next_long - long) * (y-lat) / (next_lat - lat) + long ) > x
  14. within = !within
  15. end
  16. end
  17. j = i
  18. end
  19. within
  20. end
Add Comment
Please, Sign In to add comment