My Project
ParaRegion.h
1 #pragma once
2 #include "ParaRect.h"
3 #include <vector>
4 
5 namespace ParaEngine
6 {
7  class QRegion
8  {
9  public:
10  enum RegionType { Rectangle, Ellipse };
11 
12  QRegion();
13  QRegion(int x, int y, int w, int h, RegionType t = Rectangle);
14  QRegion(const QRect &r, RegionType t = Rectangle);
15  QRegion(const QRegion &region);
16  ~QRegion();
17  QRegion &operator=(const QRegion &);
18 
19  inline void swap(QRegion &other) {
20  std::swap(*this, other);
21  }
22 
23  bool isEmpty() const;
24  bool isNull() const;
25 
26  bool contains(const QPoint &p) const;
27  bool contains(const QRect &r) const;
28 
29  /*
30  * Returns \c true if r is guaranteed to be fully contained in this region.
31  * A false return value does not guarantee the opposite.
32  */
33  inline bool contains(const QRegion &r) const {
34  return contains(r.extents);
35  }
36 
37  /*
38  * Returns \c true if this region is guaranteed to be fully contained in r.
39  */
40  inline bool within(const QRect &r1) const {
41  const QRect &r2 = extents;
42  return r2.left() >= r1.left() && r2.right() <= r1.right()
43  && r2.top() >= r1.top() && r2.bottom() <= r1.bottom();
44  }
45 
46  inline void updateInnerRect(const QRect &rect) {
47  const int area = rect.width() * rect.height();
48  if (area > innerArea) {
49  innerArea = area;
50  innerRect = rect;
51  }
52  }
53 
54  inline void vectorize() {
55  if (numRects == 1) {
56  if (!rects.size())
57  rects.resize(1);
58  rects[0] = extents;
59  }
60  }
61 
62  inline void append(const QRect *r);
63  void append(const QRegion *r);
64  void prepend(const QRect *r);
65  void prepend(const QRegion *r);
66  inline bool canAppend(const QRect *r) const;
67  inline bool canAppend(const QRegion *r) const;
68  inline bool canPrepend(const QRect *r) const;
69  inline bool canPrepend(const QRegion *r) const;
70 
71  inline bool mergeFromRight(QRect *left, const QRect *right);
72  inline bool mergeFromLeft(QRect *left, const QRect *right);
73  inline bool mergeFromBelow(QRect *top, const QRect *bottom,
74  const QRect *nextToTop,
75  const QRect *nextToBottom);
76  inline bool mergeFromAbove(QRect *bottom, const QRect *top,
77  const QRect *nextToBottom,
78  const QRect *nextToTop);
79 
80  public:
81 
82  void translate(int dx, int dy);
83  inline void translate(const QPoint &p) { translate(p.x(), p.y()); }
84  QRegion translated(int dx, int dy) const;
85  inline QRegion translated(const QPoint &p) const { return translated(p.x(), p.y()); }
86 
87  QRegion united(const QRegion &r) const;
88  QRegion united(const QRect &r) const;
89  QRegion intersected(const QRegion &r) const;
90  QRegion intersected(const QRect &r) const;
91  QRegion subtracted(const QRegion &r) const;
92  QRegion xored(const QRegion &r) const;
93 
94  bool intersects(const QRegion &r) const;
95  bool intersects(const QRect &r) const;
96 
97  QRect boundingRect() const;
98  std::vector<QRect> Rects() const;
99  void setRects(const QRect *rect, int num);
100  int rectCount() const;
101 
102  const QRegion operator|(const QRegion &r) const;
103  const QRegion operator+(const QRegion &r) const;
104  const QRegion operator+(const QRect &r) const;
105  const QRegion operator&(const QRegion &r) const;
106  const QRegion operator&(const QRect &r) const;
107  const QRegion operator-(const QRegion &r) const;
108  const QRegion operator^(const QRegion &r) const;
109  QRegion& operator|=(const QRegion &r);
110  QRegion& operator+=(const QRegion &r);
111  QRegion& operator+=(const QRect &r);
112  QRegion& operator&=(const QRegion &r);
113  QRegion& operator&=(const QRect &r);
114  QRegion& operator-=(const QRegion &r);
115  QRegion& operator^=(const QRegion &r);
116 
117  bool operator==(const QRegion &r) const;
118  inline bool operator!=(const QRegion &r) const { return !(operator==(r)); }
119 
120  private:
121  QRegion copy() const; // helper of detach.
122  void detach();
123  friend bool qt_region_strictContains(const QRegion &region, const QRect &rect);
124 
125  private:
126  int numRects;
127  std::vector<QRect> rects;
128  QRect extents;
129  QRect innerRect;
130  int innerArea;
131  };
132 }
133 
Definition: Rectangle.h:7
different physics engine has different winding order.
Definition: EventBinding.h:32
when concerting QRect with QRectF and RECT, we ensure that their left, top and width, height are the same.
Definition: ParaRect.h:16
Definition: other.hpp:41
Definition: ParaPoint.h:5
Definition: ParaRegion.h:7