[gegl] buffer: add gegl_rectangle_subtract()
- From: Ell <ell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl] buffer: add gegl_rectangle_subtract()
- Date: Mon, 29 Jul 2019 20:19:26 +0000 (UTC)
commit 0e9b7f53b405ad38c44883bbb8916cf496f44841
Author: Ell <ell_se yahoo com>
Date: Mon Jul 29 22:21:45 2019 +0300
buffer: add gegl_rectangle_subtract()
... which subtracts a subtrahend rectangle from a minuend
rectangle, returning up to 4 disjoint rectangles.
gegl/buffer/gegl-rectangle.c | 61 ++++++++++++++++++++++++++++++++++++++++++++
gegl/buffer/gegl-rectangle.h | 17 ++++++++++++
2 files changed, 78 insertions(+)
---
diff --git a/gegl/buffer/gegl-rectangle.c b/gegl/buffer/gegl-rectangle.c
index 963e388da..4accbf8df 100644
--- a/gegl/buffer/gegl-rectangle.c
+++ b/gegl/buffer/gegl-rectangle.c
@@ -209,6 +209,67 @@ gegl_rectangle_intersect (GeglRectangle *dest,
return TRUE;
}
+gint
+gegl_rectangle_subtract (GeglRectangle dest[4],
+ const GeglRectangle *minuend,
+ const GeglRectangle *subtrahend)
+{
+ gint mx1, mx2;
+ gint my1, my2;
+
+ gint sx1, sx2;
+ gint sy1, sy2;
+
+ gint n = 0;
+
+ 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 (sx2 <= mx1 || sx1 >= mx2 || sy2 <= my1 || sy1 >= my2)
+ {
+ dest[0] = *minuend;
+
+ return 1;
+ }
+
+ if (sy1 > my1)
+ {
+ gegl_rectangle_set (&dest[n++], mx1, my1, mx2 - mx1, sy1 - my1);
+
+ my1 = sy1;
+ }
+
+ if (sy2 < my2)
+ {
+ gegl_rectangle_set (&dest[n++], mx1, sy2, mx2 - mx1, my2 - sy2);
+
+ my2 = sy2;
+ }
+
+ if (sx1 > mx1)
+ {
+ gegl_rectangle_set (&dest[n++], mx1, my1, sx1 - mx1, my2 - my1);
+
+ mx1 = sx1;
+ }
+
+ if (sx2 < mx2)
+ {
+ gegl_rectangle_set (&dest[n++], sx2, my1, mx2 - sx2, my2 - my1);
+
+ mx2 = sx2;
+ }
+
+ return n;
+}
+
gboolean
gegl_rectangle_subtract_bounding_box (GeglRectangle *dest,
const GeglRectangle *minuend,
diff --git a/gegl/buffer/gegl-rectangle.h b/gegl/buffer/gegl-rectangle.h
index 7e164c1c9..d17cdad22 100644
--- a/gegl/buffer/gegl-rectangle.h
+++ b/gegl/buffer/gegl-rectangle.h
@@ -240,6 +240,23 @@ gboolean gegl_rectangle_intersect (GeglRectangle *dest,
const GeglRectangle *src1,
const GeglRectangle *src2);
+/**
+ * gegl_rectangle_subtract_bounding_box:
+ * @destination: an array of 4 #GeglRectangle elements
+ * @minuend: a #GeglRectangle
+ * @subtrahend: a #GeglRectangle
+ *
+ * Subtracts @subtrahend from @minuend, and stores the resulting rectangles in
+ * @destination. Between 0 and 4 disjoint rectangles may be produced.
+ *
+ * @destination may contain @minuend or @subtrahend.
+ *
+ * Returns the number of resulting rectangles.
+ */
+gint gegl_rectangle_subtract (GeglRectangle destination[4],
+ const GeglRectangle *minuend,
+ const GeglRectangle *subtrahend);
+
/**
* gegl_rectangle_subtract_bounding_box:
* @destination: a #GeglRectangle
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]