[gegl] utils: add gegl_rectangle_subtract_bounding_box()



commit 3ebfb9d8142bb0f5e2cc164c288b6172cb0c58fe
Author: Ell <ell_se yahoo com>
Date:   Mon Dec 25 15:55:43 2017 -0500

    utils: add gegl_rectangle_subtract_bounding_box()
    
    ... which subtracts a subtrahend rectangle from a minuend
    rectangle, and returns the bounding box of the result.

 gegl/gegl-utils.c |   44 ++++++++++++++++++++++++++++++++++++++++++++
 gegl/gegl-utils.h |   18 ++++++++++++++++++
 2 files changed, 62 insertions(+), 0 deletions(-)
---
diff --git a/gegl/gegl-utils.c b/gegl/gegl-utils.c
index 2dcfc27..c9fa8f7 100644
--- a/gegl/gegl-utils.c
+++ b/gegl/gegl-utils.c
@@ -129,6 +129,50 @@ gegl_rectangle_intersect (GeglRectangle       *dest,
   return TRUE;
 }
 
+gboolean
+gegl_rectangle_subtract_bounding_box (GeglRectangle       *dest,
+                                      const GeglRectangle *minuend,
+                                      const GeglRectangle *subtrahend)
+{
+  gint mx1, mx2;
+  gint my1, my2;
+
+  gint sx1, sx2;
+  gint sy1, sy2;
+
+  mx1 = minuend->x;
+  mx2 = minuend->x + minuend->width;
+  my1 = minuend->y;
+  my2 = minuend->y + minuend->height;
+
+  sx1 = subtrahend->x;
+  sx2 = subtrahend->x + subtrahend->width;
+  sy1 = subtrahend->y;
+  sy2 = subtrahend->y + subtrahend->height;
+
+  if (sx1 <= mx1 && sx2 >= mx2)
+    {
+      if (sy1 <= my1) my1 = MAX (my1, sy2);
+      if (sy2 >= my2) my2 = MIN (my2, sy1);
+    }
+  else if (sy1 <= my1 && sy2 >= my2)
+    {
+      if (sx1 <= mx1) mx1 = MAX (mx1, sx2);
+      if (sx2 >= mx2) mx2 = MIN (mx2, sx1);
+    }
+
+  if (mx1 < mx2 && my1 < my2)
+    {
+      gegl_rectangle_set (dest, mx1, my1, mx2 - mx1, my2 - my1);
+      return TRUE;
+    }
+  else
+    {
+      gegl_rectangle_set (dest, 0, 0, 0, 0);
+      return FALSE;
+    }
+}
+
 void
 gegl_rectangle_copy (GeglRectangle       *to,
                      const GeglRectangle *from)
diff --git a/gegl/gegl-utils.h b/gegl/gegl-utils.h
index 9848e33..2561d46 100644
--- a/gegl/gegl-utils.h
+++ b/gegl/gegl-utils.h
@@ -165,6 +165,24 @@ gboolean    gegl_rectangle_intersect     (GeglRectangle       *dest,
                                           const GeglRectangle *src2);
 
 /**
+ * gegl_rectangle_subtract_bounding_box:
+ * @destination: a #GeglRectangle
+ * @minuend: a #GeglRectangle
+ * @subtrahend: a #GeglRectangle
+ *
+ * Computes the bounding box of the area formed by subtracting @subtrahend
+ * from @minuend, and stores the result in in @destination.
+ *
+ * @destination may point to the same object as @minuend or @subtrahend.
+ *
+ * Returns TRUE if the result is not empty.
+ */
+gboolean
+    gegl_rectangle_subtract_bounding_box (GeglRectangle       *destination,
+                                          const GeglRectangle *minuend,
+                                          const GeglRectangle *subtrahend);
+
+/**
  * gegl_rectangle_contains:
  * @parent: a #GeglRectangle
  * @child: a #GeglRectangle


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]