[evolution/rendering-cleanup: 40/63] gnome-canvas: Split out matrix_transform_rect code



commit aec79928e398867e03797ae6627038d963d7804a
Author: Benjamin Otte <otte redhat com>
Date:   Fri Oct 15 11:00:27 2010 +0200

    gnome-canvas: Split out matrix_transform_rect code

 libgnomecanvas/gnome-canvas-shape.c |   45 +----------------------------
 libgnomecanvas/gnome-canvas-util.c  |   55 +++++++++++++++++++++++++++++++++++
 libgnomecanvas/gnome-canvas-util.h  |    2 +
 3 files changed, 58 insertions(+), 44 deletions(-)
---
diff --git a/libgnomecanvas/gnome-canvas-shape.c b/libgnomecanvas/gnome-canvas-shape.c
index 9029970..d1ad26c 100644
--- a/libgnomecanvas/gnome-canvas-shape.c
+++ b/libgnomecanvas/gnome-canvas-shape.c
@@ -488,49 +488,6 @@ gnome_canvas_shape_draw (GnomeCanvasItem *item,
 }
 
 static void
-my_cairo_matrix_transform_rectangle (const cairo_matrix_t *matrix,
-                                     double *x1, double *y1, double *x2, double *y2)
-{
-        double maxx, maxy, minx, miny;
-        double tmpx, tmpy;
-
-        tmpx = *x1;
-        tmpy = *y1;
-        cairo_matrix_transform_point (matrix, &tmpx, &tmpy);
-        minx = maxx = tmpx;
-        miny = maxy = tmpy;
-
-        tmpx = *x2;
-        tmpy = *y1;
-        cairo_matrix_transform_point (matrix, &tmpx, &tmpy);
-        minx = MIN (minx, tmpx);
-        maxx = MIN (maxx, tmpx);
-        miny = MIN (miny, tmpy);
-        maxy = MIN (maxy, tmpy);
-
-        tmpx = *x2;
-        tmpy = *y2;
-        cairo_matrix_transform_point (matrix, &tmpx, &tmpy);
-        minx = MIN (minx, tmpx);
-        maxx = MIN (maxx, tmpx);
-        miny = MIN (miny, tmpy);
-        maxy = MIN (maxy, tmpy);
-
-        tmpx = *x1;
-        tmpy = *y2;
-        cairo_matrix_transform_point (matrix, &tmpx, &tmpy);
-        minx = MIN (minx, tmpx);
-        maxx = MIN (maxx, tmpx);
-        miny = MIN (miny, tmpy);
-        maxy = MIN (maxy, tmpy);
-
-        *x1 = minx;
-        *x2 = maxx;
-        *y1 = miny;
-        *y2 = maxy;
-}
-
-static void
 gnome_canvas_shape_bounds (GnomeCanvasItem *item, gdouble *x1, gdouble *y1, gdouble *x2, gdouble *y2)
 {
 	GnomeCanvasShape * shape;
@@ -573,7 +530,7 @@ gnome_canvas_shape_update (GnomeCanvasItem *item, gdouble *affine, ArtSVP *clip_
         gnome_canvas_shape_bounds (item, &x1, &x2, &y1, &y2);
         gnome_canvas_item_i2w_matrix (item, &matrix);
 
-        my_cairo_matrix_transform_rectangle (&matrix, &x1, &y1, &x2, &y2);
+        gnome_canvas_matrix_transform_rect (&matrix, &x1, &y1, &x2, &y2);
         gnome_canvas_update_bbox (GNOME_CANVAS_ITEM (shape),
                                   floor (x1), floor (y1),
                                   ceil (x2), ceil (y2));
diff --git a/libgnomecanvas/gnome-canvas-util.c b/libgnomecanvas/gnome-canvas-util.c
index 1a2e0b2..78834d6 100644
--- a/libgnomecanvas/gnome-canvas-util.c
+++ b/libgnomecanvas/gnome-canvas-util.c
@@ -103,3 +103,58 @@ gnome_canvas_cairo_create_scratch (void)
 
         return cr;
 }
+
+/**
+ * gnome_canvas_matrix_transform_rect:
+ * @matrix: a cairo matrix
+ * @x1: x coordinate of top left position of rectangle (in-out)
+ * @y1: y coordinate of top left position of rectangle (in-out)
+ * @x2: x coordinate of bottom right position of rectangle (in-out)
+ * @y2: y coordinate of bottom right position of rectangle (in-out)
+ *
+ * Computes the smallest rectangle containing the whole area of the given
+ * rectangle after applying the transformation given in @matrix.
+ **/
+void
+gnome_canvas_matrix_transform_rect (const cairo_matrix_t *matrix,
+                                    double *x1, double *y1, double *x2, double *y2)
+{
+        double maxx, maxy, minx, miny;
+        double tmpx, tmpy;
+
+        tmpx = *x1;
+        tmpy = *y1;
+        cairo_matrix_transform_point (matrix, &tmpx, &tmpy);
+        minx = maxx = tmpx;
+        miny = maxy = tmpy;
+
+        tmpx = *x2;
+        tmpy = *y1;
+        cairo_matrix_transform_point (matrix, &tmpx, &tmpy);
+        minx = MIN (minx, tmpx);
+        maxx = MIN (maxx, tmpx);
+        miny = MIN (miny, tmpy);
+        maxy = MIN (maxy, tmpy);
+
+        tmpx = *x2;
+        tmpy = *y2;
+        cairo_matrix_transform_point (matrix, &tmpx, &tmpy);
+        minx = MIN (minx, tmpx);
+        maxx = MIN (maxx, tmpx);
+        miny = MIN (miny, tmpy);
+        maxy = MIN (maxy, tmpy);
+
+        tmpx = *x1;
+        tmpy = *y2;
+        cairo_matrix_transform_point (matrix, &tmpx, &tmpy);
+        minx = MIN (minx, tmpx);
+        maxx = MIN (maxx, tmpx);
+        miny = MIN (miny, tmpy);
+        maxy = MIN (maxy, tmpy);
+
+        *x1 = minx;
+        *x2 = maxx;
+        *y1 = miny;
+        *y2 = maxy;
+}
+
diff --git a/libgnomecanvas/gnome-canvas-util.h b/libgnomecanvas/gnome-canvas-util.h
index bc7dee9..52e245e 100644
--- a/libgnomecanvas/gnome-canvas-util.h
+++ b/libgnomecanvas/gnome-canvas-util.h
@@ -49,6 +49,8 @@ void gnome_canvas_update_bbox (GnomeCanvasItem *item, gint x1, gint y1, gint x2,
 /* Create a scratch cairo_t for measuring purposes */
 cairo_t *gnome_canvas_cairo_create_scratch (void);
 
+void gnome_canvas_matrix_transform_rect (const cairo_matrix_t *matrix, double *x1, double *y1, double *x2, double *y2);
+
 G_END_DECLS
 
 #endif



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]