1 #include <lib/base/erect.h>
4 /*****************************************************************************
6 *****************************************************************************/
8 eRect::eRect( const ePoint
&topLeft
, const ePoint
&bottomRight
)
16 eRect
eRect::normalize() const
19 if ( x2
< x1
) { // swap bad x values
26 if ( y2
< y1
) { // swap bad y values
36 void eRect::rect( int *x
, int *y
, int *w
, int *h
) const
44 void eRect::coords( int *xp1
, int *yp1
, int *xp2
, int *yp2
) const
52 void eRect::moveTopLeft( const ePoint
&p
)
60 void eRect::moveBottomRight( const ePoint
&p
)
68 void eRect::moveTopRight( const ePoint
&p
)
76 void eRect::moveBottomLeft( const ePoint
&p
)
84 void eRect::moveCenter( const ePoint
&p
)
94 void eRect::setRect( int x
, int y
, int w
, int h
)
102 void eRect::setCoords( int xp1
, int yp1
, int xp2
, int yp2
)
110 void eRect::setWidth( int w
)
115 void eRect::setHeight( int h
)
120 void eRect::setSize( const eSize
&s
)
126 bool eRect::contains( const ePoint
&p
) const
128 return p
.x() >= x1
&& p
.x() < x2
&&
129 p
.y() >= y1
&& p
.y() < y2
;
132 bool eRect::contains( const eRect
&r
) const
140 eRect
& eRect::operator|=(const eRect
&r
)
146 eRect
& eRect::operator&=(const eRect
&r
)
152 eRect
eRect::operator|(const eRect
&r
) const
157 tmp
.setLeft( MIN( x1
, r
.x1
) );
158 tmp
.setRight( MAX( x2
, r
.x2
) );
159 tmp
.setTop( MIN( y1
, r
.y1
) );
160 tmp
.setBottom( MAX( y2
, r
.y2
) );
170 eRect
eRect::unite( const eRect
&r
) const
175 eRect
eRect::operator&( const eRect
&r
) const
178 tmp
.x1
= MAX( x1
, r
.x1
);
179 tmp
.x2
= MIN( x2
, r
.x2
);
180 tmp
.y1
= MAX( y1
, r
.y1
);
181 tmp
.y2
= MIN( y2
, r
.y2
);
185 eRect
eRect::intersect( const eRect
&r
) const
190 bool eRect::intersects( const eRect
&r
) const
192 return ( MAX( x1
, r
.x1
) < MIN( x2
, r
.x2
) &&
193 MAX( y1
, r
.y1
) < MIN( y2
, r
.y2
) );
196 bool operator==( const eRect
&r1
, const eRect
&r2
)
198 return r1
.x1
==r2
.x1
&& r1
.x2
==r2
.x2
&& r1
.y1
==r2
.y1
&& r1
.y2
==r2
.y2
;
201 bool operator!=( const eRect
&r1
, const eRect
&r2
)
203 return r1
.x1
!=r2
.x1
|| r1
.x2
!=r2
.x2
|| r1
.y1
!=r2
.y1
|| r1
.y2
!=r2
.y2
;