third_party/cairo/src/cairo-pattern.c
void
_cairo_gradient_pattern_interpolate (const cairo_gradient_pattern_t *gradient,
				     double			     t,
				     cairo_circle_double_t	    *out_circle)
{
    assert (gradient->base.type == CAIRO_PATTERN_TYPE_LINEAR ||
	    gradient->base.type == CAIRO_PATTERN_TYPE_RADIAL);

#define lerp(a,b) (a)*(1-t) + (b)*t

    if (gradient->base.type == CAIRO_PATTERN_TYPE_LINEAR) {
	cairo_linear_pattern_t *linear = (cairo_linear_pattern_t *) gradient;
	out_circle->center.x = lerp (linear->pd1.x, linear->pd2.x);
	out_circle->center.y = lerp (linear->pd1.y, linear->pd2.y);
	out_circle->radius = 0;
    } else {
	cairo_radial_pattern_t *radial = (cairo_radial_pattern_t *) gradient;
	out_circle->center.x = lerp (radial->cd1.center.x, radial->cd2.center.x);
	out_circle->center.y = lerp (radial->cd1.center.y, radial->cd2.center.y);
	out_circle->radius   = lerp (radial->cd1.radius  , radial->cd2.radius);
    }

#undef lerp
}
/**
 * _cairo_gradient_pattern_interpolate:
 *
 * Interpolate between the start and end objects of linear or radial
 * gradients.  The interpolated object is stored in out_circle, with
 * the radius being zero in the linear gradient case.
 **/
Interpolate between the start and end objects of linear or radial
gradients.  The interpolated object is stored in out_circle, with
the radius being zero in the linear gradient case.
Interpolate between the start and end objects of linear or radial gradients . The interpolated object is stored in out_circle with the radius being zero in the linear gradient case .
void
_cairo_gradient_pattern_interpolate (const cairo_gradient_pattern_t *gradient,
				     double			     t,
				     cairo_circle_double_t	    *out_circle)
{
    assert (gradient->base.type == CAIRO_PATTERN_TYPE_LINEAR ||
	    gradient->base.type == CAIRO_PATTERN_TYPE_RADIAL);
#define lerp(a,b) (a)*(1-t) + (b)*t
    if (gradient->base.type == CAIRO_PATTERN_TYPE_LINEAR) {
	cairo_linear_pattern_t *linear = (cairo_linear_pattern_t *) gradient;
	out_circle->center.x = lerp (linear->pd1.x, linear->pd2.x);
	out_circle->center.y = lerp (linear->pd1.y, linear->pd2.y);
	out_circle->radius = 0;
    } else {
	cairo_radial_pattern_t *radial = (cairo_radial_pattern_t *) gradient;
	out_circle->center.x = lerp (radial->cd1.center.x, radial->cd2.center.x);
	out_circle->center.y = lerp (radial->cd1.center.y, radial->cd2.center.y);
	out_circle->radius   = lerp (radial->cd1.radius  , radial->cd2.radius);
    }
#undef lerp
}
void _cairo_gradient_pattern_interpolate ( const cairo_gradient_pattern_t * gradient , double t , cairo_circle_double_t * out_circle ) { assert ( gradient -> base . type == CAIRO_PATTERN_TYPE_LINEAR || gradient -> base . type == CAIRO_PATTERN_TYPE_RADIAL ) ; #define lerp ( a , b )  (a)*(1-t) + (b)*t if ( gradient -> base . type == CAIRO_PATTERN_TYPE_LINEAR ) { cairo_linear_pattern_t * linear = ( cairo_linear_pattern_t * ) gradient ; out_circle -> center . x = lerp ( linear -> pd1 . x , linear -> pd2 . x ) ; out_circle -> center . y = lerp ( linear -> pd1 . y , linear -> pd2 . y ) ; out_circle -> radius = 0 ; } else { cairo_radial_pattern_t * radial = ( cairo_radial_pattern_t * ) gradient ; out_circle -> center . x = lerp ( radial -> cd1 . center . x , radial -> cd2 . center . x ) ; out_circle -> center . y = lerp ( radial -> cd1 . center . y , radial -> cd2 . center . y ) ; out_circle -> radius = lerp ( radial -> cd1 . radius , radial -> cd2 . radius ) ; } #undef  lerp }
_cairo_gradient_pattern_interpolate:
 Interpolate between the start and end objects of linear or radial
 gradients.
_cairo_gradient_pattern_interpolate : Interpolate between the start and end objects of linear or radial gradients .