w8r / GreinerHormann

Greiner-Hormann polygon clipping algorithm. Does AND, OR, XOR. Plays nicely with Leaflet. Handles non-convex polygons and multiple clipping areas. ~3kb footprint, no dependencies
http://w8r.github.io/GreinerHormann/
MIT License
239 stars 34 forks source link

Bug in intersection #18

Open devbab opened 4 years ago

devbab commented 4 years ago

with below polygons, it does not provide same results doing intesrection A and B or B and A.


let polyA = [
    [49.05351, 1.44728],
    [48.43959, 1.88663],
    [48.77105, 2.22033],
    [48.98882, 2.12906],
    [49.05351, 1.44728]
];
let polyB = [
    [48.33984375, 1.93359375],
    [48.515624999, 1.93359375],
    [48.515624999, 2.109374999],
    [48.33984375, 2.109374999],
    [48.33984375, 1.93359375]
];

console.log(GreinerHormann.intersection(polyA, polyB));
console.log(GreinerHormann.intersection(polyB, polyA));
army8735 commented 2 years ago

Try to remove the duplicate points:


let polyA = [
    [49.05351, 1.44728],
    [48.43959, 1.88663],
    [48.77105, 2.22033],
    [48.98882, 2.12906]
];
let polyB = [
    [48.33984375, 1.93359375],
    [48.515624999, 1.93359375],
    [48.515624999, 2.109374999],
    [48.33984375, 2.109374999]
];

console.log(GreinerHormann.intersection(polyA, polyB));
console.log(GreinerHormann.intersection(polyB, polyA));```