Class: GeoRuby::SimpleFeatures::LinearRing

Inherits:
Object
  • Object
show all
Defined in:
lib/geomagic/extensions/geo_ruby_ext/point_in_polygon.rb

Instance Method Summary collapse

Instance Method Details

#contains_point?(point) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/geomagic/extensions/geo_ruby_ext/point_in_polygon.rb', line 18

def contains_point? point
  return false if outside_bounding_box? point
  i = -1
  j = self.size-1
  contains_point = false
  while (i += 1) < self.size
    a_point_on_polygon = self[i]
    trailing_point_on_polygon = self[j]
    if point_is_between_the_ys_of_the_line_segment?(point, a_point_on_polygon, trailing_point_on_polygon)
      if ray_crosses_through_line_segment?(point, a_point_on_polygon, trailing_point_on_polygon)
        contains_point = !contains_point
      end
    end
    j = i
  end
  contains_point
end