Skip to content

Reaching SVG compatibility***

Posted on:June 29, 2023

I have now implemented all the primitives supported in SVG paths:

They all support intersections with each other, as well as distances and basic transformation (not shearing yet).

How was the Bézier implementation then?

More complicated than expected. I did a bit of diving into what was possible and how I wanted to implement it.

First, for distances of a point to the segment. There were different approaches possible, I went with a solution that is minimising the distance function. Not sure this is the best approach, but this is what worked first.

With Bézier, it is easy to compute a point from the parameter. The other way not so much. I decide to just solve the cubic (quadratic) equation in Y and then check that it works with X.

The next challenge was to check that a point is on the segment. I just reused the logic to find the parameter from the point (and if it cannot find one, then the point is not on the segment.

Finally, the most fun was for intersections. First, for intersections with arcs, I used Wolfram Alpha to formulate the generic equations (of degree 6 and 4) for an intersection between an arc and a cubic or quadratic Bézier curve. I feed this to the different polynomial root finders and take the results.

Bézier to Bézier was the most fun. Instead of going the same way (which has degrees 9 polynomials for cubic cubic), I used an algorithm called [Bézier clipping][clipping]. It is easy to visualise what is going on with that algorithm (and debug issues). A [rust implementation][flo] was very useful to structure what is going on.

[clipping]: (http://nishitalab.org/user/nis/cdrom/cad/CAGD90Curve.pdf [flo]: https://github.com/Logicalshift/flo_curves

I implemented the cubic one first, which made the quadratic very easy to implement. That said, there might be some additional possible implementation lying on the floor.

What’s next?

So, as I mentionned in my last devlog, I will not have much time left to work on pantograph in the next 6 months. Ideally, it would be included in replicad by now, but I will not be able to do it. I prefer to spend a bit of time (when I have some) to polish what I have by looking at how random SVGs I find are imported and behave with the operation that I have implemented.

Generally I would like to have a good story for automatic management of self intersecting shapes when using the draw API, as well as offer full support of offsets.

Another random thought

With the collapse of many communities I followed that were using reddit (i.e. maker stuff around models for 3D printing and boardgame stuff), I have been wondering if I should bodge together an astro blog and a small logic to create summaries of RSS feeds in multiple locations.