You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Oct 28, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Oct 28, 2026. It is now read-only.
We (OpenSCAD) are using Clipper2 to perform 2D polygon offset operations.
When offsetting, we prefer writing the result to a PolyTree structure, as that allows us to later walk the tree and easily identify holes as we go.
However, we also want to perform the recommended simplification between offset operations, and I haven't found a convenient way of achieving that:
SimplifyPath() doesn't accept a PolyTree parameter (only Path and Paths).
BuildTree64(), which converts from Paths to PolyTree, is private.
Are there any recommended ways of obtaining a simplified PolyTree result from an offset result?
Barring a recommended way, what would be the best way forward, e.g. Add a new SimplifyPath() variant, make BuildTree64() public, or building a copy of one of those in user space?
In my plugin sometimes i add custom functions or classes (in this case ClipperUtils) maybe you can use the same way
namespace Clipper2Lib
{
public static class ClipperUtils
{
public static PolyTreeD PathsDToPolyTree(PathsD pathsD)
{
PolyTreeD polyTreeD = new PolyTreeD();
ClipperD clipper = new ClipperD();
// Add paths to the Clipper instance
clipper.AddSubject(pathsD);
// Execute a union operation to populate the PolyTreeD
clipper.Execute(ClipType.Union, FillRule.NonZero, polyTreeD);
return polyTreeD;
}
public static PolyTree64 Paths64ToPolyTree(Paths64 paths64)
{
PolyTree64 polyTree64 = new PolyTree64();
Clipper64 clipper = new Clipper64();
// Add paths to the Clipper instance
clipper.AddSubject(paths64);
// Execute a union operation to populate the PolyTree64
clipper.Execute(ClipType.Union, FillRule.NonZero, polyTree64);
return polyTree64;
}
}
}
Activity
seghier commentedon Jan 7, 2025
Hi @kintel
SimplifyPath() doesn't accept a PolyTree parameter (only Path and Paths).Did you try
PolyTreeToPaths64andPolyTreeToPathsDkintel commentedon Jan 7, 2025
Yes, but I'm missing a
Paths64ToPolyTree().seghier commentedon Jan 7, 2025
In my plugin sometimes i add custom functions or classes (in this case ClipperUtils) maybe you can use the same way
kintel commentedon Jan 7, 2025
Thanks! It feels a bit expensive to perform a union just to convert, considering that the Paths64 already came straight from Clipper.
In the meantime I'll look into writing my own simplification function, operating on PolyTrees..
kintel commentedon Jan 10, 2025
OK, looks like a PolyTree implementation is pretty easy, at least for closed curves: