[gtkmm] Gdk::Rectangle: Add Gdk::join() and Gdk::intersect() nonmember functions.



commit 4d59c399288aa1faec45fd73c8a0901ceed4ba9b
Author: Kjell Ahlstedt <kjell ahlstedt bredband net>
Date:   Sat Feb 9 10:03:05 2013 +0100

    Gdk::Rectangle: Add Gdk::join() and Gdk::intersect() nonmember functions.
    
    * gdk/src/rectangle.[hg|ccg]: Add Gdk::Rectangle::intersects(),
    Gdk::join() and Gdk::intersect(). Bug #452130.

 ChangeLog             |    9 ++++-
 gdk/src/rectangle.ccg |   28 +++++++++++++++
 gdk/src/rectangle.hg  |   89 +++++++++++++++++++++++++++++++++++++++----------
 3 files changed, 107 insertions(+), 19 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index b8331ee..9634979 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,7 +1,14 @@
+2013-02-09  Kjell Ahlstedt  <kjell ahlstedt bredband net>
+
+	Gdk::Rectangle: Add Gdk::join() and Gdk::intersect() nonmember functions.
+
+	* gdk/src/rectangle.[hg|ccg]: Add Gdk::Rectangle::intersects(),
+	Gdk::join() and Gdk::intersect(). Bug #452130.
+
 2013-01-31  Murray Cumming  <murrayc murrayc com>
 
 	Documentation: Small correction to TreeModel::set_value_impl().
-	
+
 	* gtk/src/treemodel.hg: set_value_impl(): Do not suggest calling
 	set_value_vfunc() because there is no such function. Maybe there
 	was once.
diff --git a/gdk/src/rectangle.ccg b/gdk/src/rectangle.ccg
index f31dd3a..599e80c 100644
--- a/gdk/src/rectangle.ccg
+++ b/gdk/src/rectangle.ccg
@@ -52,10 +52,38 @@ Rectangle& Rectangle::intersect(const Rectangle& src2, bool& rectangles_intersec
   return *this;
 }
 
+bool Rectangle::intersects(const Rectangle& src2) const
+{
+  return gdk_rectangle_intersect(&gobject_, &src2.gobject_, 0);
+}
+
 bool Rectangle::has_zero_area() const
 {
   return (gobject_.width == 0 || gobject_.height == 0);
 }
 
+// Freestanding functions (not Rectangle members)
+
+Rectangle join(const Rectangle& src1, const Rectangle& src2)
+{
+  Rectangle dest;
+  gdk_rectangle_union(src1.gobj(), src2.gobj(), dest.gobj());
+  return dest;
+}
+
+Rectangle intersect(const Rectangle& src1, const Rectangle& src2)
+{
+  Rectangle dest;
+  gdk_rectangle_intersect(src1.gobj(), src2.gobj(), dest.gobj());
+  return dest;
+}
+
+Rectangle intersect(const Rectangle& src1, const Rectangle& src2, bool& rectangles_intersect)
+{
+  Rectangle dest;
+  rectangles_intersect = gdk_rectangle_intersect(src1.gobj(), src2.gobj(), dest.gobj());
+  return dest;
+}
+
 } // namespace Gdk
 
diff --git a/gdk/src/rectangle.hg b/gdk/src/rectangle.hg
index cf909c4..24b87c6 100644
--- a/gdk/src/rectangle.hg
+++ b/gdk/src/rectangle.hg
@@ -25,55 +25,67 @@ namespace Gdk
 {
 
 /** Gdk::Rectangle is a structure holding the position and size of a rectangle.
- * The intersection of two rectangles can be computed with intersect(). To find the union of two rectangles use union().
+ * The intersection of two rectangles can be computed with intersect().
+ * To find the union of two rectangles use join().
  */
 class Rectangle
 {
   _CLASS_BOXEDTYPE_STATIC(Rectangle, GdkRectangle)
 public:
-//_CUSTOM_DEFAULT_CTOR
-//Rectangle();
 
   /** Creates a new rectangle instance with these dimensions.
    */
   Rectangle(int x, int y, int width, int height);
 
-  /** Calculates the union of two rectangles. 
-   * The union of this rectangle and @a src2 is the smallest rectangle which includes both this rectangle and @a src2 within it. 
+  // 'union' is a C and C++ keyword. Can't be a method name.
+  /** Calculates the union of two rectangles, changing this rectangle.
+   * The union of this rectangle and @a src2 is the smallest rectangle which
+   * includes both this rectangle and @a src2 within it.
    *
-   * This method returns a reference to this instance, allowing you to then call another method easily. 
+   * This method returns a reference to this instance, allowing you to then call another method easily.
    * For instance: rect.join(src2).intersect(src3);
    *
    * @param src2 The rectangle with which to calculate the union with this rectangle.
    * @returns A reference to this rectangle.
    */
   Rectangle& join(const Rectangle& src2);
-  
-  /** Calculates the intersection of two rectangles, changing this rectangle. 
-   * If the rectangles do not intersect, this rectangle's width and height is set to 0 and its x and y values are undefined.
+
+  /** Calculates the intersection of two rectangles, changing this rectangle.
+   * If the rectangles do not intersect, this rectangle's width and height are
+   * set to 0 and its x and y values are undefined.
    *
-   * This method returns a reference to this instance, allowing you to then call another method easily. 
+   * This method returns a reference to this instance, allowing you to then call another method easily.
    * For instance: rect.intersect(src2).join(src3);
    *
    * @param src2 The rectangle with which to calculate the intersection with this rectangle.
    * @returns A reference to this rectangle.
    */
   Rectangle& intersect(const Rectangle& src2);
-  
-  /** Calculates the intersection of two rectangles, changing this rectangle. 
-   * If the rectangles do not intersect, this rectangle's width and height is set to 0 and its x and y values are undefined.
+
+  /** Calculates the intersection of two rectangles, changing this rectangle.
+   * If the rectangles do not intersect, this rectangle's width and height are
+   * set to 0 and its x and y values are undefined.
    *
-   * This method returns a reference to this instance, allowing you to then call another method easily. 
-   * For instance: rect.intersect(src2).join(src3);
+   * This method returns a reference to this instance, allowing you to then call another method easily.
+   * For instance: rect.intersect(src2, rectangles_intersect).join(src3);
    *
    * @param src2 The rectangle with which to calculate the intersection with this rectangle.
-   * @param rectangles_intersect This will be set to true if the rectangles intersect.
+   * @param[out] rectangles_intersect This will be set to <tt>true</tt>
+   *             if the rectangles intersect, else <tt>false</tt>.
    * @returns A reference to this rectangle.
    */
   Rectangle& intersect(const Rectangle& src2, bool& rectangles_intersect);
 
-  /** Checks whether either the width or height are 0.
-   * @result Whether this rectangle has any non-0 area.
+  /** Checks whether two rectangles intersect.
+   *
+   * @newin{3,8}
+   * @param src2 The rectangle with which to check intersection with this rectangle.
+   * @result Whether this rectangle intersects @a src2.
+   */
+  bool intersects(const Rectangle& src2) const;
+
+  /** Checks whether either the width or height is 0.
+   * @result Whether this rectangle has 0 area.
    */
   bool has_zero_area() const;
 
@@ -87,5 +99,46 @@ public:
   _MEMBER_SET(height, height, int, int)
 };
 
+/** Calculates the union of two rectangles.
+ * The union of @a src1 and @a src2 is the smallest rectangle which
+ * includes both @a src1 and @a src2 within it.
+ *
+ * @newin{3,8}
+ * @param src1 One of the rectangles.
+ * @param src2 The other rectangle.
+ * @returns The union of @a src1 and @a src2.
+ *
+ * @relates Gdk::Rectangle
+ */
+Rectangle join(const Rectangle& src1, const Rectangle& src2);
+
+/** Calculates the intersection of two rectangles.
+ * If the rectangles do not intersect, the returned rectangle's width and height
+ * are set to 0 and its x and y values are undefined.
+ *
+ * @newin{3,8}
+ * @param src1 One of the rectangles.
+ * @param src2 The other rectangle.
+ * @returns The intersection of @a src1 and @a src2.
+ *
+ * @relates Gdk::Rectangle
+ */
+Rectangle intersect(const Rectangle& src1, const Rectangle& src2);
+
+/** Calculates the intersection of two rectangles.
+ * If the rectangles do not intersect, the returned rectangle's width and height
+ * are set to 0 and its x and y values are undefined.
+ *
+ * @newin{3,8}
+ * @param src1 One of the rectangles.
+ * @param src2 The other rectangle.
+ * @param[out] rectangles_intersect This will be set to <tt>true</tt>
+ *             if the rectangles intersect, else <tt>false</tt>.
+ * @returns The intersection of @a src1 and @a src2.
+ *
+ * @relates Gdk::Rectangle
+ */
+Rectangle intersect(const Rectangle& src1, const Rectangle& src2, bool& rectangles_intersect);
+
 } // namespace Gdk
 


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