Module: Mesa
Branch: main
Commit: 935184ca44f80897966d94673379c9416d810ad2
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=935184ca44f80897966d94673379c9416d810ad2

Author: Mike Blumenkrantz <[email protected]>
Date:   Fri Feb 17 17:04:28 2023 -0500

util/box: add intersection test functions for 1d/3d

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21397>

---

 src/gallium/auxiliary/util/u_box.h | 40 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/src/gallium/auxiliary/util/u_box.h 
b/src/gallium/auxiliary/util/u_box.h
index c39e139646a..cb547dc0781 100644
--- a/src/gallium/auxiliary/util/u_box.h
+++ b/src/gallium/auxiliary/util/u_box.h
@@ -194,6 +194,21 @@ u_box_union_3d(struct pipe_box *dst,
    dst->z = z;
 }
 
+static inline boolean
+u_box_test_intersection_1d(const struct pipe_box *a,
+                           const struct pipe_box *b)
+{
+   int ax[2], bx[2];
+
+   ax[0] = MIN2(a->x, a->x + a->width);
+   ax[1] = MAX2(a->x, a->x + a->width);
+
+   bx[0] = MIN2(b->x, b->x + b->width);
+   bx[1] = MAX2(b->x, b->x + b->width);
+
+   return ax[1] >= bx[0] && bx[1] >= ax[0];
+}
+
 static inline boolean
 u_box_test_intersection_2d(const struct pipe_box *a,
                            const struct pipe_box *b)
@@ -218,6 +233,31 @@ u_box_test_intersection_2d(const struct pipe_box *a,
    return TRUE;
 }
 
+static inline boolean
+u_box_test_intersection_3d(const struct pipe_box *a,
+                           const struct pipe_box *b)
+{
+   int ax[2], ay[2], ad[2], bx[2], by[2], bd[2];
+
+   ax[0] = MIN2(a->x, a->x + a->width);
+   ax[1] = MAX2(a->x, a->x + a->width);
+   ay[0] = MIN2(a->y, a->y + a->height);
+   ay[1] = MAX2(a->y, a->y + a->height);
+   ad[0] = MIN2(a->z, a->z + a->depth);
+   ad[1] = MAX2(a->z, a->z + a->depth);
+
+   bx[0] = MIN2(b->x, b->x + b->width);
+   bx[1] = MAX2(b->x, b->x + b->width);
+   by[0] = MIN2(b->y, b->y + b->height);
+   by[1] = MAX2(b->y, b->y + b->height);
+   bd[0] = MIN2(b->z, b->z + b->depth);
+   bd[1] = MAX2(b->z, b->z + b->depth);
+
+   return ax[1] >= bx[0] && bx[1] >= ax[0] &&
+          ay[1] >= by[0] && by[1] >= ay[0] &&
+          ad[1] >= bd[0] && bd[1] >= ad[0];
+}
+
 static inline void
 u_box_minify_2d(struct pipe_box *dst,
                 const struct pipe_box *src, unsigned l)

Reply via email to