I need a good (reliable) algorithm for splitting a polygon into two sets (left / right) into a line segment. My polygonal view is just a list of integer coordinates (ordered clocks that never self-intersect), and the line segment is represented by the start and end points. The line always starts and ends outside the polygon, i.e. Crosses the polygon an even number of times.
Here is an example:

The output of the algorithm should be two sets (time clock):
- Left: HABCH, FGDEF
- Right: HCDGH, BAB, FEF
I can determine the AH points by iterating the polygon and checking if the polygon section intersects the line, taking care to observe the boundary cases. I can also determine which side each multi-line line belongs to. I cannot, though, for the life of me, decide how to sew this segment together.
Before offering a general-purpose clipping library, I use the boost polygon, which is very good at trimming polygons against each other, but I did not find any library that would allow you to crop the polygon relative to the line segment, and it is not possible, in general, to turn the segment lines into a polygon, which I could fix with.
EDIT: I missed the FEF and the fact that the polygon can have parts on both sides of the line segment.
source share