OpenLexocad  27.1
Rect.h
Go to the documentation of this file.
1 
9 #ifndef RECT_H
10 #define RECT_H
11 
12 #include <Geom/Pnt2d.h>
13 
14 #include <cmath>
15 
16 
17 namespace Geom
18 
19 {
20 class Pnt;
21 
22 
27 class LX_GEOM_EXPORT Rect
28 {
29 public:
30  Rect();
31  Rect(const Pnt2d& bottomleft, const Pnt2d& topright);
32  Rect(double left, double bottom, double width, double height);
33 
34 
35  bool isNull(void) const;
36  bool isEmpty(void) const;
37  bool isValid(void) const;
38 
39  void setNull(void);
40  void makeSingular(void);
41 
42  void getRect(double* x, double* y, double* w, double* h) const;
43 
44  double left(void) const { return _x1; }
45  double right(void) const { return _x2; }
46  double bottom(void) const { return _y1; }
47  double top(void) const { return _y2; }
48 
49  double width(void) const { return abs(_x2 - _x1); }
50  double height(void) const { return abs(_y2 - _y1); }
51 
52  Geom::Pnt2d bottomLeft(void) const { return Pnt2d(_x1, _y1); }
53  Geom::Pnt2d bottomRight(void) const { return Pnt2d(_x2, _y1); }
54  Geom::Pnt2d topLeft(void) const { return Pnt2d(_x1, _y2); }
55  Geom::Pnt2d topRight(void) const { return Pnt2d(_x2, _y2); }
56  Geom::Pnt2d center(void) const { return Pnt2d((_x1 + _x2) / 2, (_y1 + _y2) / 2); }
57 
58  void setLeft(double left);
59  void setRight(double right);
60  void setBottom(double bottom);
61  void setTop(double top);
62 
63  void setWidth(double w) { _x2 = _x1 + w; }
64  void setHeight(double h) { _y2 = _y1 + h; }
65  void setSize(double width, double height);
66 
67  void moveCenter(const Pnt& p);
68  void moveCenter(double x, double y);
69  void grow(double value);
70  void shrink(double value);
71  void translate(double dx, double dy);
72 
73 
74  Rect operator|(const Rect& r) const;
75  Rect& operator|=(const Rect& r);
76 
77  void unite(const Rect& t);
78  Rect united(const Rect& r) const;
79  Rect normalized(void) const;
80 
81  bool contains(const Geom::Pnt& point) const;
82  bool intersects(const Geom::Rect& r) const;
83 
84  /*
85  void dump(void)
86  {
87  printf("Base Rectangle:\n");
88  printf(" . x1: %f\n", _x1);
89  printf(" . y1: %f\n", _y1);
90  printf(" . x2: %f\n", _x2);
91  printf(" . y2: %f\n", _y2);
92  printf(" . w: %f\n", width());
93  printf(" . h: %f\n", height());
94 
95  }
96  */
97 
98 private:
99  double _x1;
100  double _y1;
101  double _x2;
102  double _y2;
103 };
104 
105 
106 
107 } // namespace Geom
108 
109 
110 
111 #endif
Definition: Variant.h:60
Geom::Pnt2d center(void) const
Definition: Rect.h:56
double left(void) const
Definition: Rect.h:44
Geom::Pnt2d bottomLeft(void) const
Definition: Rect.h:52
Defines a non-persistent 3D Cartesian point.
Definition: Pnt.h:43
Geom::Pnt2d topRight(void) const
Definition: Rect.h:55
Geom::Pnt2d topLeft(void) const
Definition: Rect.h:54
Geom::Pnt2d bottomRight(void) const
Definition: Rect.h:53
Definition: Rect.h:27
void setWidth(double w)
Definition: Rect.h:63
double right(void) const
Definition: Rect.h:45
void setHeight(double h)
Definition: Rect.h:64
double bottom(void) const
Definition: Rect.h:46
double height(void) const
Definition: Rect.h:50
double top(void) const
Definition: Rect.h:47
double width(void) const
Definition: Rect.h:49
Defines a non-persistent 2D cartesian point.
Definition: Pnt2d.h:33