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