box2.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /**********************************************************************
  2. *<
  3. FILE: box2.h
  4. DESCRIPTION:
  5. CREATED BY: Dan Silva
  6. HISTORY:
  7. *> Copyright (c) 1994, All Rights Reserved.
  8. **********************************************************************/
  9. #ifndef _BOX2_H
  10. #define _BOX2_H
  11. #include "ipoint2.h"
  12. #include "point2.h"
  13. #include <windef.h>
  14. class Box2: public RECT {
  15. public:
  16. DllExport Box2();
  17. DllExport Box2(const IPoint2 a, const IPoint2 b);
  18. DllExport int IsEmpty();
  19. DllExport void SetEmpty();
  20. DllExport void Rectify(); // makes top<bottom, left<right
  21. DllExport void Scale(float f);
  22. DllExport void Translate(IPoint2 t);
  23. IPoint2 GetCenter() { return IPoint2((left+right)/2, (top+bottom)/2); }
  24. int x() { return min(left,right); }
  25. int y() { return min(top,bottom); }
  26. int w() { return abs(right-left)+1; }
  27. int h() { return abs(bottom-top)+1; }
  28. void SetW(int w) { right = left + w -1; }
  29. void SetH(int h) { bottom = top + h -1; }
  30. void SetX(int x) { left = x; }
  31. void SetY(int y) { top = y; }
  32. void SetWH(int w, int h) { SetW(w); SetH(h); }
  33. void SetXY(int x, int y) { SetX(x); SetY(y); }
  34. DllExport Box2& operator=(const RECT& r);
  35. DllExport Box2& operator=(RECT& r);
  36. DllExport Box2& operator+=(const Box2& b);
  37. DllExport Box2& operator+=(const IPoint2& p);
  38. int operator==( const Box2& b ) const { return (left==b.left && right==b.right && top==b.top && bottom==b.bottom); }
  39. DllExport int Contains(const IPoint2& p) const; // is point in this box?
  40. };
  41. typedef Box2 Rect;
  42. struct FBox2 {
  43. Point2 pmin;
  44. Point2 pmax;
  45. int IsEmpty() { return pmin.x>pmax.x?1:0; }
  46. void SetEmpty() { pmin = Point2(1E30,1E30); pmax = -pmin; }
  47. FBox2& operator=(const FBox2& r) { pmin = r.pmin; pmax = r.pmax; return *this; }
  48. DllExport FBox2& operator+=(const Point2& p);
  49. DllExport FBox2& operator+=(const FBox2& b);
  50. DllExport int Contains(const Point2& p) const; // is point in this box?
  51. };
  52. #endif