@@ -45,16 +45,16 @@ public void setScene(J2DScene scene) {
45
45
public HalfEdge computeSmallDelaunay (ArrayList <KDSPoint > points ) throws Exception {
46
46
if (points .size () == 2 ) {
47
47
// sort them
48
- sort (points );
48
+ // sort(points);
49
49
KDSPoint a = points .get (0 );
50
50
KDSPoint b = points .get (1 );
51
51
HalfEdge e1 = dcel .createEdge (a , b );
52
52
if (e1 .getOrigin ().getPoint (0 ).y () < e1 .getDestination ().getPoint (0 ).y ())
53
53
return e1 ;
54
54
return e1 .getTwin ();
55
55
} else if (points .size () == 3 ) {
56
- // sort them
57
- sort (points );
56
+ // sort them, is it really needed though?
57
+ // sort(points);
58
58
KDSPoint a = points .get (0 );
59
59
KDSPoint b = points .get (1 );
60
60
KDSPoint c = points .get (2 );
@@ -67,23 +67,23 @@ public HalfEdge computeSmallDelaunay(ArrayList<KDSPoint> points) throws Exceptio
67
67
e2 .setPrev (e1 );
68
68
e2 .getTwin ().setNext (e1 .getTwin ());
69
69
70
+ // don't create a triangle if they are collinear
70
71
if (leftOf (a , b , c ) || rightOf (a , b , c )) {
71
72
// connect and create a triangle
72
73
System .out .println ("Creating triangle!" );
73
74
connect (e2 , e1 );
74
75
}
75
- HalfEdge lowest = e1 ;
76
- while (true ) {
77
- if (lowest .getNext () != null && lowerThan (lowest .getNext (), lowest )) {
78
- lowest = lowest .getNext ();
79
- } else {
80
- break ;
81
- }
82
- if (lowest == e1 ) break ;
83
- }
84
- if (lowest .getOrigin ().getPoint (0 ).y () < lowest .getDestination ().getPoint (0 ).y ())
85
- return lowest ;
86
- return lowest .getTwin ();
76
+ // find the lowest point (y-coordinate only)
77
+ KDSPoint lowestPoint ;
78
+ if (a .getY () < b .getY ()) lowestPoint = a ;
79
+ else lowestPoint = b ;
80
+ if (lowestPoint .getY () > c .getY ()) lowestPoint = c ;
81
+
82
+ // find the ccw edge incident to lowest point
83
+ HalfEdge candidateEdge = lowestPoint .getIncidentEdge ();
84
+ if (!isCCW (candidateEdge .getPrev ().getOrigin (), candidateEdge .getOrigin (), candidateEdge .getDestination ()))
85
+ candidateEdge = candidateEdge .getTwin ();
86
+ return candidateEdge ;
87
87
} else {
88
88
throw new Exception ();
89
89
}
@@ -111,20 +111,19 @@ infCircleEnum.INSIDE && lessThan(rNext(right).getOrigin(), right.getOrigin())) {
111
111
} else {
112
112
// TODO I think it should move CW around left as the 'candidate' for lower support can't be on the right
113
113
// side of left when the lowest point in right is lower
114
- while (rPrev (left ) != null && rNext (right ) != null &&
115
- shape .inInfCircle (rPrev (left ).getOrigin (), left .getOrigin (), right .getOrigin ()) ==
116
- infCircleEnum .INSIDE && lessThan (rNext (right ).getOrigin (), right .getOrigin ())) {
114
+ while (lPrev (left ) != null && shape .inInfCircle (lPrev (left ).getOrigin (), left .getOrigin (), right .getOrigin ()) ==
115
+ infCircleEnum .INSIDE && lessThan (lPrev (left ).getOrigin (), left .getOrigin ())) {
117
116
if (rPrev (left ) == null ) break ;
118
- left = rPrev (left );
117
+ left = lPrev (left );
119
118
}
120
119
while (true ) {
121
120
if (shape .inInfCircle (left .getDestination (), left .getOrigin (), right .getOrigin ()) == infCircleEnum .INSIDE ) {
122
- left = rNext (left );
121
+ left = rPrev (left );
123
122
} else if (shape .inInfCircle (right .getDestination (), left .getOrigin (), right .getOrigin ()) == infCircleEnum .INSIDE ) {
124
- right = rNext (right );
123
+ right = rPrev (right );
125
124
} else {
126
- if (oNext (right ) == null ) return connect (left .getTwin (), right ).getTwin ();
127
- return connect (left . getTwin ( ), oNext ( right )).getTwin ();
125
+ if (oNext (left ) == null ) return connect (left , right .getTwin ()).getTwin ();
126
+ return connect (oNext ( left ), right . getTwin ( )).getTwin ();
128
127
}
129
128
System .out .println ("Am I stuck in lowersupport2?" );
130
129
}
@@ -183,10 +182,10 @@ public HalfEdge produceONext(HalfEdge edge) {
183
182
}
184
183
185
184
public HalfEdge produceOPrev (HalfEdge edge ) {
186
- if (lPrev (edge ).isBridge ()) {
185
+ if (lPrev (edge ) != null && lPrev ( edge ) .isBridge ()) {
187
186
delete (lPrev (edge ));
188
187
makeBundle (connect (lPrev (edge ), edge ).getTwin ());
189
- } else if (oPrev (edge ).isBridge ()) {
188
+ } else if (oPrev (edge ) != null && oPrev ( edge ) .isBridge ()) {
190
189
delete (oPrev (edge ));
191
190
makeBundle (oNext (connect (edge , lNext (edge ))));
192
191
}
@@ -326,18 +325,17 @@ public HalfEdge computeRcand() {
326
325
HalfEdge current = null , top = null , t = null ;
327
326
boolean foundRcand = false ;
328
327
// base must be directed from left to right for this
329
- base = base .getTwin ();
330
- rcand = lNext (base );
328
+ rcand = lNext (base .getTwin ());
331
329
332
330
if (rcand != null && shape .inInfCircle (rcand .getDestination (), base .getOrigin (), base .getDestination ()) == infCircleEnum .BEFORE ) {
333
331
rcand = produceOPrev (rcand );
334
332
while (shape .inInfCircle (rcand .getDestination (), base .getDestination (), base .getOrigin ()) == infCircleEnum .BEFORE ) {
335
- delete (oNext (rcand ));
333
+ delete (rNext (rcand ). getTwin ( ));
336
334
if (produceOPrev (rcand ) == null ) break ;
337
335
rcand = produceOPrev (rcand );
338
336
}
339
- if (isValid (rcand )) delete (oNext (rcand ));
340
- else rcand = oNext (rcand );
337
+ if (isValid (rcand )) delete (rNext (rcand ). getTwin ( ));
338
+ else rcand = rNext (rcand ). getTwin ( );
341
339
}
342
340
343
341
if (isValid (rcand )) {
@@ -353,18 +351,19 @@ public HalfEdge computeRcand() {
353
351
current .draw (scene , 0 , Color .ORANGE );
354
352
top = rcand ;
355
353
while (true ) {
354
+ assert rcand != null ;
356
355
if (foundRcand ) break ;
357
- switch (shape .inCircle (rcand .getOrigin (), rcand .getDestination (), base .getOrigin (), current .getDestination ())) {
356
+ switch (shape .inCircle (rcand .getDestination (), rcand .getOrigin (), base .getDestination (), current .getDestination ())) {
358
357
case INSIDE :
359
358
if (current .isBridge () || lNext (current ).isBridge ()) {
360
- current = produceOPrev (lNext (current ));
359
+ current = produceOPrev (oNext (current ));
361
360
}
362
361
if (rightOf (rcand .getOrigin (), rcand .getDestination (), current .getDestination ())) {
363
362
if (lNext (current ) != dNext (rcand )) {
364
363
makeBundle (connect (rcand , current .getTwin ()).getTwin ());
365
364
}
366
365
if (current != oPrev (rcand )) {
367
- makeBundle (connect (lNext (rcand ), current .getTwin ()));
366
+ makeBundle (rPrev ( connect (rNext (rcand ), current .getTwin () )));
368
367
}
369
368
t = produceOPrev (rcand );
370
369
delete (rcand );
@@ -377,7 +376,7 @@ public HalfEdge computeRcand() {
377
376
break ;
378
377
case ONBEFORE :
379
378
if (rightOf (current .getOrigin (), rcand .getDestination (), current .getDestination ())) {
380
- current = lNext (current );
379
+ current = rNext (current );
381
380
} else {
382
381
foundRcand = true ;
383
382
}
@@ -399,15 +398,13 @@ public HalfEdge computeRcand() {
399
398
}
400
399
401
400
if (top != null && rcand != null && top != rcand ) {
402
- makeBundle (connect (top , rcand ));
401
+ makeBundle (rPrev ( connect (top , rcand ) ));
403
402
top = oPrev (rcand );
404
403
}
405
404
if (current != null && top != null && oNext (current ) != top ) {
406
- makeBundle (connect (top , oNext (current )));
405
+ makeBundle (oNext ( connect (top , oNext (current ) )));
407
406
}
408
407
409
- // revert direction
410
- base = base .getTwin ();
411
408
return rcand ;
412
409
}
413
410
@@ -430,7 +427,7 @@ public HalfEdge delaunay(ArrayList<KDSPoint> points) throws Exception {
430
427
sleep (1000 );
431
428
base = findLowerSupport (lleft , lright );
432
429
base .draw (scene , 0 , Color .black );
433
- sleep (5000 );
430
+ sleep (1000 );
434
431
boolean leftLower = lowerThan (lleft .getOrigin (), lright .getOrigin ());
435
432
HalfEdge lower ;
436
433
if (leftLower ) {
@@ -447,6 +444,8 @@ public HalfEdge delaunay(ArrayList<KDSPoint> points) throws Exception {
447
444
System .out .println ("ROUND TWO" );
448
445
}
449
446
++iteration ;
447
+ base .draw (scene , 0 , Color .BLACK );
448
+ sleep (1000 );
450
449
lcand = computeLcand ();
451
450
rcand = computeRcand ();
452
451
System .out .println (lcand .getTwin () == rcand || lcand == rcand );
0 commit comments