third_party/cairo/src/cairo-pattern.c
void
_cairo_gradient_pattern_fit_to_range (const cairo_gradient_pattern_t *gradient,
				      double			      max_value,
				      cairo_matrix_t                 *out_matrix,
				      cairo_circle_double_t	      out_circle[2])
{
    double dim;

    assert (gradient->base.type == CAIRO_PATTERN_TYPE_LINEAR ||
	    gradient->base.type == CAIRO_PATTERN_TYPE_RADIAL);

    if (gradient->base.type == CAIRO_PATTERN_TYPE_LINEAR) {
	cairo_linear_pattern_t *linear = (cairo_linear_pattern_t *) gradient;

	out_circle[0].center = linear->pd1;
	out_circle[0].radius = 0;
	out_circle[1].center = linear->pd2;
	out_circle[1].radius = 0;

	dim = fabs (linear->pd1.x);
	dim = MAX (dim, fabs (linear->pd1.y));
	dim = MAX (dim, fabs (linear->pd2.x));
	dim = MAX (dim, fabs (linear->pd2.y));
	dim = MAX (dim, fabs (linear->pd1.x - linear->pd2.x));
	dim = MAX (dim, fabs (linear->pd1.y - linear->pd2.y));
    } else {
	cairo_radial_pattern_t *radial = (cairo_radial_pattern_t *) gradient;

	out_circle[0] = radial->cd1;
	out_circle[1] = radial->cd2;

	dim = fabs (radial->cd1.center.x);
	dim = MAX (dim, fabs (radial->cd1.center.y));
	dim = MAX (dim, fabs (radial->cd1.radius));
	dim = MAX (dim, fabs (radial->cd2.center.x));
	dim = MAX (dim, fabs (radial->cd2.center.y));
	dim = MAX (dim, fabs (radial->cd2.radius));
	dim = MAX (dim, fabs (radial->cd1.center.x - radial->cd2.center.x));
	dim = MAX (dim, fabs (radial->cd1.center.y - radial->cd2.center.y));
	dim = MAX (dim, fabs (radial->cd1.radius   - radial->cd2.radius));
    }

    if (unlikely (dim > max_value)) {
	cairo_matrix_t scale;

	dim = max_value / dim;

	out_circle[0].center.x *= dim;
	out_circle[0].center.y *= dim;
	out_circle[0].radius   *= dim;
	out_circle[1].center.x *= dim;
	out_circle[1].center.y *= dim;
	out_circle[1].radius   *= dim;

	cairo_matrix_init_scale (&scale, dim, dim);
	cairo_matrix_multiply (out_matrix, &gradient->base.matrix, &scale);
    } else {
	*out_matrix = gradient->base.matrix;
    }
}
/**
 * _cairo_gradient_pattern_fit_to_range:
 *
 * Scale the extremes of a gradient to guarantee that the coordinates
 * and their deltas are within the range (-max_value, max_value). The
 * new extremes are stored in out_circle.
 *
 * The pattern matrix is scaled to guarantee that the aspect of the
 * gradient is the same and the result is stored in out_matrix.
 *
 **/
Scale the extremes of a gradient to guarantee that the coordinates
and their deltas are within the range (-max_value, max_value). The
new extremes are stored in out_circle.

The pattern matrix is scaled to guarantee that the aspect of the
gradient is the same and the result is stored in out_matrix.
Scale the extremes of a gradient to guarantee that the coordinates and their deltas are within the range ( - max_value max_value ) . The new extremes are stored in out_circle . The pattern matrix is scaled to guarantee that the aspect of the gradient is the same and the result is stored in out_matrix .
void
_cairo_gradient_pattern_fit_to_range (const cairo_gradient_pattern_t *gradient,
				      double			      max_value,
				      cairo_matrix_t                 *out_matrix,
				      cairo_circle_double_t	      out_circle[2])
{
    double dim;
    assert (gradient->base.type == CAIRO_PATTERN_TYPE_LINEAR ||
	    gradient->base.type == CAIRO_PATTERN_TYPE_RADIAL);
    if (gradient->base.type == CAIRO_PATTERN_TYPE_LINEAR) {
	cairo_linear_pattern_t *linear = (cairo_linear_pattern_t *) gradient;
	out_circle[0].center = linear->pd1;
	out_circle[0].radius = 0;
	out_circle[1].center = linear->pd2;
	out_circle[1].radius = 0;
	dim = fabs (linear->pd1.x);
	dim = MAX (dim, fabs (linear->pd1.y));
	dim = MAX (dim, fabs (linear->pd2.x));
	dim = MAX (dim, fabs (linear->pd2.y));
	dim = MAX (dim, fabs (linear->pd1.x - linear->pd2.x));
	dim = MAX (dim, fabs (linear->pd1.y - linear->pd2.y));
    } else {
	cairo_radial_pattern_t *radial = (cairo_radial_pattern_t *) gradient;
	out_circle[0] = radial->cd1;
	out_circle[1] = radial->cd2;
	dim = fabs (radial->cd1.center.x);
	dim = MAX (dim, fabs (radial->cd1.center.y));
	dim = MAX (dim, fabs (radial->cd1.radius));
	dim = MAX (dim, fabs (radial->cd2.center.x));
	dim = MAX (dim, fabs (radial->cd2.center.y));
	dim = MAX (dim, fabs (radial->cd2.radius));
	dim = MAX (dim, fabs (radial->cd1.center.x - radial->cd2.center.x));
	dim = MAX (dim, fabs (radial->cd1.center.y - radial->cd2.center.y));
	dim = MAX (dim, fabs (radial->cd1.radius   - radial->cd2.radius));
    }
    if (unlikely (dim > max_value)) {
	cairo_matrix_t scale;
	dim = max_value / dim;
	out_circle[0].center.x *= dim;
	out_circle[0].center.y *= dim;
	out_circle[0].radius   *= dim;
	out_circle[1].center.x *= dim;
	out_circle[1].center.y *= dim;
	out_circle[1].radius   *= dim;
	cairo_matrix_init_scale (&scale, dim, dim);
	cairo_matrix_multiply (out_matrix, &gradient->base.matrix, &scale);
    } else {
	*out_matrix = gradient->base.matrix;
    }
}
void _cairo_gradient_pattern_fit_to_range ( const cairo_gradient_pattern_t * gradient , double max_value , cairo_matrix_t * out_matrix , cairo_circle_double_t out_circle [ 2 ] ) { double dim ; assert ( gradient -> base . type == CAIRO_PATTERN_TYPE_LINEAR || gradient -> base . type == CAIRO_PATTERN_TYPE_RADIAL ) ; if ( gradient -> base . type == CAIRO_PATTERN_TYPE_LINEAR ) { cairo_linear_pattern_t * linear = ( cairo_linear_pattern_t * ) gradient ; out_circle [ 0 ] . center = linear -> pd1 ; out_circle [ 0 ] . radius = 0 ; out_circle [ 1 ] . center = linear -> pd2 ; out_circle [ 1 ] . radius = 0 ; dim = fabs ( linear -> pd1 . x ) ; dim = MAX ( dim , fabs ( linear -> pd1 . y ) ) ; dim = MAX ( dim , fabs ( linear -> pd2 . x ) ) ; dim = MAX ( dim , fabs ( linear -> pd2 . y ) ) ; dim = MAX ( dim , fabs ( linear -> pd1 . x - linear -> pd2 . x ) ) ; dim = MAX ( dim , fabs ( linear -> pd1 . y - linear -> pd2 . y ) ) ; } else { cairo_radial_pattern_t * radial = ( cairo_radial_pattern_t * ) gradient ; out_circle [ 0 ] = radial -> cd1 ; out_circle [ 1 ] = radial -> cd2 ; dim = fabs ( radial -> cd1 . center . x ) ; dim = MAX ( dim , fabs ( radial -> cd1 . center . y ) ) ; dim = MAX ( dim , fabs ( radial -> cd1 . radius ) ) ; dim = MAX ( dim , fabs ( radial -> cd2 . center . x ) ) ; dim = MAX ( dim , fabs ( radial -> cd2 . center . y ) ) ; dim = MAX ( dim , fabs ( radial -> cd2 . radius ) ) ; dim = MAX ( dim , fabs ( radial -> cd1 . center . x - radial -> cd2 . center . x ) ) ; dim = MAX ( dim , fabs ( radial -> cd1 . center . y - radial -> cd2 . center . y ) ) ; dim = MAX ( dim , fabs ( radial -> cd1 . radius - radial -> cd2 . radius ) ) ; } if ( unlikely ( dim > max_value ) ) { cairo_matrix_t scale ; dim = max_value / dim ; out_circle [ 0 ] . center . x *= dim ; out_circle [ 0 ] . center . y *= dim ; out_circle [ 0 ] . radius *= dim ; out_circle [ 1 ] . center . x *= dim ; out_circle [ 1 ] . center . y *= dim ; out_circle [ 1 ] . radius *= dim ; cairo_matrix_init_scale ( & scale , dim , dim ) ; cairo_matrix_multiply ( out_matrix , & gradient -> base . matrix , & scale ) ; } else { * out_matrix = gradient -> base . matrix ; } }
_cairo_gradient_pattern_fit_to_range:
 Scale the extremes of a gradient to guarantee that the coordinates
 and their deltas are within the range (-max_value, max_value).
_cairo_gradient_pattern_fit_to_range : Scale the extremes of a gradient to guarantee that the coordinates and their deltas are within the range ( - max_value max_value ) .