Hacker News new | ask | show | jobs
by raphlinus 802 days ago
Cool to see! The tweak suggested in the blog post when you're near the vertex of the parabola is valid, and the implementation that was in Vello did something very similar. This is also the flatten algorithm that's in kurbo[1], and the code for that is probably the most accessible source for the ideas. However, if approaching this again I'd suggest placing a subdivision point at the vertex, which will also handle the degenerate colinear case; I now have reason to believe that the error metric that all this is based on works for monotonic curvature, and can fail otherwise.

I say "was" as the new version in Vello is much more sophisticated, and handles both flattening and stroke expansion, all on the GPU. A paper is in the works, and I'll post it to HN when it's ready.

[1]: https://docs.rs/kurbo/latest/kurbo/struct.BezPath.html#metho...

2 comments

The OP had perfect timing as I was scratching my head on how to implement click hit-testing a bezier. Flattening and then hit testing the segments in parallel is exactly what I was looking for, as it should be fast and I already implemented hit-testing line segments with stroke/margin-of-error expansion.

Aside from seeming like a good solution, would you go that route?

It's... ok.

What kurbo does is lower to quadratic Béziers[1], then the analytic solution to nearest for a quadratic Bézier is the solution to a cubic equation[2].

I'm not sure this is the best possible answer, but it's at least pretty good, and certainly better than flattening to lines.

And I'd like for people to get in the habit of checking kurbo; the intent is for it to always have the best in class algorithm.

[1]: https://docs.rs/kurbo/latest/src/kurbo/cubicbez.rs.html#647-...

[2]: https://docs.rs/kurbo/latest/src/kurbo/quadbez.rs.html#297-3...

Thanks for point out kurbo.

Another question(s): What is your opinion of Sederberg's CAGD publication? Has that publication had tangible mapping to your API designs? If so, what percentage of that publication (in your opinion) would be exposed as API in an ideal CAGD API?

I'm sure there's an art to what should be in an API and I have limited understanding of how the math maps to actual needed implementation.

Thank you! Looking forward to your research.