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