Skip to content

Commit c54f1ed

Browse files
author
Meulemans
committed
Fixed bug in DT computation
1 parent 6911fa9 commit c54f1ed

File tree

1 file changed

+39
-21
lines changed

1 file changed

+39
-21
lines changed

src/nl/tue/geometrycore/algorithms/delaunay/DelaunayTriangulation.java

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -77,29 +77,29 @@ private TVertex compute(int low, int high) {
7777

7878
switch (high - low) {
7979
case 0:
80-
//System.err.println("Should not occur");
80+
System.err.println("Should not occur");
8181
return null;
8282
case 1: {
8383
// one vertex
84-
//System.err.println("CALL " + low + "-" + (high - 1));
84+
// System.err.println("CALL " + low + "-" + (high - 1) + " :: " + _vertices.get(low) + "-" + _vertices.get(high - 1));
8585
TVertex u = _vertices.get(low);
86-
//System.err.println("RET " + u.getGraphIndex());
86+
// System.err.println("RET " + u + " << " + low + "-" + (high - 1));
8787
return u;
8888
}
8989
case 2: {
9090
// one line segment
91-
//System.err.println("CALL " + low + "-" + (high - 1));
91+
// System.err.println("CALL " + low + "-" + (high - 1) + " :: " + _vertices.get(low) + "-" + _vertices.get(high - 1));
9292
TVertex u = _vertices.get(low);
9393
TVertex v = _vertices.get(low + 1);
9494
addEdge(u, v);
9595
TVertex min = u.getY() <= v.getY() ? u : v;
96-
//System.err.println("RET " + min.getGraphIndex());
96+
// System.err.println("RET " + min + " << " + low + "-" + (high - 1));
9797
return min;
9898
}
9999
case 3: {
100100
// one triangle
101101

102-
//System.err.println("CALL " + low + "-" + (high - 1));
102+
// System.err.println("CALL " + low + "-" + (high - 1) + " :: " + _vertices.get(low) + "-" + _vertices.get(high - 1));
103103
TVertex u = _vertices.get(low);
104104
TVertex v = _vertices.get(low + 1);
105105
TVertex w = _vertices.get(low + 2);
@@ -108,22 +108,24 @@ private TVertex compute(int low, int high) {
108108
addEdge(w, u);
109109
TVertex min = u.getY() <= v.getY() && u.getY() <= w.getY()
110110
? u : (v.getY() <= w.getY() ? v : w);
111-
//System.err.println("RET " + min.getGraphIndex());
111+
// System.err.println("RET " + min + " << " + low + "-" + (high - 1));
112112
return min;
113113
}
114114
default: {
115115
int mid = (low + high) / 2;
116116
TVertex u = compute(low, mid);
117117
TVertex v = compute(mid, high);
118118

119-
//System.err.println("CALL " + low + "-" + (high - 1));
120-
//System.err.println(" mid: " + mid);
119+
// System.err.println("CALL " + low + "-" + (high - 1) + " :: " + _vertices.get(low) + "-" + _vertices.get(high - 1));
120+
121+
// System.err.println(" mid: " + mid);
121122
if (u == null || v == null) {
123+
System.err.println(" nulls? << " + low + "-" + (high - 1));
122124
return null;
123125
}
124126

125-
// System.err.println("u" + u.getGraphIndex());
126-
// System.err.println("v" + v.getGraphIndex());
127+
// System.err.println(" u " + u);
128+
// System.err.println(" v " + v);
127129

128130
TVertex min = u.getY() <= v.getY() ? u : v;
129131
// walk up to find edge on lower convex hull
@@ -137,55 +139,64 @@ private TVertex compute(int low, int high) {
137139
v = shiftHull(v, u, mid, Side.RIGHT);
138140
} while (u != prevu || v != prevv);
139141

140-
// System.err.println("u" + u.getGraphIndex());
141-
// System.err.println("v" + v.getGraphIndex());
142-
143142
addEdge(u, v);
144143

145144
// start merge process
146145
TVertex u_cand = candidate(u, v, mid, Side.LEFT);
147146
TVertex v_cand = candidate(v, u, mid, Side.RIGHT);
148147

148+
// System.err.println(" u " + u);
149+
// System.err.println(" v " + v);
150+
// System.err.println(" u_cand " + u_cand);
151+
// System.err.println(" v_cand " + v_cand);
152+
149153
while (u_cand != null || v_cand != null) {
150154
if (u_cand != null && v_cand != null) {
151155
Circle c = Circle.byThreePoints(u, v, u_cand);
156+
// System.err.println(" c "+c);
152157
if (c != null && c.contains(v_cand)) {
158+
// System.err.println(" discarding u_cand");
153159
u_cand = null;
154160
} else {
161+
// System.err.println(" discarding v_cand");
155162
v_cand = null;
156163
}
157164
}
158165

159166
if (u_cand != null) {
160167
if (addEdge(u_cand, v)) {
161-
//System.err.println("DUPLICATE EDGE -- aborting");
168+
System.err.println("DUPLICATE EDGE -- aborting" + " << " + low + "-" + (high - 1));
162169
return null;
163170
}
164171
u = u_cand;
165172
} else { // v_cand != null
166173
if (addEdge(u, v_cand)) {
167-
//System.err.println("DUPLICATE EDGE -- aborting");
174+
System.err.println("DUPLICATE EDGE -- aborting" + " << " + low + "-" + (high - 1));
168175
return null;
169176
}
170177
v = v_cand;
171178
}
172179

173180
u_cand = candidate(u, v, mid, Side.LEFT);
174181
v_cand = candidate(v, u, mid, Side.RIGHT);
182+
183+
// System.err.println(" u " + u);
184+
// System.err.println(" v " + v);
185+
// System.err.println(" u_cand " + u_cand);
186+
// System.err.println(" v_cand " + v_cand);
175187
}
176188

177-
//System.err.println("RET " + min.getGraphIndex());
189+
// System.err.println("RET " + min + " << " + low + "-" + (high - 1));
178190
return min;
179191
}
180192
}
181193
}
182194

183195
private boolean addEdge(TVertex u, TVertex v) {
196+
// System.err.println(" adding " + u + "-" + v);
184197
if (u.isNeighborOf(v)) {
185198
return true;
186199
}
187-
188-
//System.err.println(" adding " + u.getGraphIndex() + " " + v.getGraphIndex());
189200
_input.addEdge(u, v, _cloner.clone(new LineSegment(u.clone(), v.clone())));
190201
return false;
191202
}
@@ -237,14 +248,19 @@ private TVertex candidate(TVertex vertex, TVertex other, int mid, Side side) {
237248
Vector dir = Vector.subtract(other, vertex);
238249
dir.normalize();
239250

251+
// System.err.println(" candidate? "+vertex+" "+other);
252+
240253
TVertex first = findFirst(vertex, dir, mid, side);
254+
// System.err.println(" first "+first);
241255
if (first == null) {
242256
return null;
243257
}
244258
TVertex second = findSecond(vertex, dir, mid, side);
259+
// System.err.println(" second "+second);
245260
Circle c = Circle.byThreePoints(vertex, other, first);
261+
// System.err.println(" c "+c);
246262
while (second != null && c != null && c.contains(second)) {
247-
//System.err.println(" removing " + vertex.getGraphIndex() + " - " + first.getGraphIndex());
263+
// System.err.println(" removing " + vertex + "-" + first);
248264
_input.removeEdge(vertex.getEdgeTo(first));
249265
first = second;
250266
second = findSecond(vertex, dir, mid, side);
@@ -308,6 +324,8 @@ private TVertex findSecond(TVertex vertex, Vector dir, int mid, Side side) {
308324
double a = side == Side.LEFT
309325
? dir.computeCounterClockwiseAngleTo(edir, false, false)
310326
: dir.computeClockwiseAngleTo(edir, false, false);
327+
328+
// System.err.println(" "+nbr+" :: "+a);
311329
// if (a > Math.PI * 2 - DoubleUtil.EPS) {
312330
// a = 0;
313331
// }
@@ -326,7 +344,7 @@ private TVertex findSecond(TVertex vertex, Vector dir, int mid, Side side) {
326344
return null;
327345
}
328346

329-
if (opt >= Math.PI) {
347+
if (sec_opt >= Math.PI) {
330348
return null;
331349
}
332350

0 commit comments

Comments
 (0)