[cairo] Shouldn't Cairo use/offer degrees rather than radians?
simon at budig.de
Tue Jun 27 10:56:16 UTC 2017
David Kastrup (dak at gnu.org) wrote:
> PostScript uses degrees. PDF uses degrees. Either have a numerically
> stable presentation of right angles, the most important angles a
> rectilinear coordinate system can work with.
You're (in my book) wrong about PDF. PDF does not have a generic
"rotate" operator, it always uses transformation matrices for this
purpose, leaving it up to the application developer to pick his tools.
There is a /Rotate-entry in various object dictionaries, that accepts
0/90/180/270 as value, however, these are the *only* values accepted,
they basically work as an enum, specifying the paper orientation. Using
this as an argument for degrees in cairo is comparing apples and
> In contrast, Cairo uses radians. For every floating point format, PI/4
> has different multiples, as opposed to 45. You don't get guarantees
> (1.5*M_PI/2 - M_PI) == 0.5 * M_PI
> which means that detecting almost any kind of right angle reliably is a
I am not sure what you're trying to prove that "==" returns false when
comparing -0.7854 to 1.5708...
Replacing M_PI with 180 makes that -45 == 90, which is very much false
Did you mean "(1.5*M_PI/2 - M_PI) == -0.25 * M_PI"?
if (1.5 * M_PI / 2.0 - M_PI == -0.25 * M_PI)
printf ("not equal!\n");
returns "equal!" for me. However, I see your point that this is not
guaranteed, and that floating point math can give unexpected results.
Yeah, whenever you're dealing with floating point numbers, the "=="
operator is mostly useless, unless you know *very* exactly what you're
doing. But exchanging M_PI with 180.0 doesn't change that.
Obviously using integer degrees is too limiting for a library like
cairo, so we're always dealing with floats. And then there is no point
to offering degrees.
> So why not provide degrees (and use them internally) for Cairo?
a) 6.12323e-17 is sufficiently zero for basically all usecases
b) the math library trigonometric functions are based on radians
c) degrees are easily made available by a tiny macro.
simon at budig.de http://simon.budig.de/
More information about the cairo