ScummVM API documentation
polygon.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 /*
23  * This code is based on Broken Sword 2.5 engine
24  *
25  * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
26  *
27  * Licensed under GNU GPL v2
28  *
29  */
30 
31 #ifndef SWORD25_POLYGON_H
32 #define SWORD25_POLYGON_H
33 
34 // Includes
35 #include "sword25/kernel/common.h"
36 #include "sword25/kernel/persistable.h"
37 #include "sword25/math/vertex.h"
38 
39 namespace Sword25 {
40 
41 class Vertex;
42 
46 class Polygon : public Persistable {
47 public:
53  Polygon();
54 
58  Polygon(const Polygon &other);
59 
64 
72  Polygon(int vertexCount_, const Vertex *vertices_);
73 
77  ~Polygon() override;
78 
90  bool init(int vertexCount_, const Vertex *vertices_);
91 
92  //
93  // ** Exploratory methods **
94  //
95 
102  bool isCW() const;
103 
110  bool isCCW() const;
111 
118  bool isPointInPolygon(const Vertex &vertex, bool borderBelongsToPolygon = true) const;
119 
127  bool isPointInPolygon(int x, int y, bool borderBelongsToPolygon = true) const;
128 
132  Vertex getCentroid() const;
133 
134  // Edge belongs to the polygon
135  // Polygon must be CW
136  bool isLineInterior(const Vertex &a, const Vertex &b) const;
137  // Edge does not belong to the polygon
138  // Polygon must be CW
139  bool isLineExterior(const Vertex &a, const Vertex &b) const;
140 
141  //
142  // Manipulation methods
143  //
144 
148  void ensureCWOrder();
149 
153  void ensureCCWOrder();
154 
158  void reverseVertexOrder();
159 
164  void operator+=(const Vertex &delta);
165 
166  //
167  //------------------
168  //
169 
171  int32 vertexCount;
174 
175  bool persist(OutputPersistenceBlock &writer) override;
176  bool unpersist(InputPersistenceBlock &reader) override;
177 
178  Polygon &operator=(const Polygon &p) {
179  init(p.vertexCount, p.vertices);
180  return *this;
181  }
182 
183 private:
184  bool _isCW;
185  Vertex _centroid;
186 
190  Vertex computeCentroid() const;
191 
197  bool computeIsCW() const;
198 
207  int crossProduct(const Vertex &v1, const Vertex &v2, const Vertex &v3) const;
208 
214  bool checkForSelfIntersection() const;
215 
222  int findLRVertexIndex() const;
223 
224  bool isLineInCone(int startVertexIndex, const Vertex &endVertex, bool includeEdges) const;
225 };
226 
227 } // End of namespace Sword25
228 
229 #endif
Vertex * vertices
COntains the Vertecies of the polygon.
Definition: polygon.h:173
bool isCW() const
Eine Polygonklasse.
Definition: polygon.h:46
int32 vertexCount
Specifies the number of Vertecies in the Vertecies array.
Definition: polygon.h:171
void operator+=(const Vertex &delta)
bool init(int vertexCount_, const Vertex *vertices_)
Definition: persistable.h:39
Definition: console.h:27
Definition: display_client.h:53
bool isPointInPolygon(const Vertex &vertex, bool borderBelongsToPolygon=true) const
~Polygon() override
Definition: inputpersistenceblock.h:40
void reverseVertexOrder()
bool isCCW() const
Definition: outputpersistenceblock.h:39
Definition: vertex.h:52
Vertex getCentroid() const