Submitted by mark on Sun, 10/04/2015 - 13:50
I began extending the algorithm to handle paths containing Bézier curve segments:
This shows how far I've got. After the next step everything will drown in errors.
Submitted by mark on Wed, 09/30/2015 - 00:05
Guess what! After fixing the 3rd issue, the algorithm suddenly feels stable. And because I'm so happy about it, below is a picture of my scribbling paper used to get there. Oh the irony of it: Requiring paper to get rid of paper. :)
Submitted by mark on Sun, 09/27/2015 - 16:23
I replaced the algorithm which calculates the line intersections. The next class of errors are cases where dividing a line would place it somewhere else within the sweep line buffer. Currently the line's flags are calculated, then the line is divided and because the division might have changed the position of some lines in the sweep line buffer, the flags are recalculated for some known cases.
I found one case where this didn't happen and it seems that there are more.
A more reliable approach might be to reevaluate the order within the sweep line buffer and act accordingly. From there I could even brute force a list of all cases where the flags need to be recalculated.
Submitted by mark on Tue, 09/22/2015 - 11:04
Submitted by mark on Mon, 09/21/2015 - 22:45
I'm beginning to grasp the algorithm. Pretty clever. The problem might be that the code to calculate line intersections isn't stable.
Submitted by mark on Wed, 09/16/2015 - 07:49
Each iteration of the sweep algorithm is now printed into a PDF file. The trouble is that in a special case of overlapping lines of the subject and clipping polygons, none of these lines end up in the result when at least one should.
Submitted by mark on Wed, 09/09/2015 - 11:58
What we see here is this:
- the black line with the crosses is the previous polygon (subj)
- the blue line with the circles is the polygon to be added (clip)
- the red line is the result of the union operation (result)
My assumption is that the point on the right might be the same for subj and clip and this is causes the routine constructing the result from the sweep events to pick another point. In this case where the red line goes straight upwards it picked the next point right to it.
Which is strange, there shouldn't be a sweep event connecting these points at all...
Submitted by mark on Tue, 09/08/2015 - 18:57
F. Martínez had warned me that the example code had some issues. But since I wanted to add support for curves
- I wanted to use the newest algorithm available and
- I had to debug and understand the algorithm anyway.
And to make this work as an absolute no-brainer, I began to write a debugger:
(But when I look at CGAL I might be totally wasting my time trying to implement this on my own... but it's so much fun! On the other hand, linking against CGAL might an adventure of it's own.)
Submitted by mark on Sun, 09/06/2015 - 14:21
I've spend too much time trying to play guitar lately but here's an update: I began integrating the boolean path operations into the TOAD library, added some unit tests, build a little free hand drawing demo, which handles pressure and rotation... it looks okay but there are still some errors to hunt down.
Submitted by mark on Sun, 05/17/2015 - 17:06
Porting the code for boolean operations on paths in Paper.js to C++ turned out too hard.
But there are quite a few documented algorithms available for this:
||"Reentrant polygon clipping", Sutherland and Hodgemann (convex clip polygon)
||"Polygon comparison using graph representation", Weiler
||"Plane-sweep algorithms for intersecting geometric figures", Nievergelt and Preparata
||"An analysis and algorithm for polygon clipping", Liang and Barsky
||"An algorithm for computing the union, intersection or different of two polygons", Margalit and Knott
||"Algorithm for clipping arbitrary polygons", Andereev
||"A generic solution to polygon clipping", Vatti
||"Efficient clipping of arbitrary polygons", Greiner and Hormann
||"A new algorithm for Boolean operations on general polygons", Yu Peng et al.
||"An algorithm for polygon clipping, for determining polygon intersections and unions", Liu et al.
||"A new algorithm for computing Boolean operations on polygons", F. Martínez et al.
||"An efficient algorithm for clipping operation based on trapezoidal meshes and sweep-line technique", Wang et al.
||"A simple Algorithm for Boolean operations on polygons", F. Martínez et al.
And I picked the most recent and F. Martínez was kind enough to mail me a copy of their C++ library which I'm now going to adapt to TOAD's data structures and bézier splines.