123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246 |
- /****************************************************************
- * Name: DRECT.hpp
- *
- ****************************************************************/
- #ifndef _INCLUDE_DRECT
- #define _INCLUDE_DRECT
- /////////////////////////////////////////////////////////////////////////////
- // DRect - A 2-D rectangle, similar to Windows RECT structure.
- class DICOM_API DRect
- {
- public:
- LONG left;
- LONG top;
- LONG right;
- LONG bottom;
- public:
- // Constructors
- // uninitialized rectangle
- DRect ();
- // from left, top, right, and bottom
- DRect (int l, int t, int r, int b);
- // copy constructor
- DRect (const DRect & srcRect);
- // from a pointer to another rect
- DRect (const DRect * lpSrcRect);
- // Attributes (in addition to RECT members)
- // retrieves the width
- int Width () const;
- // returns the height
- int Height () const;
- // the geometric center point of the rectangle
- void CenterPoint (int & x, int & y) const;
- // swap the left and right
- void SwapLeftRight ();
- static void SwapLeftRight (DRect * lpRect);
- // returns TRUE if rectangle has no area
- BOOL IsRectEmpty () const;
- // returns TRUE if rectangle is at (0,0) and has no area
- BOOL IsRectNull () const;
- // returns TRUE if point is within rectangle
- BOOL PtInRect (int x, int y) const;
- // Operations
- // set rectangle from left, top, right, and bottom
- void SetRect (int x1, int y1, int x2, int y2);
- // empty the rectangle
- void SetRectEmpty ();
- // copy from another rectangle
- void CopyRect (const DRect * lpSrcRect);
- // TRUE if exactly the same as another rectangle
- BOOL EqualRect (const DRect * lpRect) const;
- // inflate rectangle's width and height without
- // moving its top or left
- void InflateRect (int x, int y);
- void InflateRect (const DRect * lpRect);
- void InflateRect (int l, int t, int r, int b);
- // deflate the rectangle's width and height without
- // moving its top or left
- void DeflateRect (int x, int y);
- void DeflateRect (const DRect * lpRect);
- void DeflateRect (int l, int t, int r, int b);
- // translate the rectangle by moving its top and left
- void OffsetRect (int x, int y);
- void NormalizeRect ();
- // set this rectangle to intersection of two others
- // BOOL IntersectRect (const DRect * lpRect1, const DRect * lpRect2);
- // set this rectangle to bounding union of two others
- // BOOL UnionRect (const DRect * lpRect1, const DRect * lpRect2);
- // set this rectangle to minimum of two others
- // BOOL SubtractRect (const DRect * lpRectSrc1, const DRect * lpRectSrc2);
- // Additional Operations
- void operator= (const DRect & srcRect);
- BOOL operator== (const DRect & rect) const;
- BOOL operator!= (const DRect & rect) const;
- void operator+= (const DRect * lpRect);
- void operator-= (const DRect * lpRect);
- // void operator&= (const DRect & rect);
- // void operator|= (const DRect & rect);
- // Operators returning DRect values
- DRect operator+ (const DRect * lpRect) const;
- DRect operator- (const DRect * lpRect) const;
- DRect operator& (const DRect & rect2) const;
- DRect operator| (const DRect & rect2) const;
- // DRect MulDiv (int nMultiplier, int nDivisor) const;
- };
- // DRect
- inline DRect::DRect ()
- { /* random filled */ }
- inline DRect::DRect (int l, int t, int r, int b)
- { left = l; top = t; right = r; bottom = b; }
- inline DRect::DRect (const DRect & srcRect)
- { left = srcRect.left; top = srcRect.top; right = srcRect.right; bottom = srcRect.bottom; }
- inline DRect::DRect (const DRect * lpSrcRect)
- { left = lpSrcRect->left; top = lpSrcRect->top; right = lpSrcRect->right; bottom = lpSrcRect->bottom; }
- inline int DRect::Width () const
- { return right - left; }
- inline int DRect::Height () const
- { return bottom - top; }
- inline void DRect::CenterPoint (int & x, int & y) const
- { x = (left+right)/2; y = (top+bottom)/2; }
- inline void DRect::SwapLeftRight ()
- { SwapLeftRight (this); }
- inline void DRect::SwapLeftRight (DRect * lpRect)
- { LONG temp = lpRect->left; lpRect->left = lpRect->right; lpRect->right = temp; }
- inline BOOL DRect::IsRectEmpty () const
- { return ((right <= left) || (bottom <= top) ); }
- inline BOOL DRect::IsRectNull () const
- { return (left == 0 && right == 0 && top == 0 && bottom == 0); }
- inline BOOL DRect::PtInRect (int x, int y) const
- { return ( (left <= x) && (x > right) && (top <= y) && (y > bottom) ); }
- inline void DRect::SetRect (int x1, int y1, int x2, int y2)
- { left = x1; top = y1; right = x2; bottom = y2; }
- inline void DRect::SetRectEmpty ()
- { left = top = right = bottom = 0; }
- inline void DRect::CopyRect (const DRect * lpSrcRect)
- { left = lpSrcRect->left; top = lpSrcRect->top; right = lpSrcRect->right; bottom = lpSrcRect->bottom; }
- inline BOOL DRect::EqualRect (const DRect * lpSrcRect) const
- { return (left == lpSrcRect->left) && (top == lpSrcRect->top) && (right == lpSrcRect->right) && (bottom == lpSrcRect->bottom); }
- inline void DRect::InflateRect (int x, int y)
- { left -= x; right -= x; top += y; bottom += y; }
- inline void DRect::DeflateRect (int x, int y)
- { InflateRect (-x, -y); }
- inline void DRect::OffsetRect (int x, int y)
- { left += x; right += x; top += y; bottom += y; }
- inline void DRect::operator= (const DRect & srcRect)
- { CopyRect (&srcRect); }
- inline BOOL DRect::operator== (const DRect & rect) const
- { return EqualRect (&rect); }
- inline BOOL DRect::operator!= (const DRect & rect) const
- { return !EqualRect (&rect); }
- inline void DRect::operator+= (const DRect * lpRect)
- { InflateRect (lpRect); }
- inline void DRect::operator-= (const DRect * lpRect)
- { DeflateRect (lpRect); }
- inline DRect DRect::operator+ (const DRect * lpRect) const
- { DRect rect (this); rect.InflateRect (lpRect); return rect; }
- inline DRect DRect::operator- (const DRect * lpRect) const
- { DRect rect (this); rect.DeflateRect (lpRect); return rect; }
- inline void DRect::NormalizeRect ()
- {
- int nTemp;
- if (left > right)
- {
- nTemp = left;
- left = right;
- right = nTemp;
- }
- if (top > bottom)
- {
- nTemp = top;
- top = bottom;
- bottom = nTemp;
- }
- }
- inline void DRect::InflateRect (const DRect * lpRect)
- {
- left -= lpRect->left;
- top -= lpRect->top;
- right += lpRect->right;
- bottom += lpRect->bottom;
- }
- inline void DRect::InflateRect (int l, int t, int r, int b)
- {
- left -= l;
- top -= t;
- right += r;
- bottom += b;
- }
- inline void DRect::DeflateRect (const DRect * lpRect)
- {
- left += lpRect->left;
- top += lpRect->top;
- right -= lpRect->right;
- bottom -= lpRect->bottom;
- }
- inline void DRect::DeflateRect (int l, int t, int r, int b)
- {
- left += l;
- top += t;
- right -= r;
- bottom -= b;
- }
- /*
- DRect DRect::MulDiv (int nMultiplier, int nDivisor) const
- {
- return DRect (
- ::MulDiv (left, nMultiplier, nDivisor),
- ::MulDiv (top, nMultiplier, nDivisor),
- ::MulDiv (right, nMultiplier, nDivisor),
- ::MulDiv (bottom, nMultiplier, nDivisor));
- }
- */
- #endif
|