linebender / kurbo

A Rust library for manipulating curves
Apache License 2.0
718 stars 69 forks source link

Include interpolated splines? #253

Closed partim closed 1 year ago

partim commented 1 year ago

I’m curious if algorithms for interpolating splines are considered in scope for Kurbo and if there’s an interest to include them.

For some background, in a map project, I am using a simplified representation of paths as a sequence of segments traversing points either in a straight or curved fashion to make it easier to deal with various map projections and because editing tools exist to generate this representation.

Currently I am converting these descriptions into Bézier paths through Hobby’s splines (an earlier incarnation of the project used MetaPost for rendering, so that seemed obvious). I have implemented this conversion atop Kurbo but given a lack of understanding of the maths, this implementation is basically a conversion of another C implementation. It likely is rather inefficient and not quite as flexible as I’d like it to be. Naturally, I’d much rather prefer using a high-quality implementation.

I think this somewhat overlaps with the ongoing work on offset curves, maybe it is even a by product of it?

raphlinus commented 1 year ago

This is obviously a topic close to my heart, but I think it is out of scope for kurbo. The reason is that there is no one single canonical interpolating spline, but rather a very large family with different tradeoffs. By contrast, the primitives in kurbo tend to be universal or nearly so in the vector graphics space. That includes the offset curve problem, as that is an extremely common operation both for graphics (stroke to fill expansion, which will become a feature in kurbo) and CAD.

The spline crate contains work in progress, and is probably the best place for that to land.

partim commented 1 year ago

Oh, I totally missed spline! From a brief glance it looks like exactly what I need!