[PATCH 2/5] rectangle: Implement _cairo_rectangle_contains_rectangle()

Andrea Canciani <[email protected]>
Newsgroups gmane.comp.lib.cairo
Message-ID <[email protected]>
And reuse it.
---
 src/cairo-clip-boxes.c       |    7 +------
 src/cairo-image-source.c     |   10 ++--------
 src/cairo-pattern.c          |   26 ++++++--------------------
 src/cairo-spans-compositor.c |   10 +---------
 src/cairo-surface.c          |    5 +----
 src/cairo-traps-compositor.c |   10 +---------
 src/cairoint.h               |   10 ++++++++++
 7 files changed, 22 insertions(+), 56 deletions(-)

diff --git a/src/cairo-clip-boxes.c b/src/cairo-clip-boxes.c
index f42b53d..be4497c 100644
--- a/src/cairo-clip-boxes.c
+++ b/src/cairo-clip-boxes.c
@@ -82,13 +82,8 @@ _cairo_clip_contains_rectangle_box (const cairo_clip_t *clip,
     if (clip->path)
 	return FALSE;
 
-    if (clip->extents.x > rect->x ||
-	clip->extents.y > rect->y ||
-	clip->extents.x + clip->extents.width  < rect->x + rect->width ||
-	clip->extents.y + clip->extents.height < rect->y + rect->height)
-    {
+    if (! _cairo_rectangle_contains_rectangle (&clip->extents, rect))
 	return FALSE;
-    }
 
     /* Check for a clip-box that wholly contains the rectangle */
     for (i = 0; i < clip->num_boxes; i++) {
diff --git a/src/cairo-image-source.c b/src/cairo-image-source.c
index 26f245a..047a049 100644
--- a/src/cairo-image-source.c
+++ b/src/cairo-image-source.c
@@ -621,18 +621,12 @@ _pixman_image_for_recording (cairo_image_surface_t *dst,
 
     extend = pattern->base.extend;
     if (_cairo_surface_get_extents (source, &limit)) {
-	if (sample->x >= limit.x &&
-	    sample->y >= limit.y &&
-	    sample->x + sample->width  <= limit.x + limit.width &&
-	    sample->y + sample->height <= limit.y + limit.height)
+	if (_cairo_rectangle_contains_rectangle (&limit, sample))
 	{
 	    extend = CAIRO_EXTEND_NONE;
 	}
 	else if (extend == CAIRO_EXTEND_NONE &&
-		 (sample->x + sample->width <= limit.x ||
-		  sample->x >= limit.x + limit.width ||
-		  sample->y + sample->height <= limit.y ||
-		  sample->y >= limit.y + limit.height))
+		 ! _cairo_rectangle_intersects (&limit, sample))
 	{
 	    return _pixman_transparent_image ();
 	}
diff --git a/src/cairo-pattern.c b/src/cairo-pattern.c
index 41d7384..ea47b6a 100644
--- a/src/cairo-pattern.c
+++ b/src/cairo-pattern.c
@@ -3143,17 +3143,10 @@ _surface_is_opaque (const cairo_surface_pattern_t *pattern,
     if (! _cairo_surface_get_extents (pattern->surface, &extents))
 	return TRUE;
 
-    if (sample != NULL) {
-	if (sample->x >= extents.x &&
-	    sample->y >= extents.y &&
-	    sample->x + sample->width  <= extents.x + extents.width &&
-	    sample->y + sample->height <= extents.y + extents.height)
-	{
-	    return TRUE;
-	}
-    }
+    if (sample == NULL)
+	return FALSE;
 
-    return FALSE;
+    return _cairo_rectangle_contains_rectangle (&extents, sample);
 }
 
 static cairo_bool_t
@@ -3166,17 +3159,10 @@ _raster_source_is_opaque (const cairo_raster_source_pattern_t *pattern,
     if (pattern->base.extend != CAIRO_EXTEND_NONE)
 	return TRUE;
 
-    if (sample != NULL) {
-	if (sample->x >= pattern->extents.x &&
-	    sample->y >= pattern->extents.y &&
-	    sample->x + sample->width  <= pattern->extents.x + pattern->extents.width &&
-	    sample->y + sample->height <= pattern->extents.y + pattern->extents.height)
-	{
-	    return TRUE;
-	}
-    }
+    if (sample == NULL)
+	return FALSE;
 
-    return FALSE;
+    return _cairo_rectangle_contains_rectangle (&pattern->extents, sample);
 }
 
 static cairo_bool_t
diff --git a/src/cairo-spans-compositor.c b/src/cairo-spans-compositor.c
index 468f338..0e94be8 100644
--- a/src/cairo-spans-compositor.c
+++ b/src/cairo-spans-compositor.c
@@ -421,15 +421,7 @@ recording_pattern_contains_sample (const cairo_pattern_t *pattern,
     if (surface->unbounded)
 	return TRUE;
 
-    if (sample->x >= surface->extents.x &&
-	sample->y >= surface->extents.y &&
-	sample->x + sample->width <= surface->extents.x + surface->extents.width &&
-	sample->y + sample->height <= surface->extents.y + surface->extents.height)
-    {
-	return TRUE;
-    }
-
-    return FALSE;
+    return _cairo_rectangle_contains_rectangle (&surface->extents, sample);
 }
 
 static cairo_bool_t
diff --git a/src/cairo-surface.c b/src/cairo-surface.c
index 88f306a..2607f29 100644
--- a/src/cairo-surface.c
+++ b/src/cairo-surface.c
@@ -631,10 +631,7 @@ cairo_surface_map_to_image (cairo_surface_t  *surface,
 	/* If this surface is bounded, we can't map parts
 	 * that are outside of it. */
 	if (likely (surface->backend->get_extents (surface, &surface_extents))) {
-	    if (unlikely (extents->x < surface_extents.x ||
-			  extents->y < surface_extents.y ||
-			  extents->x + extents->width > surface_extents.x + surface_extents.width ||
-			  extents->y + extents->height > surface_extents.y + surface_extents.height))
+	    if (unlikely (! _cairo_rectangle_contains_rectangle (&surface_extents, extents)))
 		return _cairo_surface_create_in_error (CAIRO_STATUS_INVALID_SIZE);
 	}
     }
diff --git a/src/cairo-traps-compositor.c b/src/cairo-traps-compositor.c
index 0371c80..ac0a56f 100644
--- a/src/cairo-traps-compositor.c
+++ b/src/cairo-traps-compositor.c
@@ -959,15 +959,7 @@ recording_pattern_contains_sample (const cairo_pattern_t *pattern,
     if (surface->unbounded)
 	return TRUE;
 
-    if (sample->x >= surface->extents.x &&
-	sample->y >= surface->extents.y &&
-	sample->x + sample->width <= surface->extents.x + surface->extents.width &&
-	sample->y + sample->height <= surface->extents.y + surface->extents.height)
-    {
-	return TRUE;
-    }
-
-    return FALSE;
+    return _cairo_rectangle_contains_rectangle (&surface->extents, sample);
 }
 
 static cairo_bool_t
diff --git a/src/cairoint.h b/src/cairoint.h
index 8f4c370..f08462c 100644
--- a/src/cairoint.h
+++ b/src/cairoint.h
@@ -310,6 +310,16 @@ _cairo_rectangle_intersects (const cairo_rectangle_int_t *dst,
 	     src->y + (int) src->height <= dst->y);
 }
 
+static inline cairo_bool_t
+_cairo_rectangle_contains_rectangle (const cairo_rectangle_int_t *a,
+				     const cairo_rectangle_int_t *b)
+{
+    return (a->x <= b->x &&
+	    a->x + (int) a->width >= b->x + (int) b->width &&
+	    a->y <= b->y &&
+	    a->y + (int) a->height >= b->y + (int) b->height);
+}
+
 cairo_private void
 _cairo_rectangle_int_from_double (cairo_rectangle_int_t *recti,
 				  const cairo_rectangle_t *rectf);
-- 
1.7.5.4

--
cairo mailing list
[email protected]
http://lists.cairographics.org/mailman/listinfo/cairo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.