[Bf-blender-cvs] [3ca9eaf1870] blender-v2.82-release: BLI_rect: add rect-rect intersection checks on a single axis

Campbell Barton noreply at git.blender.org
Mon Jan 27 09:46:26 CET 2020


Commit: 3ca9eaf187051477e8fb0219f014f278cc1178a3
Author: Campbell Barton
Date:   Mon Jan 27 17:47:04 2020 +1100
Branches: blender-v2.82-release
https://developer.blender.org/rB3ca9eaf187051477e8fb0219f014f278cc1178a3

BLI_rect: add rect-rect intersection checks on a single axis

===================================================================

M	source/blender/blenlib/BLI_rect.h
M	source/blender/blenlib/intern/rct.c

===================================================================

diff --git a/source/blender/blenlib/BLI_rect.h b/source/blender/blenlib/BLI_rect.h
index e3cd70f7413..23a8f775576 100644
--- a/source/blender/blenlib/BLI_rect.h
+++ b/source/blender/blenlib/BLI_rect.h
@@ -79,6 +79,10 @@ bool BLI_rctf_compare(const struct rctf *rect_a, const struct rctf *rect_b, cons
 bool BLI_rcti_compare(const struct rcti *rect_a, const struct rcti *rect_b);
 bool BLI_rctf_isect(const struct rctf *src1, const struct rctf *src2, struct rctf *dest);
 bool BLI_rcti_isect(const struct rcti *src1, const struct rcti *src2, struct rcti *dest);
+bool BLI_rctf_isect_rect_x(const struct rctf *src1, const struct rctf *src2, float range_x[2]);
+bool BLI_rctf_isect_rect_y(const struct rctf *src1, const struct rctf *src2, float range_y[2]);
+bool BLI_rcti_isect_rect_x(const struct rcti *src1, const struct rcti *src2, int range_x[2]);
+bool BLI_rcti_isect_rect_y(const struct rcti *src1, const struct rcti *src2, int range_y[2]);
 bool BLI_rcti_isect_x(const rcti *rect, const int x);
 bool BLI_rcti_isect_y(const rcti *rect, const int y);
 bool BLI_rcti_isect_pt(const struct rcti *rect, const int x, const int y);
diff --git a/source/blender/blenlib/intern/rct.c b/source/blender/blenlib/intern/rct.c
index ecff2ebffef..1712738e859 100644
--- a/source/blender/blenlib/intern/rct.c
+++ b/source/blender/blenlib/intern/rct.c
@@ -899,6 +899,90 @@ bool BLI_rcti_isect(const rcti *src1, const rcti *src2, rcti *dest)
   }
 }
 
+bool BLI_rctf_isect_rect_x(const rctf *src1, const rctf *src2, float range_x[2])
+{
+  const float xmin = (src1->xmin) > (src2->xmin) ? (src1->xmin) : (src2->xmin);
+  const float xmax = (src1->xmax) < (src2->xmax) ? (src1->xmax) : (src2->xmax);
+
+  if (xmax >= xmin) {
+    if (range_x) {
+      range_x[0] = xmin;
+      range_x[1] = xmax;
+    }
+    return true;
+  }
+  else {
+    if (range_x) {
+      range_x[0] = 0;
+      range_x[1] = 0;
+    }
+    return false;
+  }
+}
+
+bool BLI_rctf_isect_rect_y(const rctf *src1, const rctf *src2, float range_y[2])
+{
+  const float ymin = (src1->ymin) > (src2->ymin) ? (src1->ymin) : (src2->ymin);
+  const float ymax = (src1->ymax) < (src2->ymax) ? (src1->ymax) : (src2->ymax);
+
+  if (ymax >= ymin) {
+    if (range_y) {
+      range_y[0] = ymin;
+      range_y[1] = ymax;
+    }
+    return true;
+  }
+  else {
+    if (range_y) {
+      range_y[0] = 0;
+      range_y[1] = 0;
+    }
+    return false;
+  }
+}
+
+bool BLI_rcti_isect_rect_x(const rcti *src1, const rcti *src2, int range_x[2])
+{
+  const int xmin = (src1->xmin) > (src2->xmin) ? (src1->xmin) : (src2->xmin);
+  const int xmax = (src1->xmax) < (src2->xmax) ? (src1->xmax) : (src2->xmax);
+
+  if (xmax >= xmin) {
+    if (range_x) {
+      range_x[0] = xmin;
+      range_x[1] = xmax;
+    }
+    return true;
+  }
+  else {
+    if (range_x) {
+      range_x[0] = 0;
+      range_x[1] = 0;
+    }
+    return false;
+  }
+}
+
+bool BLI_rcti_isect_rect_y(const rcti *src1, const rcti *src2, int range_y[2])
+{
+  const int ymin = (src1->ymin) > (src2->ymin) ? (src1->ymin) : (src2->ymin);
+  const int ymax = (src1->ymax) < (src2->ymax) ? (src1->ymax) : (src2->ymax);
+
+  if (ymax >= ymin) {
+    if (range_y) {
+      range_y[0] = ymin;
+      range_y[1] = ymax;
+    }
+    return true;
+  }
+  else {
+    if (range_y) {
+      range_y[0] = 0;
+      range_y[1] = 0;
+    }
+    return false;
+  }
+}
+
 void BLI_rcti_rctf_copy(rcti *dst, const rctf *src)
 {
   dst->xmin = floorf(src->xmin + 0.5f);



More information about the Bf-blender-cvs mailing list