cairo_rotate inherently inaccurate
Submitted by M Welinder
Assigned to Chris Wilson @ickle
Description
cairo_rotate takes its argument in radians which is one of those things that work better on a blackboard than on a computer.
Consider the angle M_PI/2. When this angle is rounded to its closest "double" representative x, we have sin(x)=1 [good!] but cos(x)=6.12323e-17 [not good].
This is an API problem: the damage is already done when cairo_rotate is entered.
Suggestions:
-
Add cairo_rotate_degrees and/or cairo_rotate_pi, the latter taking an angle argument that is 2 for a full rotation.
-
Make the backend api use an angle argument that is 2 for a full turn.
-
Use the IEEE 754-2008 functions sinpi and cospi in the backends where they currently use sin and cos.
http://www.math.fsu.edu/~gallivan/courses/FCM1/IEEE-fpstandard-2008.pdf.gz
The sinpi and cospi functions are fairly easy to implement. Feel free to grab code from https://git.gnome.org/browse/goffice/tree/goffice/math/go-math.c lines 942-1043 which also has tanpi and atan2pi.
Benefits: the matrices will actually have zeros where you would expect them. Rotating by 90 degrees four times will actually bring you back where you started.