Mesa (master): gallium/util: return FALSE for intersection if there' s empty rectangles

Brian Paul brianp at kemper.freedesktop.org
Tue Sep 1 22:30:57 UTC 2015


Module: Mesa
Branch: master
Commit: fec4f5de67b22a7048266fb7e57f49fe6fc3744a
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=fec4f5de67b22a7048266fb7e57f49fe6fc3744a

Author: Roland Scheidegger <sroland at vmware.com>
Date:   Tue Sep  1 16:29:17 2015 -0600

gallium/util: return FALSE for intersection if there's empty rectangles

It isn't really obvious if intersection test should take into account empty
rectangles or if the caller should do it. But it looks like most callers
actually verified one of the rects but not the other, but since correctly
returning an empty rect that other rect could actually be empty leading to
more bugs. Hence just verify both rects for emptyness in the intersection
test itself which makes the code easier in the caller (though it will be
slower if the caller knows the rectangles are non-empty).

Reviewed-by: Zack Rusin <zackr at vmware.com>

---

 src/gallium/auxiliary/util/u_rect.h |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/gallium/auxiliary/util/u_rect.h b/src/gallium/auxiliary/util/u_rect.h
index b26f671..dea1e1e 100644
--- a/src/gallium/auxiliary/util/u_rect.h
+++ b/src/gallium/auxiliary/util/u_rect.h
@@ -42,6 +42,7 @@ struct u_rect {
 };
 
 /* Do two rectangles intersect?
+ * Note: empty rectangles are valid as inputs (and never intersect).
  */
 static inline boolean
 u_rect_test_intersection(const struct u_rect *a,
@@ -50,7 +51,11 @@ u_rect_test_intersection(const struct u_rect *a,
    return (!(a->x1 < b->x0 ||
              b->x1 < a->x0 ||
              a->y1 < b->y0 ||
-             b->y1 < a->y0));
+             b->y1 < a->y0 ||
+             a->x1 < a->x0 ||
+             a->y1 < a->y0 ||
+             b->x1 < b->x0 ||
+             b->y1 < b->y0));
 }
 
 /* Find the intersection of two rectangles known to intersect.




More information about the mesa-commit mailing list