start all over again
start all over again

Reputation: 11

Clip hollow polygons using the clipper library

I wrote the following function according to the usage of the clipper library, but the printed result is not the coordinates of the clipped polygon I want。I want to know where the main problem of this code is, or that the clipper library cannot give the coordinates of the clipped polygon。Because according to the polygon I made, it should give two L-shaped polygons or two polygons of other shapes, but this code returns the coordinates of the original large polygon and the original hollowed-out polygon.

Paths subject;
Paths clip;
Paths solution;

Path subject_polygon;
subject_polygon << IntPoint(0, 0) << IntPoint(0, 100) << IntPoint(100, 100) << IntPoint(100, 0);
subject.push_back(subject_polygon);

Path hole_polygon;
hole_polygon << IntPoint(20, 20) << IntPoint(20, 80) << IntPoint(80, 80) << IntPoint(80, 20);
clip.push_back(hole_polygon);

Clipper c;
c.AddPaths(subject, ptSubject, true);
c.AddPaths(clip, ptClip, true);
c.Execute(ctDifference, solution, pftEvenOdd, pftEvenOdd);

for (size_t i = 0; i < solution.size(); ++i) {
    for (size_t j = 0; j < solution[i].size(); ++j) {
        std::cout << "X: " << solution[i][j].X << ", Y: " << solution[i][j].Y << std::endl;
    }
    std::cout << "-----------------" << std::endl;
}

Upvotes: 1

Views: 113

Answers (0)

Related Questions