[cairo-commit] src/cairo-gstate.c src/cairo-matrix.c

Chris Wilson ickle at kemper.freedesktop.org
Sun Jan 13 03:22:23 PST 2008


 src/cairo-gstate.c |   25 ++++++-------------------
 src/cairo-matrix.c |   25 ++++++-------------------
 2 files changed, 12 insertions(+), 38 deletions(-)

New commits:
commit 3f59ef95482db478230bb7634209bb826b6a06d0
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Sun Jan 13 11:21:39 2008 +0000

    [cairo-matrix] Tidy usage of HAVE_ISFINITE.
    
    Use a macro to switch between isfinite() and its fallback in order to
    avoid using an #ifdef from within a function.

diff --git a/src/cairo-gstate.c b/src/cairo-gstate.c
index 508cf97..099f7ed 100644
--- a/src/cairo-gstate.c
+++ b/src/cairo-gstate.c
@@ -43,7 +43,9 @@
 #include "cairo-gstate-private.h"
 
 #if _XOPEN_SOURCE >= 600 || _ISOC99_SOURCE
-#define HAVE_ISFINITE 1
+#define ISFINITE(x) isfinite (x)
+#else
+#define ISFINITE(x) ((x) * (x) >= 0.) /* check for NaNs */
 #endif
 
 static cairo_status_t
@@ -629,13 +631,8 @@ _cairo_gstate_translate (cairo_gstate_t *gstate, double tx, double ty)
 {
     cairo_matrix_t tmp;
 
-#if HAVE_ISFINITE
-    if (! isfinite (tx) || ! isfinite (ty))
-	return _cairo_error (CAIRO_STATUS_INVALID_MATRIX);
-#else
-    if (! (tx * tx >= 0.) || ! (ty * ty >= 0.)) /* check for NaNs */
+    if (! ISFINITE (tx) || ! ISFINITE (ty))
 	return _cairo_error (CAIRO_STATUS_INVALID_MATRIX);
-#endif
 
     _cairo_gstate_unset_scaled_font (gstate);
 
@@ -659,13 +656,8 @@ _cairo_gstate_scale (cairo_gstate_t *gstate, double sx, double sy)
 
     if (sx * sy == 0.) /* either sx or sy is 0, or det == 0 due to underflow */
 	return _cairo_error (CAIRO_STATUS_INVALID_MATRIX);
-#if HAVE_ISFINITE
-    if (! isfinite (sx) || ! isfinite (sy))
-	return _cairo_error (CAIRO_STATUS_INVALID_MATRIX);
-#else
-    if (! (sx * sx > 0.) || ! (sy * sy > 0.)) /* check for NaNs */
+    if (! ISFINITE (sx) || ! ISFINITE (sy))
 	return _cairo_error (CAIRO_STATUS_INVALID_MATRIX);
-#endif
 
     _cairo_gstate_unset_scaled_font (gstate);
 
@@ -690,13 +682,8 @@ _cairo_gstate_rotate (cairo_gstate_t *gstate, double angle)
     if (angle == 0.)
 	return CAIRO_STATUS_SUCCESS;
 
-#if HAVE_ISFINITE
-    if (! isfinite (angle))
+    if (! ISFINITE (angle))
 	return _cairo_error (CAIRO_STATUS_INVALID_MATRIX);
-#else
-    if (! (angle * angle >= 0.)) /* check for NaNs */
-	return _cairo_error (CAIRO_STATUS_INVALID_MATRIX);
-#endif
 
     _cairo_gstate_unset_scaled_font (gstate);
 
diff --git a/src/cairo-matrix.c b/src/cairo-matrix.c
index df6d3cd..d534826 100644
--- a/src/cairo-matrix.c
+++ b/src/cairo-matrix.c
@@ -39,7 +39,9 @@
 #include "cairoint.h"
 
 #if _XOPEN_SOURCE >= 600 || _ISOC99_SOURCE
-#define HAVE_ISFINITE 1
+#define ISFINITE(x) isfinite (x)
+#else
+#define ISFINITE(x) ((x) * (x) >= 0.) /* check for NaNs */
 #endif
 
 static void
@@ -479,14 +481,8 @@ cairo_matrix_invert (cairo_matrix_t *matrix)
     if (det == 0)
 	return _cairo_error (CAIRO_STATUS_INVALID_MATRIX);
 
-#if HAVE_ISFINITE
-    if (! isfinite (det))
-	return _cairo_error (CAIRO_STATUS_INVALID_MATRIX);
-#else
-    /* this weird construct is for detecting NaNs */
-    if (! (det * det > 0.))
+    if (! ISFINITE (det))
 	return _cairo_error (CAIRO_STATUS_INVALID_MATRIX);
-#endif
 
     _cairo_matrix_compute_adjoint (matrix);
     _cairo_matrix_scalar_multiply (matrix, 1 / det);
@@ -502,14 +498,7 @@ _cairo_matrix_is_invertible (const cairo_matrix_t *matrix)
 
     _cairo_matrix_compute_determinant (matrix, &det);
 
-#if HAVE_ISFINITE
-    if (! isfinite (det))
-	return FALSE;
-
-    return det != 0.;
-#else
-    return det != 0. && det * det > 0.;
-#endif
+    return det != 0. && ISFINITE (det);
 }
 
 void
@@ -533,9 +522,7 @@ _cairo_matrix_compute_scale_factors (const cairo_matrix_t *matrix,
 
     _cairo_matrix_compute_determinant (matrix, &det);
 
-#if HAVE_ISFINITE
-    assert (isfinite (det));
-#endif
+    assert (ISFINITE (det));
 
     if (det == 0)
     {


More information about the cairo-commit mailing list