alexbol99 / flatten-js

Javascript library for 2d geometry
MIT License
546 stars 56 forks source link

Intersect and subtract boolean operations fail when passed empty polygons #52

Closed OliverColeman closed 4 years ago

OliverColeman commented 4 years ago

I get an error when passing an empty polygon as one of the arguments to the intersect or subtract boolean operations. Eg see the console output at https://codesandbox.io/s/late-https-8sjsf?file=/src/index.js

I expected output for intersect to be empty polygon.

I expected output for subtract to be same as the first polygon passed.

If the current behaviour is an error I'm happy to submit a PR.

In my browser console the error looks like:

Uncaught (in promise) TypeError: element is undefined
    toArray modules.js:160363
    get edges modules.js:164770
    get shapes modules.js:164778
    clone modules.js:165370
    subtract modules.js:158791
alexbol99 commented 4 years ago

Hello, @OliverColeman ,

Big fixed in release v1.2.9 Now construction of polygon like

const emptyP = new Polygon([]);

gives the same result as

const emptyP = new Polygon();

The result is empty polygon with zero number of faces. Then all boolean operations gives correct result.

Thank you, Alex Bol