[cairo] sincos patch final(?) patch

Behdad Esfahbod behdad at cs.toronto.edu
Mon Sep 12 20:50:26 PDT 2005


Hi,

I updated the sincos patch to reflect Owen's feedback.  I think
the patch can be applied now.


Cheers,

--behdad
http://behdad.org/
-------------- next part --------------
Index: configure.in
===================================================================
RCS file: /cvs/cairo/cairo/configure.in,v
retrieving revision 1.142
diff -u -p -r1.142 configure.in
--- configure.in	12 Sep 2005 18:11:33 -0000	1.142
+++ configure.in	13 Sep 2005 03:48:44 -0000
@@ -81,6 +81,8 @@ AC_CHECK_LIBM
 
 LIBS="$LIBS $LIBM"
 
+AC_CHECK_FUNCS(sincos)
+
 dnl ===========================================================================
 
 AC_ARG_ENABLE(xlib,
Index: src/cairo-arc.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-arc.c,v
retrieving revision 1.5
diff -u -p -r1.5 cairo-arc.c
--- src/cairo-arc.c	22 Aug 2005 23:50:30 -0000	1.5
+++ src/cairo-arc.c	13 Sep 2005 03:48:44 -0000
@@ -59,7 +59,10 @@
 static double
 _arc_error_normalized (double angle)
 {
-    return 2.0/27.0 * pow (sin (angle / 4), 6) / pow (cos (angle / 4), 2);
+    double s, c;
+
+    _cairo_sincos (angle / 4, &s, &c);
+    return 2.0/27.0 * pow (s, 6) / pow (c, 2);
 }
 
 static double
@@ -154,10 +157,12 @@ _cairo_arc_segment (cairo_t *cr,
     double r_sin_B, r_cos_B;
     double h;
 
-    r_sin_A = radius * sin (angle_A);
-    r_cos_A = radius * cos (angle_A);
-    r_sin_B = radius * sin (angle_B);
-    r_cos_B = radius * cos (angle_B);
+    _cairo_sincos (angle_A, &r_sin_A, &r_cos_A);
+    _cairo_sincos (angle_B, &r_sin_B, &r_cos_B);
+    r_sin_A *= radius;
+    r_cos_A *= radius;
+    r_sin_B *= radius;
+    r_cos_B *= radius;
 
     h = 4.0/3.0 * tan ((angle_B - angle_A) / 4.0);
 
Index: src/cairo-matrix.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-matrix.c,v
retrieving revision 1.34
diff -u -p -r1.34 cairo-matrix.c
--- src/cairo-matrix.c	12 Sep 2005 18:11:33 -0000	1.34
+++ src/cairo-matrix.c	13 Sep 2005 03:48:44 -0000
@@ -227,12 +227,13 @@ void
 cairo_matrix_init_rotate (cairo_matrix_t *matrix,
 			  double radians)
 {
-    double  s;
-    double  c;
+    double  s, c;
 
     s = sin (radians);
     c = cos (radians);
 
+    _cairo_sincos (radians, &s, &c);
+
     cairo_matrix_init (matrix,
 		       c, s,
 		       -s, c,
Index: src/cairo-pattern.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-pattern.c,v
retrieving revision 1.65
diff -u -p -r1.65 cairo-pattern.c
--- src/cairo-pattern.c	30 Aug 2005 17:42:17 -0000	1.65
+++ src/cairo-pattern.c	13 Sep 2005 03:48:44 -0000
@@ -1173,6 +1173,8 @@ _cairo_image_data_set_radial (cairo_radi
 		denumerator = -2.0 * c0_e * c0_c1;
 		
 		if (denumerator != 0.0) {
+		    double s, c;
+
 		    fraction = (c1_e * c1_e - c0_e * c0_e - c0_c1 * c0_c1) /
 			denumerator;
 
@@ -1183,8 +1185,9 @@ _cairo_image_data_set_radial (cairo_radi
 		    
 		    angle_c0 = acos (fraction);
 		    
-		    c0_y = cos (angle_c0) * c0_c1;
-		    c1_y = sin (angle_c0) * c0_c1;
+		    _cairo_sincos (angle_c0, &s, &c);
+		    c0_y = c * c0_c1;
+		    c1_y = s * c0_c1;
 		    
 		    y_x = sqrt (r1_2 - c1_y * c1_y);
 		    c0_x = y_x + c0_y;
Index: src/cairo-pen.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-pen.c,v
retrieving revision 1.25
diff -u -p -r1.25 cairo-pen.c
--- src/cairo-pen.c	22 Aug 2005 23:48:28 -0000	1.25
+++ src/cairo-pen.c	13 Sep 2005 03:48:44 -0000
@@ -102,8 +102,12 @@ _cairo_pen_init (cairo_pen_t *pen, doubl
      */
     for (i=0; i < pen->num_vertices; i++) {
 	double theta = 2 * M_PI * i / (double) pen->num_vertices;
-	double dx = radius * cos (reflect ? -theta : theta);
-	double dy = radius * sin (reflect ? -theta : theta);
+	double s, c;
+	double dx, dy;
+
+	_cairo_sincos (reflect ? -theta : theta, &s, &c);
+	dx = radius * c;
+	dy = radius * s;
 	cairo_pen_vertex_t *v = &pen->vertices[i];
 	cairo_matrix_transform_distance (&gstate->ctm, &dx, &dy);
 	v->point.x = _cairo_fixed_from_double (dx);
Index: src/cairo.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo.c,v
retrieving revision 1.136
diff -u -p -r1.136 cairo.c
--- src/cairo.c	24 Aug 2005 13:09:11 -0000	1.136
+++ src/cairo.c	13 Sep 2005 03:48:44 -0000
@@ -1125,6 +1125,8 @@ cairo_arc (cairo_t *cr,
 	   double radius,
 	   double angle1, double angle2)
 {
+    double s, c;
+
     if (cr->status)
 	return;
 
@@ -1135,9 +1137,11 @@ cairo_arc (cairo_t *cr,
     while (angle2 < angle1)
 	angle2 += 2 * M_PI;
 
+    _cairo_sincos (angle1, &s, &c);
+
     cairo_line_to (cr,
-		   xc + radius * cos (angle1),
-		   yc + radius * sin (angle1));
+		   xc + radius * c,
+		   yc + radius * s);
 
     _cairo_arc_path (cr, xc, yc, radius,
 		     angle1, angle2);
@@ -1167,6 +1171,8 @@ cairo_arc_negative (cairo_t *cr,
 		    double radius,
 		    double angle1, double angle2)
 {
+    double s, c;
+
     if (cr->status)
 	return;
 
@@ -1177,9 +1183,11 @@ cairo_arc_negative (cairo_t *cr,
     while (angle2 > angle1)
 	angle2 -= 2 * M_PI;
 
+    _cairo_sincos (angle1, &s, &c);
+
     cairo_line_to (cr,
-		   xc + radius * cos (angle1),
-		   yc + radius * sin (angle1));
+		   xc + radius * c,
+		   yc + radius * s);
 
      _cairo_arc_path_negative (cr, xc, yc, radius,
 			       angle1, angle2);
Index: src/cairoint.h
===================================================================
RCS file: /cvs/cairo/cairo/src/cairoint.h,v
retrieving revision 1.210
diff -u -p -r1.210 cairoint.h
--- src/cairoint.h	7 Sep 2005 23:57:59 -0000	1.210
+++ src/cairoint.h	13 Sep 2005 03:48:44 -0000
@@ -66,6 +66,19 @@
 #include "cairo-debug.h"
 #include <pixman.h>
 
+
+#define _GNU_SOURCE               /* Needed for sincos() in math.h */
+
+#if HAVE_SINCOS
+# define _cairo_sincos(angle,s,c) sincos((angle), (s), (c))
+#else
+# define _cairo_sincos(angle,s,c) do { \
+	double _sincos_angle = (angle); \
+	*(s) = sin (_sincos_angle); \
+	*(c) = cos (_sincos_angle); \
+	} while (0)
+#endif
+
 #if __GNUC__ >= 3 && defined(__ELF__)
 # define slim_hidden_proto(name)	slim_hidden_proto1(name, INT_##name)
 # define slim_hidden_def(name)		slim_hidden_def1(name, INT_##name)


More information about the cairo mailing list