jscad / OpenJSCAD.org

JSCAD is an open source set of modular, browser and command line tools for creating parametric 2D and 3D designs with JavaScript code. It provides a quick, precise and reproducible method for generating 3D models, and is especially useful for 3D printing applications.
https://openjscad.xyz/
MIT License
2.65k stars 513 forks source link

Is poly2 always convex? #968

Open jue89 opened 2 years ago

jue89 commented 2 years ago

The API description states that poly2 is always convex: https://github.com/jscad/OpenJSCAD.org/blob/f5f31084843adebaeb481c064eb09634fb7490a0/packages/modeling/src/geometries/poly2/create.js#L2

But looking in the code, poly2 is created from geom2 outlines, which may not be convex: https://github.com/jscad/OpenJSCAD.org/blob/f5f31084843adebaeb481c064eb09634fb7490a0/packages/modeling/src/operations/expansions/offsetGeom2.js#L28-L30

Is this a possible bug? Or is the documentation outdated?

z3dev commented 2 years ago

Ah… poly2… it was added as part of V2 but is not really 100%. So, I’m not sure where this geometry will be useful. I believe it was added to scope those special functions.

Do you have some use cases?

jue89 commented 2 years ago

I was just wondering. I looked into the code for existing parts useful for the implementation of the Minkowski sum. If poly2 isn't guaranteed to be convex, a poly2.isConvex() function would make sense. Some goes for a decompose function to split a non-convex polygon into convex polygons.

z3dev commented 2 years ago

Ah. Now, I understand where this is going. Feel free to contribute functionality to poly2. Please follow name and style similar to poly3, if possible. And of course, some rudimentary tests.

z3dev commented 2 years ago

@jue89 theres a set of changes coming for poly2. Can you follow and add comments? Or even better... enhancements.