My Project
qpolygon.h
1 #pragma once
2 #include "ParaPoint.h"
3 
4 namespace ParaEngine
5 {
6  class QMatrix;
7  class QTransform;
8  class QRect;
9 
10  class QPolygon : public std::vector < QPoint >
11  {
12  public:
13  inline QPolygon() {}
14  inline ~QPolygon() {}
15  inline explicit QPolygon(int size);
16  inline QPolygon(const QPolygon &a) : std::vector<QPoint>(a) {}
17  inline /*implicit*/ QPolygon(const std::vector<QPoint> &v) : std::vector<QPoint>(v) {}
18  QPolygon(const QRect &r, bool closed = false);
19  QPolygon(int nPoints, const int *points);
20  inline void swap(QPolygon &other) { std::vector<QPoint>::swap(other); } // prevent std::vector<QPoint><->QPolygon swaps
21 
22  const ParaEngine::QPoint* constData() const;
23 
24  void translate(int dx, int dy);
25  void translate(const QPoint &offset);
26 
27  QPolygon translated(int dx, int dy) const;
28  inline QPolygon translated(const QPoint &offset) const;
29 
30  QRect boundingRect() const;
31 
32  void point(int i, int *x, int *y) const;
33  QPoint point(int i) const;
34  void setPoint(int index, int x, int y);
35  void setPoint(int index, const QPoint &p);
36  void setPoints(int nPoints, const int *points);
37  void setPoints(int nPoints, int firstx, int firsty, ...);
38  void putPoints(int index, int nPoints, const int *points);
39  void putPoints(int index, int nPoints, int firstx, int firsty, ...);
40  void putPoints(int index, int nPoints, const QPolygon & from, int fromIndex = 0);
41 
42  bool containsPoint(const QPoint &pt, FillRule fillRule) const;
43 
44  QPolygon united(const QPolygon &r) const;
45  QPolygon intersected(const QPolygon &r) const;
46  QPolygon subtracted(const QPolygon &r) const;
47 
48  inline QPolygon& operator << (const QPoint& pt){
49  push_back(pt);
50  return *this;
51  }
52  };
53 
54  inline QPolygon::QPolygon(int asize) : std::vector<QPoint>(asize) {}
55 
56  /*****************************************************************************
57  Misc. QPolygon functions
58  *****************************************************************************/
59 
60  inline void QPolygon::setPoint(int index, const QPoint &pt)
61  {
62  (*this)[index] = pt;
63  }
64 
65  inline void QPolygon::setPoint(int index, int x, int y)
66  {
67  (*this)[index] = QPoint(x, y);
68  }
69 
70  inline QPoint QPolygon::point(int index) const
71  {
72  return at(index);
73  }
74 
75  inline void QPolygon::translate(const QPoint &offset)
76  {
77  translate(offset.x(), offset.y());
78  }
79 
80  inline QPolygon QPolygon::translated(const QPoint &offset) const
81  {
82  return translated(offset.x(), offset.y());
83  }
84 
85  class QRectF;
86 
87  class QPolygonF : public std::vector < QPointF >
88  {
89  public:
90  inline QPolygonF() {}
91  inline ~QPolygonF() {}
92  inline explicit QPolygonF(int size);
93  inline QPolygonF(const QPolygonF &a) : std::vector<QPointF>(a) {}
94  inline /*implicit*/ QPolygonF(const std::vector<QPointF> &v) : std::vector<QPointF>(v) {}
95  QPolygonF(const QRectF &r);
96  /*implicit*/ QPolygonF(const QPolygon &a);
97  inline void swap(QPolygonF &other) { std::vector<QPointF>::swap(other); } // prevent std::vector<QPointF><->QPolygonF swaps
98 
99  const ParaEngine::QPointF* constData() const;
100 
101  inline void translate(float dx, float dy);
102  void translate(const QPointF &offset);
103 
104  inline QPolygonF translated(float dx, float dy) const;
105  QPolygonF translated(const QPointF &offset) const;
106 
107  QPolygon toPolygon() const;
108 
109  bool isClosed() const { return !empty() && front() == back(); }
110 
111  QRectF boundingRect() const;
112 
113  bool containsPoint(const QPointF &pt, FillRule fillRule) const;
114 
115  QPolygonF united(const QPolygonF &r) const;
116  QPolygonF intersected(const QPolygonF &r) const;
117  QPolygonF subtracted(const QPolygonF &r) const;
118 
119  inline QPolygonF& operator << (const QPointF& pt){
120  push_back(pt);
121  return *this;
122  }
123  };
124 
125  inline QPolygonF::QPolygonF(int asize) : std::vector<QPointF>(asize) {}
126 
127  inline void QPolygonF::translate(float dx, float dy)
128  {
129  translate(QPointF(dx, dy));
130  }
131 
132  inline QPolygonF QPolygonF::translated(float dx, float dy) const
133  {
134  return translated(QPointF(dx, dy));
135  }
136 
137 
138 }
Definition: ParaPoint.h:203
different physics engine has different winding order.
Definition: EventBinding.h:32
Definition: ParaRect.h:517
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: qpolygon.h:10
Definition: qpolygon.h:87