Hacker News new | past | comments | ask | show | jobs | submit login

From Shewchuk’s thesis:

> From the beginning of the implementation of Triangle, and well into the development of Pyramid, floating-point roundoff problems plagued me. Each program would sometimes crash, sometimes find itself stuck in an endless loop, and sometimes produce garbled output. At first I believed that I would be able to fix the problems by understanding how the algorithms went wrong when roundoff error produced incorrect answers, and writing special-case code to handle each potential problem. Some of the robustness problems yielded to this approach, but others did not. Fortunately, Steven Fortune of AT&T Bell Laboratories convinced me, in a few brief but well-worded email messages (and in several longer and equally well-worded technical papers), to choose the alternative path to robustness, which led to the research described in this chapter. For reasons that will become apparent, exact arithmetic is the better approach to solving many, if not all, of the robustness worries associated with triangulation.

Of course, what can be done with polygons is often not feasible for more general kids of shapes like parametric cubics.

* * *

What is a “clever vector path algorithm”, and how do you avoid them?




Algorithms that gave me floating-point related problems:

- Fast polygon triangulation/partitioning. There's a reason why people use ear clipping in practice despite it having bad asymptotic time complexity. Even ear clipping isn't very useful for robust path rendering because it doesn't handle self-intersection. Tiling and stenciling to compute winding numbers is a much more robust approach than tessellation.

- Generation of bounding geometry for analytic antialiasing of polygon edges, to work around the lack of conservative rasterization on GPUs. Skia has impressive code that handles this, but it is incredibly painful and I decided it wasn't worth it.

- Determining polygon convexity. This even led to a security bug in Skia [1].

- Clipping of Bézier paths, especially in homogeneous coordinates. Yes, this even includes clipping to axis-aligned rects. It's too hard. Convert to triangles or quads and clip those.

- Any sort of Boolean operation on Bézier paths, if you want reliable results. Leave those to applications like Illustrator, where artists can notice if the algorithm goes wrong and fix it up manually when it does.

[1]: https://googleprojectzero.blogspot.com/2019/02/the-curious-c...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: