Issue
I'm following the source code of OpenJFX. The PathIterator
only supports SEG_LINETO
, SEG_QUADTO
, SEG_CUBICTO
, which are lines and quadratic/cubic Bézier curves. ArcIterator
and EllipseIterator
returns SEG_CUBICTO
, which means that it will use cubic Bézier curve segments. Since cubic Bézier curves can't represent ellipse accurately, I think Javafx ellipses and arcs are not genuine but actually approximations. Is this right?
Solution
Both ArcIteratpr and EllipseIterator iterate over (true) ellipses and yield (a sequence of one or more) cubic Bézier curves that approximate the arc/ellipse in question.
So no, you're not working with "true" arcs and ellipses when iterating over them for pathing purpose, but the Arc2D
and Ellipse2D
classes themselves are 100% true arc and ellipse definitions. The only time you get Béziers is when they get converted "because it's safe to do so": you don't need exact representations when you're doing things like drawing them to the screen. They just need to be accurate at the sub-pixel level for proper anti-aliasing.
So: are they? The ellipse iterator uses four cubic Béziers, which is the industry standard because of how accurate it is for how simple it is to construct, so how close to the real ellipse is that? Well, the maximum error between a single cubic and a quarter of a true ellipse is 0.00027 for a unit ellipse (i.e. a circle with radius 1). To put that into perspective, that's at most 2.7 pixels off for an ellipse that's 20,000 pixels across at its widest. Or, put another way: it's accurate enough for sub-pixel accuracy for ellipses that are 5,000 pixels across at their widest, which even on a 300dpi screen would be a shape so big that it doesn't even fit the physical dimensions of devices with that kind of resolution.
You will never notice this difference. So: no, cubic Bézier curves can't represent ellipses perfectly, but then can represent them accurately enough as to be indistinguishable from the real thing.
Answered By - Mike 'Pomax' Kamermans
Answer Checked By - Gilberto Lyons (JavaFixing Admin)