Understand contains? edge cases
masterThe contains? function has specific behaviors regarding boundaries:
- Polygons and Boundaries: A Polygon does not contain its own boundary. A
LineStringrepresenting the exact same exterior ring as aPolygonwill returnfalseforcontains?, buttrueforintersects?. - LineStrings and Endpoints: A
LineStringdoes not contain its own first and last points unless those points are identical (forming a closed loop).
# Polygon does not contain its own boundary
a = %Geo.Polygon{coordinates: [[{2, 2}, {20, 2}, {11, 11}, {2, 2}]]}
b = %Geo.LineString{coordinates: [{2, 2}, {20, 2}, {11, 11}, {2, 2}]}
Topo.contains? a, b # => false
Topo.intersects? a, b # => true
# LineString does not contain its own endpoints
a = %Geo.LineString{coordinates: [{1, 3}, {2, -1}, {0, -1}]}
b = %Geo.LineString{coordinates: [{1, 3}, {2, -1}, {0, -1}, {1, 3}]}
Topo.contains? a, {1, 3} # => false
Topo.intersects? a, {1, 3} # => true