1 #include <lib/gdi/erect.h>
3 /*****************************************************************************
5 *****************************************************************************/
7 eRect::eRect( const ePoint &topLeft, const ePoint &bottomRight )
15 eRect eRect::normalize() const
18 if ( x2 < x1 ) { // swap bad x values
25 if ( y2 < y1 ) { // swap bad y values
35 void eRect::rect( int *x, int *y, int *w, int *h ) const
43 void eRect::coords( int *xp1, int *yp1, int *xp2, int *yp2 ) const
51 void eRect::moveTopLeft( const ePoint &p )
59 void eRect::moveBottomRight( const ePoint &p )
67 void eRect::moveTopRight( const ePoint &p )
75 void eRect::moveBottomLeft( const ePoint &p )
83 void eRect::moveCenter( const ePoint &p )
93 void eRect::setRect( int x, int y, int w, int h )
101 void eRect::setCoords( int xp1, int yp1, int xp2, int yp2 )
109 void eRect::setWidth( int w )
114 void eRect::setHeight( int h )
119 void eRect::setSize( const eSize &s )
125 bool eRect::contains( const ePoint &p) const
127 return p.x() >= x1 && p.x() < x2 &&
128 p.y() >= y1 && p.y() < y2;
131 bool eRect::contains( const eRect &r) const
139 eRect& eRect::operator|=(const eRect &r)
145 eRect& eRect::operator&=(const eRect &r)
151 eRect eRect::operator|(const eRect &r) const
156 tmp.setLeft( MIN( x1, r.x1 ) );
157 tmp.setRight( MAX( x2, r.x2 ) );
158 tmp.setTop( MIN( y1, r.y1 ) );
159 tmp.setBottom( MAX( y2, r.y2 ) );
169 eRect eRect::unite( const eRect &r ) const
174 eRect eRect::operator&( const eRect &r ) const
177 tmp.x1 = MAX( x1, r.x1 );
178 tmp.x2 = MIN( x2, r.x2 );
179 tmp.y1 = MAX( y1, r.y1 );
180 tmp.y2 = MIN( y2, r.y2 );
184 eRect eRect::intersect( const eRect &r ) const
189 bool eRect::intersects( const eRect &r ) const
191 return ( MAX( x1, r.x1 ) < MIN( x2, r.x2 ) &&
192 MAX( y1, r.y1 ) < MIN( y2, r.y2 ) );
195 bool operator==( const eRect &r1, const eRect &r2 )
197 return r1.x1==r2.x1 && r1.x2==r2.x2 && r1.y1==r2.y1 && r1.y2==r2.y2;
200 bool operator!=( const eRect &r1, const eRect &r2 )
202 return r1.x1!=r2.x1 || r1.x2!=r2.x2 || r1.y1!=r2.y1 || r1.y2!=r2.y2;