luizbarboza / polyclip-ts

MIT License
28 stars 10 forks source link

Two polygons with shared coords doesn't return intersecting but union works #12

Open Falke-Design opened 7 months ago

Falke-Design commented 7 months ago

I want to check if two polygons with are intersecting. When the polygons have overlapping coords, intersection still returns that they are not intersecting

Example:

const poly1 = [
            [
                [72.723999, 18.976429],
                [72.723999, 19.324103],
                [73.100281, 19.324103], // <-- overlapping coords
                [73.100281, 18.976429], // <-- overlapping coords
                [72.723999, 18.976429],
            ],
        ];

const poly2 = [
            [
                [73.100281, 18.976429], // <-- overlapping coords
                [73.100281, 19.324103], // <-- overlapping coords
                [74.900281, 19.324103],
                [74.900281, 18.976429],
                [73.100281, 18.976429],
            ],
        ];
polyclip.intersection(poly1, poly2);

Is not intersecting ... Why? Bounds are overlapping: []

polyclip.union(poly1, poly2);

Union returns single polygon (correctly), because bounds are overlapping: [[[[72.723999,18.976429],[74.900281,18.976429],[74.900281,19.324103],[72.723999,19.324103],[72.723999,18.976429]]]]

https://plnkr.co/edit/qDSAFfMQUsJFog2S

Falke-Design commented 7 months ago

With https://github.com/rowanwins/sweepline-intersections I get the correct result but only if the lines are intersecting not if the polygon is inside of the other polygon