Hi Clipper2 community, thanks for this awesome library.
I though about a very simple problem clipping away parts of a rectangle with open paths with C++
At then end I want the right-hand side a closed path, where the lower right hand part is gone and replaced by the red line.
I have three questions here:
- Since Clipperlib2 only supports
subjects to be open, my scenario is not working out of the box, is it?
- As a fallback I can construct at least the lines that trims my rectangle ( the bold red line). To store all the information i need later, to reconstruct by hand my clipped rectangle I'm using the
USINGZ feature. This I do by the following code:
using namespace Clipper2Lib;
// create rectangle
PathsD rectPath;
rectPath.push_back({});
for (int i=0; i<4 ; ++i)
rectPath[0].push_back({corners[i][0],corners[i][1],i+1}); // flag indices of rectangle
ClipperD c(5);
int intersectionCounter= 5;
std::map<int,std::tuple<int,int,PointD>> tracker;
c.SetZCallback([&](const PointD& e1bot, const PointD& e1top,
const PointD& e2bot, const PointD& e2top, PointD& pt) {
tracker.insert({{intersectionCounter++},{e2top.z,e2bot.z,PointD({pt.x,pt.y})}});
pt.z=intersectionCounter++; // not needed since the rectangle is gone anyway at the end
});
PathsD trimmingCurve;
// ... create curve
c.AddOpenSubject(trimmingCurve);
c.AddClip(rectPath);
PathsD clippedOpenEdges;
PathsD clippedClosedEdges;
PolyTreeD tree;
// c.Execute(ClipType::Intersection,FillRule::NonZero,tree); // returns empty tree, is this expected?
c.Execute(ClipType::Intersection,FillRule::EvenOdd,clippedClosedEdges,clippedOpenEdges)
//clippedClosedEdges is empty
// clippedOpenEdges contains red line
//reconstruct clipped rectangle with tracker and clippedOpenEdges
Now with my tracker, I can reconstruct the full trimmed rectangle, from the information how I pierced my edges of the rectangle.
I feel this is quite overengineered and I wonder if there is an easier solution.
3. Since my solutions depends on setting a ZCallback on my rectangle path, I cannot use RectClipLines for my scenario, can I?
Thanks for your time.
Hi Clipper2 community, thanks for this awesome library.
I though about a very simple problem clipping away parts of a rectangle with open paths with C++
At then end I want the right-hand side a closed path, where the lower right hand part is gone and replaced by the red line.
I have three questions here:
subjectsto be open, my scenario is not working out of the box, is it?USINGZfeature. This I do by the following code:Now with my tracker, I can reconstruct the full trimmed rectangle, from the information how I pierced my edges of the rectangle.
I feel this is quite overengineered and I wonder if there is an easier solution.
3. Since my solutions depends on setting a
ZCallbackon my rectangle path, I cannot useRectClipLinesfor my scenario, can I?Thanks for your time.