00001 #ifndef __CRect__
00002 #define __CRect__
00003
00004 #include "CPoint.hpp"
00005 #include "CDimension.hpp"
00006 #include "../Basics/CString.hpp"
00007 using Exponent::Basics::CString;
00008 using Exponent::MathTools::CDimension;
00009 using Exponent::MathTools::CPoint;
00010
00011
00012
00013 namespace Exponent
00014 {
00015 namespace MathTools
00016 {
00042 class CRect : public CCountedObject
00043 {
00045 EXPONENT_CLASS_DECLARATION;
00048
00049
00050 public:
00051
00052
00053
00061 CRect(const long left = 0, const long top = 0, const long width = 0, const long height = 0);
00062
00067 CRect(const CRect &rect);
00068
00074 CRect(const CPoint &origin, const CDimension &dimension);
00075
00079 virtual ~CRect();
00080
00081
00082
00088 virtual CRect &operator = (const CRect &rect);
00089
00095 virtual bool operator == (const CRect &rect);
00096
00097
00098
00106 void setRect(const long left, const long top, const long width, const long height);
00107
00113 void setRect(const CPoint &origin, const CDimension &dimension);
00114
00119 void setLeft(const long left);
00120
00121
00122
00123
00124
00125 void setWidth(const long width);
00126
00131 void setTop(const long top);
00132
00137 void setHeight(const long height);
00138
00143 void setOrigin(const CPoint &point);
00144
00149 void setDimensions(const CDimension &dimension);
00150
00151
00152
00157 long getLeft() const { return m_left; }
00158
00163 long getRight() const { return m_right; }
00164
00169 long getTop() const { return m_top; }
00170
00175 long getBottom() const { return m_bottom; }
00176
00181 long getWidth() const { return m_width; }
00182
00187 long getHeight() const { return m_height; }
00188
00193 CPoint getOrigin() const { return CPoint(m_left, m_top); }
00194
00199 CDimension getDimension() const { return CDimension(m_width, m_height); }
00200
00205 long getCentralXPosition() const;
00206
00211 long getCentralYPosition() const;
00212
00213
00214
00215 #ifdef WIN32
00216
00220 RECT getAsRect();
00221
00226 void setFromRect(RECT &rect);
00227 #else
00228
00232 Rect *getAsRect() const;
00233
00238 void setFromRect(Rect &rect);
00239 #endif
00240
00246 FORCEINLINE bool pointIsInside(const CPoint &point) const
00247 {
00248 return ((point.getXPosition() >= m_left) &&
00249 (point.getXPosition() <= m_right) &&
00250 (point.getYPosition() >= m_top) &&
00251 (point.getYPosition() <= m_bottom));
00252 }
00253
00259 FORCEINLINE bool rectIsInside(const CRect &rect) const
00260 {
00261 return ((rect.getLeft() >= m_left) &&
00262 (rect.getTop() >= m_top) &&
00263 (rect.getRight() <= m_right) &&
00264 (rect.getBottom() <= m_bottom));
00265 }
00266
00272 FORCEINLINE bool rectanglesIntersect(const CRect& other) const
00273 {
00274 return !((m_left > other.getRight()) ||
00275 (m_top > other.getBottom()) ||
00276 (other.getLeft() > m_right) ||
00277 (other.getTop() > m_bottom));
00278 }
00279
00284 FORCEINLINE bool isRectangleEmpty() const
00285 {
00286 return (m_left == 0 && m_top == 0 && m_width == 0 && m_height == 0);
00287 }
00288
00293 void offset(const CPoint &point);
00294
00299 void inset(const long amount);
00300
00305 void scale(const double amount);
00306
00313 static CRect *getIntersectionArea(const CRect &rect1, const CRect &rect2);
00314
00321 static void getIntersectionArea(const CRect &rect1, const CRect &rect2, CRect &output);
00322
00327 void unionWith(const CRect &rect);
00328
00334 virtual void getObjectDescription(char *string, const long size) const;
00335
00341 static CRect convertFromString(const CString &string);
00342
00343
00344
00345 protected:
00346
00347
00348
00349 long m_width;
00350 long m_height;
00352 long m_left;
00353 long m_right;
00354 long m_top;
00355 long m_bottom;
00356 };
00357 }
00358 }
00359 #endif // End of CRect.hpp