[cairo] Shouldn't Cairo use/offer degrees rather than radians?

David Kastrup dak at gnu.org
Thu Jun 29 06:08:04 UTC 2017


Lawrence D'Oliveiro <ldo at geek-central.gen.nz> writes:

> On Thu, 29 Jun 2017 06:37:50 +0200, David Kastrup wrote:
>
>> No: I already showed the kind of code I was going to use instead and
>> that would avoid any discontinuities and would make for perfect
>> periodicity (the "discontinuity" would get stuffed into sin(pi/2+eps)
>> which is approximately 1+eps^2/2 and thus not likely to show any
>> staircasing).
>
> You realize that, by introducing this distortion, you are reducing the
> accuracy of the computation?

It replaces a sin(x)/cos(x) pair by a sin(x)/sin(pi/2-x) pair.  The
largest cumulative effect is at pi/4.  Here we are talking about an
offset of pi/4 in the argument which is less than 1.  Consequently the
mean inaccuracy introduced in the argument is less than 1ulp and the
mean inaccuracy in the result is less than 0.7ulp.

> I wonder what the term is, for deliberately producing inaccurate
> answers just to look good...

A very well-considered tradeoff and solid engineering?

Applying cairo_rotate(M_PI/4) two times will likely show slightly better
(but still incorrect) magnitude than applying cairo_rotate_deg(45) two
times, but the latter will show actual zeroes where they belong.
Applying them 1000000 times will give better (but still wrong) magnitude
but a skewed angle for the former and perfect angle but marginally less
correct magnitude for the latter.

At the same time, results for the statistically much more prevalent
rotations by multiples of 90 degrees will be perfect without introducing
any discontinuities (like the Ghostscript approach).  Also heuristics
based on recognizing straight lines will work without having to
introduce "tolerances" and thus much larger discontinuities than even
Ghostscript has.

At any rate, you are free to continue using cairo_rotate exclusively, so
what is your actual fear here?

-- 
David Kastrup



More information about the cairo mailing list