mirror of
https://gitlab.freedesktop.org/cairo/cairo.git
synced 2026-05-05 06:28:01 +02:00
[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.
This commit is contained in:
parent
5e32dcf863
commit
3f59ef9548
2 changed files with 12 additions and 38 deletions
|
|
@ -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))
|
||||
if (! ISFINITE (tx) || ! ISFINITE (ty))
|
||||
return _cairo_error (CAIRO_STATUS_INVALID_MATRIX);
|
||||
#else
|
||||
if (! (tx * tx >= 0.) || ! (ty * ty >= 0.)) /* check for NaNs */
|
||||
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))
|
||||
if (! ISFINITE (sx) || ! ISFINITE (sy))
|
||||
return _cairo_error (CAIRO_STATUS_INVALID_MATRIX);
|
||||
#else
|
||||
if (! (sx * sx > 0.) || ! (sy * sy > 0.)) /* check for NaNs */
|
||||
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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
if (! ISFINITE (det))
|
||||
return _cairo_error (CAIRO_STATUS_INVALID_MATRIX);
|
||||
#else
|
||||
/* this weird construct is for detecting NaNs */
|
||||
if (! (det * det > 0.))
|
||||
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)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue