diff --git a/src/cairo-pattern.c b/src/cairo-pattern.c index 6eea9a6..4fb352e 100644 --- a/src/cairo-pattern.c +++ b/src/cairo-pattern.c @@ -373,9 +373,9 @@ cairo_pattern_create_rgb (double red, do cairo_pattern_t *pattern; cairo_color_t color; - _cairo_restrict_value (&red, 0.0, 1.0); - _cairo_restrict_value (&green, 0.0, 1.0); - _cairo_restrict_value (&blue, 0.0, 1.0); + red = CLAMP (red, 0.0, 1.0); + green = CLAMP (green, 0.0, 1.0); + blue = CLAMP (blue, 0.0, 1.0); _cairo_color_init_rgb (&color, red, green, blue); @@ -416,10 +416,10 @@ cairo_pattern_create_rgba (double red, d cairo_pattern_t *pattern; cairo_color_t color; - _cairo_restrict_value (&red, 0.0, 1.0); - _cairo_restrict_value (&green, 0.0, 1.0); - _cairo_restrict_value (&blue, 0.0, 1.0); - _cairo_restrict_value (&alpha, 0.0, 1.0); + red = CLAMP (red, 0.0, 1.0); + green = CLAMP (green, 0.0, 1.0); + blue = CLAMP (blue, 0.0, 1.0); + alpha = CLAMP (alpha, 0.0, 1.0); _cairo_color_init_rgba (&color, red, green, blue, alpha); @@ -868,10 +868,10 @@ cairo_pattern_add_color_stop_rgb (cairo_ return; } - _cairo_restrict_value (&offset, 0.0, 1.0); - _cairo_restrict_value (&red, 0.0, 1.0); - _cairo_restrict_value (&green, 0.0, 1.0); - _cairo_restrict_value (&blue, 0.0, 1.0); + offset = CLAMP (offset, 0.0, 1.0); + red = CLAMP (red, 0.0, 1.0); + green = CLAMP (green, 0.0, 1.0); + blue = CLAMP (blue, 0.0, 1.0); _cairo_pattern_add_color_stop ((cairo_gradient_pattern_t *) pattern, offset, red, green, blue, 1.0); @@ -922,11 +922,11 @@ cairo_pattern_add_color_stop_rgba (cairo return; } - _cairo_restrict_value (&offset, 0.0, 1.0); - _cairo_restrict_value (&red, 0.0, 1.0); - _cairo_restrict_value (&green, 0.0, 1.0); - _cairo_restrict_value (&blue, 0.0, 1.0); - _cairo_restrict_value (&alpha, 0.0, 1.0); + offset = CLAMP (offset, 0.0, 1.0); + red = CLAMP (red, 0.0, 1.0); + green = CLAMP (green, 0.0, 1.0); + blue = CLAMP (blue, 0.0, 1.0); + alpha = CLAMP (alpha, 0.0, 1.0); _cairo_pattern_add_color_stop ((cairo_gradient_pattern_t *) pattern, offset, red, green, blue, alpha); diff --git a/src/cairo.c b/src/cairo.c index 73c2dc4..925836e 100644 --- a/src/cairo.c +++ b/src/cairo.c @@ -854,7 +854,7 @@ cairo_set_tolerance (cairo_t *cr, double if (cr->status) return; - _cairo_restrict_value (&tolerance, CAIRO_TOLERANCE_MINIMUM, tolerance); + tolerance = MAX (tolerance, CAIRO_TOLERANCE_MINIMUM); status = _cairo_gstate_set_tolerance (cr->gstate, tolerance); if (status) @@ -945,7 +945,7 @@ cairo_set_line_width (cairo_t *cr, doubl if (cr->status) return; - _cairo_restrict_value (&width, 0.0, width); + width = MAX (width, 0.0); status = _cairo_gstate_set_line_width (cr->gstate, width); if (status) @@ -3555,15 +3555,6 @@ cairo_status_to_string (cairo_status_t s return ""; } -void -_cairo_restrict_value (double *value, double min, double max) -{ - if (*value < min) - *value = min; - else if (*value > max) - *value = max; -} - /* This function is identical to the C99 function lround(), except that it * performs arithmetic rounding (instead of away-from-zero rounding) and * has a valid input range of (INT_MIN, INT_MAX] instead of diff --git a/src/cairoint.h b/src/cairoint.h index c5cdf1a..18d1d3d 100644 --- a/src/cairoint.h +++ b/src/cairoint.h @@ -82,6 +82,10 @@ #define MIN(a, b) ((a) < (b) ? (a) : (b) #undef MAX #define MAX(a, b) ((a) > (b) ? (a) : (b)) +#undef CLAMP +#define CLAMP(x, lo, hi) (((x) > (hi)) ? (hi) : (((x) < (lo)) ? (lo) : (x))) + + #ifndef FALSE #define FALSE 0 #endif