»õ ÆÄÀÏ |
| | |
| | | #pragma once |
| | | |
| | | |
| | | |
| | | template<typename T> |
| | | class CakRectT |
| | | { |
| | | public: |
| | | T left; |
| | | T top; |
| | | T right; |
| | | T bottom; |
| | | |
| | | public: |
| | | CakRectT(void); |
| | | //CakRectT(T l, T t, T r, T b); |
| | | CakRectT(const T l, const T t, const T r, const T b):left(l),top(t),right(r),bottom(b) {}; |
| | | virtual ~CakRectT(void); |
| | | |
| | | |
| | | //Attirbute |
| | | // retrieves the width |
| | | T Width() const throw(); |
| | | // returns the height |
| | | T Height() const throw(); |
| | | |
| | | //{ |
| | | // // reference to the top-left point |
| | | // CPoint& TopLeft() throw(); |
| | | // // reference to the bottom-right point |
| | | // CPoint& BottomRight() throw(); |
| | | // // const reference to the top-left point |
| | | // const CPoint& TopLeft() const throw(); |
| | | // // const reference to the bottom-right point |
| | | // const CPoint& BottomRight() const throw(); |
| | | // // the geometric center point of the rectangle |
| | | // CPoint CenterPoint() const throw(); |
| | | // |
| | | // bool PtInRect(POINT point) const throw(); |
| | | //} |
| | | |
| | | // swap the left and right |
| | | void SwapLeftRight() throw(); |
| | | void SwapTopBottom() throw(); |
| | | |
| | | |
| | | |
| | | // returns TRUE if rectangle has no area |
| | | bool IsRectEmpty() const throw(); |
| | | // returns TRUE if rectangle is at (0,0) and has no area |
| | | bool IsRectNull() const throw(); |
| | | // returns TRUE if point is within rectangle |
| | | |
| | | bool PtInRect(T x, T y) const throw(); |
| | | |
| | | // Operations |
| | | |
| | | // set rectangle from left, top, right, and bottom |
| | | void SetRect(T x1, T y1, T x2, T y2) throw(); |
| | | //void SetRect(POINT topLeft, POINT bottomRight) throw(); |
| | | // empty the rectangle |
| | | void SetRectEmpty() throw(); |
| | | // copy from another rectangle |
| | | void CopyRect(const CakRectT<T>* lpSrcRect) throw(); |
| | | // TRUE if exactly the same as another rectangle |
| | | bool EqualRect(const CakRectT<T>* lpRect) const throw(); |
| | | |
| | | // Inflate rectangle's width and height by |
| | | // x units to the left and right ends of the rectangle |
| | | // and y units to the top and bottom. |
| | | void InflateRect(T x, T y) throw(); |
| | | void InflateRect(T l, T t, T r, T b) throw(); |
| | | void InflateRect(CakRectT<T>* lpRect) throw(); |
| | | |
| | | // deflate the rectangle's width and height without |
| | | // moving its top or left |
| | | void DeflateRect(T x, T y) throw(); |
| | | void DeflateRect(T l, T t, T r, T b) throw(); |
| | | //void DeflateRect(SIZE size) throw(); |
| | | void DeflateRect(CakRectT<T>* lpRect) throw(); |
| | | |
| | | // translate the rectangle by moving its top and left |
| | | void OffsetRect(T x, T y) throw(); |
| | | //void OffsetRect(SIZE size) throw(); |
| | | //void OffsetRect(POINT point) throw(); |
| | | void NormalizeRect() throw(); |
| | | |
| | | // absolute position of rectangle |
| | | void MoveToY(T y) throw(); |
| | | void MoveToX(T x) throw(); |
| | | void MoveToXY(T x, T y) throw(); |
| | | //void MoveToXY(POINT point) throw(); |
| | | |
| | | // ëì¬ê°íì´ ê²¹ì¹ë ë¶ë¶ë§ ê²ì¶ ììì 0ì¼ë¡ ì
í
(Returnì ê²¹ì¹ë ë¶ë¶ì´ ìì¼ë©´ True) |
| | | bool IntersectRect(CakRectT<T>* lpRect1, CakRectT<T>* lpRect2) throw(); |
| | | |
| | | // ë ì¬ê°íì í
ë리 ë¶ë¶ ê²ì¶(Returnì ê²¹ì¹ë ë¶ë¶ì´ ìì¼ë©´ True) |
| | | bool UnionRect(CakRectT<T>* lpRect1, CakRectT<T>* lpRect2) throw(); |
| | | |
| | | // set this rectangle to minimum of two others |
| | | //bool SubtractRect(CakRectT<T>* lpRectSrc1, CakRectT<T>* lpRectSrc2) throw(); |
| | | |
| | | // Additional Operations |
| | | void operator=(const CakRectT<T>& srcRect) throw(); |
| | | bool operator==(const CakRectT<T>& rect) const throw(); |
| | | bool operator!=(const CakRectT<T>& rect) const throw(); |
| | | void operator+=(CakRectT<T>* lpRect) throw(); |
| | | void operator-=(CakRectT<T>* lpRect) throw(); |
| | | //void operator&=(const CakRectT<T>& rect) throw(); |
| | | //void operator|=(const CakRectT<T>& rect) throw(); |
| | | |
| | | // Operators returning CakRectT<T> values |
| | | //CakRectT<T> operator+(POINT point) const throw(); |
| | | //CakRectT<T> operator-(POINT point) const throw(); |
| | | CakRectT<T> operator+(CakRectT<T>* lpRect) const throw(); |
| | | //CakRectT<T> operator+(SIZE size) const throw(); |
| | | //CakRectT<T> operator-(SIZE size) const throw(); |
| | | CakRectT<T> operator-(CakRectT<T>* lpRect) const throw(); |
| | | //CakRectT<T> operator&(const CakRectT<T>& rect2) const throw(); |
| | | //CakRectT<T> operator|(const CakRectT<T>& rect2) const throw(); |
| | | |
| | | CakRectT<T> MulDiv(T nMultiplier, T nDivisor) const throw(); |
| | | |
| | | //ìì ì ì°ë í¨ìë¤ |
| | | public: |
| | | inline void set(T l, T t, T r, T b) |
| | | { |
| | | left = l; |
| | | top = t; |
| | | right = r; |
| | | bottom = b; |
| | | }; |
| | | inline T getWidth(){return right-left;}; |
| | | inline T getHeight(){return bottom-top;}; |
| | | inline T getCenter(){return T(left+(right-left)/2.0);}; |
| | | inline T getVCenter(){return T(top+(bottom-top)/2.0);}; |
| | | void setAlign(){NormalizeRect();}; //ììê°ì´ ì¼ìª½, ì, í°ê°ì´ ì¤ë¥¸ìª½ ìëë¡ ê°ê² íë¤. |
| | | bool getCheckAreaIn(double x, double y); //ì¬ê°í ììì x,yí¬ì¸í¸ê° ìëì§ ê²ì¬ |
| | | bool getCheckWidthIn(double p1); //xí¬ì¸í¸ ê°ì´ë° ì ì´ ìëì§ ê²ì¬ |
| | | bool getCheckHeightIn(double p1); //yí¬ì¸í¸ ê°ì´ë° ì ì´ ìëì§ ê²ì¬ |
| | | |
| | | |
| | | |
| | | }; |
| | | |
| | | |
| | | template<typename T> |
| | | bool CakRectT<T>::IntersectRect( CakRectT<T>* lpRect1, CakRectT<T>* lpRect2 ) throw() |
| | | { |
| | | |
| | | if ( lpRect1->left < lpRect2->right && |
| | | lpRect1->top < lpRect2->bottom && |
| | | lpRect1->right > lpRect2->left && |
| | | lpRect1->bottom > lpRect2->top ) |
| | | { |
| | | //*this = *lpRect2; |
| | | |
| | | lpRect1->left > lpRect2->left ? left = lpRect1->left : left = lpRect2->left ; |
| | | lpRect1->top > lpRect2->top ? top = lpRect1->top : top = lpRect2->top ; |
| | | lpRect1->right < lpRect2->right ? right = lpRect1->right : right = lpRect2->right ; |
| | | lpRect1->bottom < lpRect2->bottom ? bottom = lpRect1->bottom : bottom= lpRect2->bottom ; |
| | | |
| | | return true; |
| | | } |
| | | |
| | | set(0,0,0,0); |
| | | |
| | | return false; |
| | | } |
| | | |
| | | template<typename T> |
| | | bool CakRectT<T>::UnionRect( CakRectT<T>* lpRect1, CakRectT<T>* lpRect2 ) throw() |
| | | { |
| | | |
| | | lpRect1->left < lpRect2->left ? left = lpRect1->left : left = lpRect2->left ; |
| | | lpRect1->top < lpRect2->top ? top = lpRect1->top : top = lpRect2->top ; |
| | | lpRect1->right > lpRect2->right ? right = lpRect1->right : right = lpRect2->right ; |
| | | lpRect1->bottom > lpRect2->bottom ? bottom = lpRect1->bottom : bottom= lpRect2->bottom ; |
| | | |
| | | if ( lpRect1->left < lpRect2->right && |
| | | lpRect1->top < lpRect2->bottom && |
| | | lpRect1->right > lpRect2->left && |
| | | lpRect1->bottom > lpRect2->top ) |
| | | { |
| | | return true; |
| | | } |
| | | |
| | | return false; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | #include "inl/akRectT.inl" |