[gimp] Add gimp_rectangle_union()



commit c6bd3e0570ae8bf5233198392def3f67c9ef55c8
Author: Michael Natterer <mitch gimp org>
Date:   Sun Aug 23 22:58:36 2009 +0200

    Add gimp_rectangle_union()

 libgimpbase/gimpbase.def    |    1 +
 libgimpbase/gimprectangle.c |   49 ++++++++++++++++++++++++++++++++++++++++++-
 libgimpbase/gimprectangle.h |   13 +++++++++++
 3 files changed, 62 insertions(+), 1 deletions(-)
---
diff --git a/libgimpbase/gimpbase.def b/libgimpbase/gimpbase.def
index 468c409..2a1990a 100644
--- a/libgimpbase/gimpbase.def
+++ b/libgimpbase/gimpbase.def
@@ -86,6 +86,7 @@ EXPORTS
 	gimp_plug_in_directory
 	gimp_progress_command_get_type
 	gimp_rectangle_intersect
+	gimp_rectangle_union
 	gimp_repeat_mode_get_type
 	gimp_run_mode_get_type
 	gimp_signal_private
diff --git a/libgimpbase/gimprectangle.c b/libgimpbase/gimprectangle.c
index 73012cc..df44d64 100644
--- a/libgimpbase/gimprectangle.c
+++ b/libgimpbase/gimprectangle.c
@@ -45,7 +45,7 @@
  * Return value: %TRUE if the intersection is non-empty, %FALSE otherwise
  *
  * Since: GIMP 2.4
- */
+ **/
 gboolean
 gimp_rectangle_intersect (gint  x1,
                           gint  y1,
@@ -75,3 +75,50 @@ gimp_rectangle_intersect (gint  x1,
 
   return (d_w > 0 && d_h > 0);
 }
+
+/**
+ * gimp_rectangle_union:
+ * @x1:          origin of first rectangle
+ * @y1:          origin of first rectangle
+ * @width1:      width of first rectangle
+ * @height1:     height of first rectangle
+ * @x2:          origin of second rectangle
+ * @y2:          origin of second rectangle
+ * @width2:      width of second rectangle
+ * @height2:     height of second rectangle
+ * @dest_x:      return location for origin of union (may be %NULL)
+ * @dest_y:      return location for origin of union (may be %NULL)
+ * @dest_width:  return location for width of union (may be %NULL)
+ * @dest_height: return location for height of union (may be %NULL)
+ *
+ * Calculates the union of two rectangles.
+ *
+ * Since: GIMP 2.8
+ **/
+void
+gimp_rectangle_union (gint  x1,
+                      gint  y1,
+                      gint  width1,
+                      gint  height1,
+                      gint  x2,
+                      gint  y2,
+                      gint  width2,
+                      gint  height2,
+                      gint *dest_x,
+                      gint *dest_y,
+                      gint *dest_width,
+                      gint *dest_height)
+{
+  gint d_x, d_y;
+  gint d_w, d_h;
+
+  d_x = MIN (x1, x2);
+  d_y = MIN (y1, y2);
+  d_w = MAX (x1 + width1,  x2 + width2)  - d_x;
+  d_h = MAX (y1 + height1, y2 + height2) - d_y;
+
+  if (dest_x)      *dest_x      = d_x;
+  if (dest_y)      *dest_y      = d_y;
+  if (dest_width)  *dest_width  = d_w;
+  if (dest_height) *dest_height = d_h;
+}
diff --git a/libgimpbase/gimprectangle.h b/libgimpbase/gimprectangle.h
index c2ba7ba..715f9a2 100644
--- a/libgimpbase/gimprectangle.h
+++ b/libgimpbase/gimprectangle.h
@@ -37,6 +37,19 @@ gboolean  gimp_rectangle_intersect (gint  x1,
                                     gint *dest_width,
                                     gint *dest_height);
 
+void      gimp_rectangle_union     (gint  x1,
+                                    gint  y1,
+                                    gint  width1,
+                                    gint  height1,
+                                    gint  x2,
+                                    gint  y2,
+                                    gint  width2,
+                                    gint  height2,
+                                    gint *dest_x,
+                                    gint *dest_y,
+                                    gint *dest_width,
+                                    gint *dest_height);
+
 
 G_END_DECLS
 



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