/
polygon.h
138 lines (115 loc) · 3.61 KB
/
polygon.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/** @file map/polygon.h World Map Polygon Geometry.
*
* @authors Copyright © 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2006-2013 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA</small>
*/
#ifndef DENG_WORLD_MAP_POLYGON
#define DENG_WORLD_MAP_POLYGON
#include <de/aabox.h>
#include <de/Error>
#include <de/Vector>
class BspLeaf;
class HEdge;
namespace de {
/**
* Polygon geometry.
*
* @ingroup map
*/
class Polygon
{
public:
/// No BSP leaf is attributed. @ingroup errors
DENG2_ERROR(MissingBspLeafError);
public: /// @todo Make private:
/// First half-edge in the face geometry. Ordered by angle, clockwise starting
/// from the smallest angle.
HEdge *_hedge;
/// Number of HEdge's in the face.
int _hedgeCount;
public:
Polygon();
/**
* Returns @c true iff a BSP leaf is attributed to the polygon.
*/
bool hasBspLeaf() const;
/**
* Returns the BSP leaf attributed to the polygon.
*
* @see hasBspLeaf()
*/
BspLeaf &bspLeaf() const;
/**
* Change the BSP leaf attributed to the polygon.
*
* @param newBspLeaf New BSP leaf to attribute the polygon. Ownership is
* unaffected. Can be @c 0 (to clear the attribution).
*
* @see hasBspLeaf(), bspLeaf()
*/
void setBspLeaf(BspLeaf *newBspLeaf);
/**
* Returns a pointer to the first half-edge of the Face of the polygon (note
* that half-edges are sorted in a clockwise order). May return @c 0 if there
* is no half-edge linked to the face.
*/
HEdge *firstHEdge() const;
/**
* Total number of half-edges in the polygon.
*/
int hedgeCount() const;
/**
* Returns the axis-aligned bounding box which encompases all the vertexes
* which define the geometry.
*/
AABoxd const &aaBox() const;
/**
* Update the geometry's axis-aligned bounding box to encompass all vertexes.
*/
void updateAABox();
/**
* Returns the point described by the average origin coordinates of all the
* vertexes which define the geometry.
*/
Vector2d const ¢er() const;
/**
* Update the center point of the geometry.
*
* @pre Axis-aligned bounding box must have been initialized.
*/
void updateCenter();
/**
* Determines whether the geometry of the polygon is currently convex.
*
* @note Due to the potential computational complexity of determining convexity
* this should be called sparingly/only when necessary.
*
* @todo Cache this result.
*/
bool isConvex() const;
#ifdef DENG_DEBUG
/**
* Output a textual, human-readable description/representation of the polygon
* to the application's output log.
*/
void print() const;
#endif
private:
DENG2_PRIVATE(d)
};
} // namespace de
#endif // DENG_WORLD_MAP_POLYGON