Rewrite _cairo_matrix_transform_bounding_box to actually accept a box not a rectangle

It turns out that all of the callers want a box anyway, so this
simplfies the code in addition to being more honest to the name.

(For those new to the convention, a "box" is an (x1,y2),(x2,y2)
pair while a "rectangle" is an (x,y),(width,height) pair.)
This commit is contained in:
Carl Worth 2006-11-07 01:42:21 -08:00
parent 777eaf326a
commit fc584e1fbb
4 changed files with 29 additions and 42 deletions

View file

@ -712,17 +712,12 @@ _cairo_gstate_backend_to_user_rectangle (cairo_gstate_t *gstate,
double *x2, double *y2,
cairo_bool_t *is_tight)
{
double width = *x2 - *x1;
double height = *y2 - *y1;
cairo_matrix_t matrix_inverse;
cairo_matrix_multiply (&matrix_inverse, &gstate->ctm_inverse,
&gstate->target->device_transform_inverse);
_cairo_matrix_transform_bounding_box (
&matrix_inverse, x1, y1, &width, &height, is_tight);
*x2 = *x1 + width;
*y2 = *y1 + height;
_cairo_matrix_transform_bounding_box (&matrix_inverse,
x1, y1, x2, y2, is_tight);
}
/* XXX: NYI

View file

@ -357,35 +357,30 @@ slim_hidden_def(cairo_matrix_transform_point);
void
_cairo_matrix_transform_bounding_box (const cairo_matrix_t *matrix,
double *x, double *y,
double *width, double *height,
double *x1, double *y1,
double *x2, double *y2,
cairo_bool_t *is_tight)
{
int i;
double quad_x[4], quad_y[4];
double dx1, dy1;
double dx2, dy2;
double min_x, max_x;
double min_y, max_y;
quad_x[0] = *x;
quad_y[0] = *y;
quad_x[0] = *x1;
quad_y[0] = *y1;
cairo_matrix_transform_point (matrix, &quad_x[0], &quad_y[0]);
dx1 = *width;
dy1 = 0;
cairo_matrix_transform_distance (matrix, &dx1, &dy1);
quad_x[1] = quad_x[0] + dx1;
quad_y[1] = quad_y[0] + dy1;
quad_x[1] = *x2;
quad_y[1] = *y1;
cairo_matrix_transform_point (matrix, &quad_x[1], &quad_y[1]);
dx2 = 0;
dy2 = *height;
cairo_matrix_transform_distance (matrix, &dx2, &dy2);
quad_x[2] = quad_x[0] + dx2;
quad_y[2] = quad_y[0] + dy2;
quad_x[2] = *x1;
quad_y[2] = *y2;
cairo_matrix_transform_point (matrix, &quad_x[2], &quad_y[2]);
quad_x[3] = quad_x[0] + dx1 + dx2;
quad_y[3] = quad_y[0] + dy1 + dy2;
quad_x[3] = *x2;
quad_y[3] = *y2;
cairo_matrix_transform_point (matrix, &quad_x[3], &quad_y[3]);
min_x = max_x = quad_x[0];
min_y = max_y = quad_y[0];
@ -402,10 +397,10 @@ _cairo_matrix_transform_bounding_box (const cairo_matrix_t *matrix,
max_y = quad_y[i];
}
*x = min_x;
*y = min_y;
*width = max_x - min_x;
*height = max_y - min_y;
*x1 = min_x;
*y1 = min_y;
*x2 = max_x;
*y2 = max_y;
if (is_tight) {
/* it's tight if and only if the four corner points form an axis-aligned

View file

@ -1173,20 +1173,17 @@ _cairo_pattern_acquire_surface_for_surface (cairo_surface_pattern_t *pattern,
* clone only that portion of the surface that will be
* read. */
if (! _cairo_matrix_is_identity (&attr->matrix)) {
double src_x = x;
double src_y = y;
double src_width = width;
double src_height = height;
double x2, y2;
double x1 = x;
double y1 = y;
double x2 = x + width;
double y2 = y + height;
cairo_bool_t is_tight;
_cairo_matrix_transform_bounding_box (&attr->matrix, &src_x, &src_y,
&src_width, &src_height,
_cairo_matrix_transform_bounding_box (&attr->matrix,
&x1, &y1, &x2, &y2,
&is_tight);
x2 = src_x + src_width;
y2 = src_y + src_height;
x = floor (src_x);
y = floor (src_y);
x = floor (x1);
y = floor (y1);
width = ceil (x2) - x;
height = ceil (y2) - y;
}

View file

@ -2173,8 +2173,8 @@ _cairo_matrix_get_affine (const cairo_matrix_t *matrix,
cairo_private void
_cairo_matrix_transform_bounding_box (const cairo_matrix_t *matrix,
double *x, double *y,
double *width, double *height,
double *x1, double *y1,
double *x2, double *y2,
cairo_bool_t *is_tight);
cairo_private void