jbuckmccready / CavalierContours

2D polyline library for offsetting, combining, etc.
MIT License
427 stars 79 forks source link

Multiple combining polylines #31

Open kadircanik opened 3 years ago

kadircanik commented 3 years ago

Is there a way to make multi combining on polylines like clipper's AddPaths.

Initially i have 1 polyline, after offset i get multi polylines and i want to cut (cavc::PlineCombineMode::Exclude) these polylines by more than one islands.

jbuckmccready commented 3 years ago

It's not supported/implemented, but there is an algorithm to efficiently do it. I'm in the process of rewriting this library in Rust. See my replies to this issue: https://github.com/jbuckmccready/CavalierContours/issues/29

kadircanik commented 3 years ago

This works

std::vector<cavc::Polyline> GuidePolylines, aPolyList; for (TopoDS_Wire aGuide : GuideWires2d) { aGuide = CAM::ApproximateWireToLineAndArcs(aGuide, P.Tol); cavc::Polyline aGuidePolyLine = WireToCavalier(aGuide, P.Tol); GuidePolylines = cavc::parallelOffset(aGuidePolyLine, P.GuideOffset);

for (cavc::Polyline<double> aIsland : Islands) {
    aPolyList.clear();
    for (cavc::Polyline<double> aGuide : GuidePolylines) {
        cavc::CombineResult<double> res = cavc::combinePolylines(aGuide, aIsland, cavc::PlineCombineMode::Exclude);
        for (cavc::Polyline<double> aPoly : res.remaining)
            aPolyList.push_back(aPoly);
    }
    GuidePolylines = aPolyList;
}

}

jbuckmccready commented 3 years ago

I thought you needed a more generalized multi polyline combine operation - for your use case you may be able to just repeatedly call the combine function.

kadircanik commented 3 years ago

Ofcourse it will be better, i have to go this way until you develop new solution :)