[cairo] Shouldn't Cairo use/offer degrees rather than radians?
David Kastrup
dak at gnu.org
Fri Jun 30 20:44:46 UTC 2017
Bill Spitzak <spitzak at gmail.com> writes:
> David's code seems to be an alternative to atan2 that returns degrees.
The patch I posted does not do anything akin to atan2.
> It has a bunch of kludges to hide the fact that the atan2d he is
> calling internally
I am not calling any atan2d.
> apparently just calls atan2 and multiplies by 180/pi. He then has
> another function that is in effect calculating sin() and cos() and has
> even more kludges to detect multiples of 45 degrees.
Are you kidding me? The code I posted does not do anything with
multiples of 45 degrees. It does not detect anything either: it figures
out the quadrant the angle is in while still in degrees and then uses
the pi/180 factor only with respect to the given quadrant in order to
minimize the accumulative error caused by pi/180 not having an exact
representation to start with.
> The work needed in the second function indicates that passing degrees
> does not really help.
A few comparisons?
> Although it seems like it helps as far as I can tell if you don't want
> discontinuities then adjusting the sin/cos results for N*pi/2 is
> exactly the same difficulty whether degrees or radians are used.
N*pi/2 does not have an exact representation. 3*pi/2 may or may not be
pi+pi/2. pi+pi/2 may or may not be 3*pi/2. pi+pi/2+pi/2 is unlikely to
be 2*pi. That is _not_, I repeat _not_ "exactly the same difficulty" as
working with multiples of 90 which are perfectly representable in all
floating point formats in use (9 bits of mantissa will suffice for
binary floating point, and decimal floating point works too).
> Basically it amounts to detecting if a/90 or a/M_PI_2 is near an
> integer, and is thus exactly the same problem.
Sorry, but that's just wrong. Do the same code I did for degrees for
radians, and it just won't work. You won't get dependable zeros for
right angles because right angles don't have a floating point
representation to start with in radians.
--
David Kastrup
More information about the cairo
mailing list