[opengtl-commits] [360] add united function

[ Thread Index | Date Index | More lists.tuxfamily.org/opengtl-commits Archives ]


Revision: 360
Author:   cyrille
Date:     2008-09-03 23:04:52 +0200 (Wed, 03 Sep 2008)

Log Message:
-----------
add united function

Modified Paths:
--------------
    trunk/OpenGTL/OpenGTL/GTLCore/Region.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/Region.h


Modified: trunk/OpenGTL/OpenGTL/GTLCore/Region.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Region.cpp	2008-09-03 21:04:17 UTC (rev 359)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Region.cpp	2008-09-03 21:04:52 UTC (rev 360)
@@ -19,6 +19,8 @@
 
 #include "Region.h"
 
+#include "Utils_p.h"
+
 using namespace GTLCore;
 
 Region::Region() : m_x(0), m_y(0), m_width(0), m_height(0)
@@ -87,3 +89,18 @@
 {
   return x() != _region.x() or y() != _region.y() or width() != _region.width() or height() != _region.height();
 }
+
+GTLCore::Region& Region::operator+=( const Region& _region )
+{
+  return (*this = this->united( _region ) );
+}
+
+GTLCore::Region Region::united( const Region& _region ) const
+{
+  int right = max( _region.right(), this->right() );
+  int bottom = max( _region.bottom(), this->bottom() );
+  int left = min( _region.left(), this->left() );
+  int top = min( _region.top(), this->top() );
+  
+  return GTLCore::Region(  left, top, right - left, bottom - top );
+}

Modified: trunk/OpenGTL/OpenGTL/GTLCore/Region.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Region.h	2008-09-03 21:04:17 UTC (rev 359)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Region.h	2008-09-03 21:04:52 UTC (rev 360)
@@ -41,6 +41,8 @@
       int top() const;
       void setWidth( int _width );
       void setHeight( int _height );
+      GTLCore::Region united( const Region& _region ) const;
+      GTLCore::Region& operator+=( const Region& _region );
       bool operator!=( const Region& _region ) const;
     private:
       int m_x, m_y, m_width, m_height;


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/