Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I use clipper library with C++.
I want to clip parallel lines with a polygon.
look below code.
C++
Paths subj(2), clip(1), solution;
subj[0] <<IntPoint(0, 100) << IntPoint(100, 100);
subj[1] <<IntPoint(0, 50) << IntPoint(100, 50);
clip[0] <<IntPoint(30,0) << IntPoint(35,200) <<IntPoint(40,210) << IntPoint(45,40);
Clipper c;
c.AddPaths(subj, ptSubject, true);
c.AddPaths(clip, ptClip, true);
c.Execute(ctIntersection, solution, pftNonZero, pftNonZero);

but size of solution is zero after execute below instruction
c.Execute(ctIntersection, solution, pftNonZero, pftNonZero).
for what? problem is where?
Posted
Updated 23-Sep-15 5:11am
v3
Comments
Stefan_Lang 23-Sep-15 2:29am    
The link you posted links to this question. Maybe you should fix that.

Parallel lines don't have an intersection, so why do you expect a solution?
kave2011 23-Sep-15 6:56am    
I improved question.
clip[0] is a polygon, and subj[0] and subj[1] are parallel lines.
These lines have intersection with polygon.
Stefan_Lang 23-Sep-15 7:34am    
Ah, sorry, didn't check the code too closely. That makes more sense.

Looking at the coordinates, I agree there should be intersections. The only thing I noticed is that the orientation of the polygon is mathematically negative. That shouldn't make a difference, but it might be worth a try reversing the polygon point order.

Although the link you posted didn't work, I was able to find the library here: http://www.angusj.com/delphi/clipper.php[^]. On this page: http://www.angusj.com/delphi/clipper/documentation/Docs/Units/ClipperLib/Classes/Clipper/Methods/Execute.htm[^] the documentation states that
Quote:
when open paths are passed to a Clipper object, the user must use a PolyTree object as the solution parameter, otherwise an exception will be raised.

So it seems that either you have to define your paths as closed paths, or you should define your solution as PolyTree instead of using the Paths type.
 
Share this answer
 
My paths(parallel lines) are open, so I can't do this work with this library. look this link.
I changed lines to triangles and then I clip their.
when I want to draw their, just I draw parallel lines.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900