/
hplane.h
219 lines (186 loc) · 6.96 KB
/
hplane.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
/** @file map/bsp/hplane.h BSP Builder Half-plane.
*
* Originally based on glBSP 2.24 (in turn, based on BSP 2.3)
* @see http://sourceforge.net/projects/glbsp/
*
* @authors Copyright © 2007-2013 Daniel Swanson <danij@dengine.net>
* @authors Copyright © 2000-2007 Andrew Apted <ajapted@gmail.com>
* @authors Copyright © 1998-2000 Colin Reed <cph@moria.org.uk>
* @authors Copyright © 1998-2000 Lee Killough <killough@rsn.hp.com>
*
* @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_BSP_HPLANE
#define DENG_WORLD_MAP_BSP_HPLANE
#include <QList>
#include <de/Vector>
#include "map/bsp/linesegment.h"
#include "partition.h"
/// Two intercepts whose distance is inclusive of this bound will be merged.
#define HPLANE_INTERCEPT_MERGE_DISTANCE_EPSILON 1.0 / 128
class Sector;
class Vertex;
namespace de {
namespace bsp {
class EdgeTips;
/**
* Models the partitioning binary space half-plane.
*/
class HPlane
{
public:
/**
* Used to model an intercept in the list of intersections.
*/
class Intercept
{
public: /// @todo make private:
// True if this intersection was on a self-referencing line.
bool selfRef;
/// Sector on each side of the vertex (along the partition), or @c 0
/// if that direction is "closed" (i.e., the intercept point is along
/// a map line that has no Sector on the relevant side).
Sector *before;
Sector *after;
public:
Intercept(double distance, LineSegment &lineSeg, int edge);
bool operator < (Intercept const &other) const {
return _distance < other._distance;
}
/**
* Determine the distance between "this" and the @a other intercept.
*/
double operator - (Intercept const &other) const {
return _distance - other._distance;
}
/**
* Returns distance along the half-plane relative to the origin.
*/
double distance() const { return _distance; }
/**
* Returns the intercepted line segment.
*/
LineSegment &lineSegment() const;
/**
* Returns the identifier for the relevant edge of the intercepted
* line segment.
*/
int lineSegmentEdge() const;
/**
* Returns the relative vertex from the intercepted line segment.
*
* @see lineSegment(), lineSegmentEdge()
*/
inline Vertex &vertex() const {
return lineSegment().vertex(lineSegmentEdge());
}
#ifdef DENG_DEBUG
void debugPrint() const;
#endif
private:
/// Distance along the half-plane relative to the origin.
double _distance;
// The intercepted line segment and edge identifier.
LineSegment *_lineSeg;
int _edge;
};
typedef QList<Intercept> Intercepts;
public:
/**
* Construct a new half-plane with the given origin and direction.
*
* @param partitionOrigin Origin of the partition line.
* @param partitionDirection Direction of the partition line.
*/
HPlane(Vector2d const &partitionOrigin = Vector2d(0, 0),
Vector2d const &partitionDirection = Vector2d(0, 0));
/**
* Reconfigure the half-plane according to the given line segment.
*
* @param newLineSeg The "new" line segment to configure using.
*/
void configure(LineSegment const &newLineSeg);
/**
* Perform intersection of the half-plane with the specified @a lineSeg.
* If the two are found to intersect -- a new intercept will be added to
* the list of intercepts. If a previous intersection for the specified
* @a lineSeg @a edge has already been found then no new intercept will
* be created and @c 0 is returned.
*
* @param lineSeg Line segment to perform intersection with.
* @param edge Line segment edge identifier of the vertex to associate
* with any resulting intercept.
* @param edgeTips Set of EdgeTips for the identified @a edge of
* @a lineSeg. (@todo Refactor away -ds)
*
* @return The resultant new intercept; otherwise @a 0.
*/
Intercept *intercept(LineSegment const &lineSeg, int edge,
EdgeTips const &edgeTips);
/**
* Sort and then merge near-intercepts from the given list.
*
* @todo fixme: Logically this is very suspect. Implementing this logic by
* merging near-intercepts at hplane level is wrong because this does
* nothing about any intercepting half-edge vertices. Consequently, rather
* than moving the existing vertices and welding them, this will result in
* the creation of new gaps gaps along the partition and result in holes
* (which buildHEdgesAtIntersectionGaps() will then warn about).
*
* This should be redesigned so that near-intercepting vertices are welded
* in a stable manner (i.e., not incrementally, which can result in vertices
* drifting away from the hplane). Logically, therefore, this should not
* be done prior to creating hedges along the partition - instead this
* should happen afterwards. -ds
*
* @param intercepts The list of intercepts to be sorted (in place).
*/
void sortAndMergeIntercepts();
/**
* Clear the list of intercept "points" for the half-plane.
*/
void clearIntercepts();
#ifdef DENG_DEBUG
void printIntercepts() const;
#endif
/**
* Returns the Partition (immutable) used to model the partitioning line of
* the half-plane.
*
* @see configure()
*/
Partition const &partition() const;
/**
* Returns a copy of the LineSegment (immutable) from which the half-plane
* was originally configured.
*
* @see configure()
*/
LineSegment const &lineSegment() const;
/**
* Returns the list of intercepts for the half-plane for efficient traversal.
*
* @note This list may or may not yet be sorted. If a sorted list is desired
* then sortAndMergeIntercepts() should first be called.
*
* @see interceptLineSegment()
*/
Intercepts const &intercepts() const;
private:
DENG2_PRIVATE(d)
};
} // namespace bsp
} // namespace de
#endif // DENG_WORLD_MAP_BSP_HPLANE