Polygon.Intersects() method not working for some inputs?
sreekanth-cb opened this issue · comments
Not sure why the below polygon intersect unit test isn't working?
The actual polygons aren't overlapping on the earth's surface but S2 says it does.
Does anyone have any idea/clues as to why this isn't working?
func TestPolygonIntersectsNotWorking(t *testing.T) {
pts := make([]Point, 7)
pts[0] = PointFromLatLng(LatLngFromDegrees(13.197164523281993, -282.9803466796875))
pts[1] = PointFromLatLng(LatLngFromDegrees(12.404388944669792, -282.919921875))
pts[2] = PointFromLatLng(LatLngFromDegrees(12.833226023521243, -282.1728515625))
pts[3] = PointFromLatLng(LatLngFromDegrees(12.95102921601837, -281.55761718749994))
pts[4] = PointFromLatLng(LatLngFromDegrees(13.443052132777558, -281.62353515625))
pts[5] = PointFromLatLng(LatLngFromDegrees(13.678013256725489, -282.19482421875))
pts[6] = PointFromLatLng(LatLngFromDegrees(13.720708401412068, -282.777099609375))
polygon1 := PolygonFromLoops([]*Loop{
LoopFromPoints(pts),
})
pts = make([]Point, 19)
pts[0] = PointFromLatLng(LatLngFromDegrees(45.13745, -67.13734))
pts[1] = PointFromLatLng(LatLngFromDegrees(44.8097, -66.96466))
pts[2] = PointFromLatLng(LatLngFromDegrees(44.3252, -68.03252))
pts[3] = PointFromLatLng(LatLngFromDegrees(43.98, -69.06))
pts[4] = PointFromLatLng(LatLngFromDegrees(43.68405, -70.11617))
pts[5] = PointFromLatLng(LatLngFromDegrees(43.09008, -70.64573))
pts[6] = PointFromLatLng(LatLngFromDegrees(43.08003, -70.75102))
pts[7] = PointFromLatLng(LatLngFromDegrees(43.21973, -70.79761))
pts[8] = PointFromLatLng(LatLngFromDegrees(43.36789, -70.98176))
pts[9] = PointFromLatLng(LatLngFromDegrees(43.46633, -70.94416))
pts[10] = PointFromLatLng(LatLngFromDegrees(45.30524, -71.08482))
pts[11] = PointFromLatLng(LatLngFromDegrees(45.46022, -70.66002))
pts[12] = PointFromLatLng(LatLngFromDegrees(45.91479, -70.30495))
pts[13] = PointFromLatLng(LatLngFromDegrees(46.69317, -70.00014))
pts[14] = PointFromLatLng(LatLngFromDegrees(47.44777, -69.23708))
pts[15] = PointFromLatLng(LatLngFromDegrees(47.18479, -68.90478))
pts[16] = PointFromLatLng(LatLngFromDegrees(47.35462, -68.2343))
pts[17] = PointFromLatLng(LatLngFromDegrees(47.06624, -67.79035))
pts[18] = PointFromLatLng(LatLngFromDegrees(45.70258, -67.79035))
polygon2 := PolygonFromLoops([]*Loop{
LoopFromPoints(pts),
})
if polygon2.Intersects(polygon1) {
t.Errorf("polygons should not intersect")
}
if polygon2.Contains(polygon1) {
t.Errorf("polygon2 should not contain polygon1")
}
}
Closing this ticket as the issue was wrt the wrong ordering of the edges in the second polygon and that was resulting in an enclosure for the whole sphere.