summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrea Canciani <ranma42@gmail.com>2010-10-12 22:35:36 +0200
committerAndrea Canciani <ranma42@gmail.com>2010-10-12 23:18:13 +0200
commitd21b4f31665d409e1bfa6eae82b3c10dd77c4b28 (patch)
treec41a6df3fccdcdb4d30dd31cd0e63ee68a5def80 /src
parent2b3d9b3a3aedc37481639dff923c97b8ff956c80 (diff)
Add _cairo_rectangle_union
Implement _cairo_rectangle_union(), a function to compute a rectangle containing two input rectangles.
Diffstat (limited to 'src')
-rw-r--r--src/cairo-rectangle.c23
-rw-r--r--src/cairoint.h7
2 files changed, 30 insertions, 0 deletions
diff --git a/src/cairo-rectangle.c b/src/cairo-rectangle.c
index cc271804..185c75c0 100644
--- a/src/cairo-rectangle.c
+++ b/src/cairo-rectangle.c
@@ -149,6 +149,29 @@ _cairo_rectangle_intersect (cairo_rectangle_int_t *dst,
}
}
+/* Extends the dst rectangle to also contain src.
+ * If one of the rectangles is empty, the result is undefined
+ */
+void
+_cairo_rectangle_union (cairo_rectangle_int_t *dst,
+ const cairo_rectangle_int_t *src)
+{
+ int x1, y1, x2, y2;
+
+ x1 = MIN (dst->x, src->x);
+ y1 = MIN (dst->y, src->y);
+ /* Beware the unsigned promotion, fortunately we have bits to spare
+ * as (CAIRO_RECT_INT_MAX - CAIRO_RECT_INT_MIN) < UINT_MAX
+ */
+ x2 = MAX (dst->x + (int) dst->width, src->x + (int) src->width);
+ y2 = MAX (dst->y + (int) dst->height, src->y + (int) src->height);
+
+ dst->x = x1;
+ dst->y = y1;
+ dst->width = x2 - x1;
+ dst->height = y2 - y1;
+}
+
#define P1x (line->p1.x)
#define P1y (line->p1.y)
#define P2x (line->p2.x)
diff --git a/src/cairoint.h b/src/cairoint.h
index 2bb88d37..e3582ec3 100644
--- a/src/cairoint.h
+++ b/src/cairoint.h
@@ -280,6 +280,13 @@ cairo_private cairo_bool_t
_cairo_rectangle_intersect (cairo_rectangle_int_t *dst,
const cairo_rectangle_int_t *src);
+/* Extends the dst rectangle to also contain src.
+ * If one of the rectangles is empty, the result is undefined
+ */
+cairo_private void
+_cairo_rectangle_union (cairo_rectangle_int_t *dst,
+ const cairo_rectangle_int_t *src);
+
cairo_private cairo_bool_t
_cairo_box_intersects_line_segment (cairo_box_t *box,
cairo_line_t *line) cairo_pure;