With pantograph 0.2 I have added the arc data structure, and everything to make them work as part of the current pantograph API.
How do other project handle it
Before implementing anything I did a small survey of how other people define their arc structure.
One of the tricky part is to handle the orientation of the circle, as well as how it behaves with transformation.
maker.js
The data structure here is the center of the circle, its radius and a start and end angle. The angle can be larger than 360, and are oriented such that the end angle is always greater than the start angle.
The angles are swapped when necessary during a mirror operation.
flatten-js
The data structure here is the center of the circle, its radius and a start and end angle as well as a clockwise flag.
The clockwise flag is swapped when mirroring
cavalier contours
The data structure in cavalier contour is a start point, an endpoint and a bulge (length of the sagitta in units of half of the chord).
I am not sure how that would behave with scaling, rotation and mirror (which are not part of cavalier contours).
SVG
SVG uses the same data structure for arc of circle or ellipses (the arc of circle is a particular case of the ellipse). It consists its radius, both start and end point as well as a “large arc sweep” and “sweep” flag.
What I implemented
In order to fully define which arc it is - I added the center of the circle and a clockwise flag. This seemed the best compromise with what I try to achieve:
- it is relatively straightforward to transform (we just transform the points, and flip the clockwise flag when necessary).
- arcs are segments of a circle, with a start point and an end point so I keep them as part of the data structure.
- the values are easy to interpret (easier than the SVG flags at least).
The angles are very useful for many operations. They are also computed and
stored as angles in the [0, 2 * PI]
interval. There is also a parameter
equivalent that is fixed in the interval [0, 1]
and takes into account the
clockwise or counter clockwise orientation.