2
2
3
3
import ProGAL .geom2d .viewer .J2DScene ;
4
4
import dcel .DCEL ;
5
+ import dcel .Face ;
5
6
import dcel .HalfEdge ;
6
7
import kds .KDSPoint ;
7
8
import static utils .Helpers .*; // not very nice, but it's to avoid having to write Helpers.<func> everywhere
@@ -31,7 +32,7 @@ public ConvexDT(ArrayList<KDSPoint> points, ConvexShape shape, J2DScene scene) {
31
32
this .points = points ;
32
33
this .shape = shape ;
33
34
this .scene = scene ;
34
- this .dcel = new DCEL (scene );
35
+ this .dcel = new DCEL (scene , points );
35
36
}
36
37
37
38
public DCEL getDcel () {
@@ -49,12 +50,13 @@ public HalfEdge computeSmallDelaunay(ArrayList<KDSPoint> points) throws Exceptio
49
50
KDSPoint a = points .get (0 );
50
51
KDSPoint b = points .get (1 );
51
52
HalfEdge e1 = dcel .createEdge (a , b );
53
+ e1 .setFace (dcel .createFace (e1 ));
52
54
if (e1 .getOrigin ().getPoint (0 ).y () < e1 .getDestination ().getPoint (0 ).y ())
53
55
return e1 ;
54
56
return e1 .getTwin ();
55
57
} else if (points .size () == 3 ) {
56
58
// sort them, is it really needed though?
57
- // sort(points);
59
+ sort (points );
58
60
KDSPoint a = points .get (0 );
59
61
KDSPoint b = points .get (1 );
60
62
KDSPoint c = points .get (2 );
@@ -63,9 +65,15 @@ public HalfEdge computeSmallDelaunay(ArrayList<KDSPoint> points) throws Exceptio
63
65
HalfEdge e2 = dcel .createEdge (b , c );
64
66
// connect a -> b with b -> c and a <- b with b <- c
65
67
e1 .setNext (e2 );
68
+ e1 .setFace (dcel .createFace (e1 ));
66
69
e1 .getTwin ().setPrev (e2 .getTwin ());
70
+ e1 .getTwin ().setFace (dcel .createFace (e1 .getTwin ()));
71
+
67
72
e2 .setPrev (e1 );
73
+ e2 .setFace (e1 .getFace ());
68
74
e2 .getTwin ().setNext (e1 .getTwin ());
75
+ e2 .getTwin ().setFace (e1 .getTwin ().getFace ());
76
+
69
77
70
78
// don't create a triangle if they are collinear
71
79
if (leftOf (a , b , c ) || rightOf (a , b , c )) {
@@ -111,19 +119,19 @@ infCircleEnum.INSIDE && lessThan(rNext(right).getOrigin(), right.getOrigin())) {
111
119
} else {
112
120
// TODO I think it should move CW around left as the 'candidate' for lower support can't be on the right
113
121
// side of left when the lowest point in right is lower
114
- while (lPrev (left ) != null && shape .inInfCircle (lPrev (left ).getOrigin (), left .getOrigin (), right .getOrigin ()) ==
115
- infCircleEnum .INSIDE && lessThan (lPrev (left ).getOrigin (), left .getOrigin ())) {
116
- if (rPrev (left ) == null ) break ;
117
- left = lPrev (left );
122
+ while (rNext (left ) != null && shape .inInfCircle (rNext (left ).getOrigin (), left .getOrigin (), right .getOrigin ()) ==
123
+ infCircleEnum .INSIDE && lessThan (rNext (left ).getOrigin (), left .getOrigin ())) {
124
+ if (rNext (left ) == null ) break ;
125
+ left = rNext (left );
118
126
}
119
127
while (true ) {
120
128
if (shape .inInfCircle (left .getDestination (), left .getOrigin (), right .getOrigin ()) == infCircleEnum .INSIDE ) {
121
129
left = rPrev (left );
122
130
} else if (shape .inInfCircle (right .getDestination (), left .getOrigin (), right .getOrigin ()) == infCircleEnum .INSIDE ) {
123
131
right = rPrev (right );
124
132
} else {
125
- if (oNext (left ) == null ) return connect (left , right .getTwin ()). getTwin ( );
126
- return connect (oNext ( left ), right .getTwin ()). getTwin ( );
133
+ if (oNext (left ) == null ) return connect (right .getTwin (), left );
134
+ return connect (right .getTwin (), oNext ( left ) );
127
135
}
128
136
System .out .println ("Am I stuck in lowersupport2?" );
129
137
}
@@ -232,7 +240,7 @@ public HalfEdge computeLcand() throws Exception {
232
240
boolean foundLcand = false ;
233
241
lcand = rPrev (base );
234
242
lcand .draw (scene , 0 , Color .ORANGE );
235
- sleep (1000 );
243
+ // sleep(1000);
236
244
assert lcand != null ;
237
245
assert base != null ;
238
246
@@ -243,12 +251,12 @@ public HalfEdge computeLcand() throws Exception {
243
251
if (produceONext (lcand ) == null ) break ;
244
252
lcand = produceONext (lcand );
245
253
lcand .draw (scene , 0 , Color .ORANGE );
246
- sleep (1000 );
254
+ // sleep(1000);
247
255
}
248
256
if (isValid (lcand )) delete (oPrev (lcand ));
249
257
else lcand = oPrev (lcand );
250
258
lcand .draw (scene , 0 , Color .ORANGE );
251
- sleep (1000 );
259
+ // sleep(1000);
252
260
}
253
261
254
262
if (isValid (lcand )) {
@@ -297,9 +305,9 @@ public HalfEdge computeLcand() throws Exception {
297
305
break ;
298
306
}
299
307
lcand .draw (scene , 0 , Color .ORANGE );
300
- sleep (1000 );
308
+ // sleep(1000);
301
309
current .draw (scene , 0 , Color .GREEN );
302
- sleep (1000 );
310
+ // sleep(1000);
303
311
System .out .println ("Am I stuck in lcand?" );
304
312
}
305
313
} else {
@@ -424,10 +432,10 @@ public HalfEdge delaunay(ArrayList<KDSPoint> points) throws Exception {
424
432
//lleft.draw(scene, 0, Color.MAGENTA);
425
433
HalfEdge lright = delaunay (right );
426
434
//lright.draw(scene, 0, 0);
427
- sleep (1000 );
435
+ // sleep(1000);
428
436
base = findLowerSupport (lleft , lright );
429
437
base .draw (scene , 0 , Color .black );
430
- sleep (1000 );
438
+ // sleep(1000);
431
439
boolean leftLower = lowerThan (lleft .getOrigin (), lright .getOrigin ());
432
440
HalfEdge lower ;
433
441
if (leftLower ) {
@@ -440,20 +448,22 @@ public HalfEdge delaunay(ArrayList<KDSPoint> points) throws Exception {
440
448
// merge step
441
449
int iteration = 0 ;
442
450
while (true ) {
451
+ scene .repaint ();
452
+ sleep (100 );
443
453
if (iteration > 0 ) {
444
454
System .out .println ("ROUND TWO" );
445
455
}
446
456
++iteration ;
447
457
base .draw (scene , 0 , Color .BLACK );
448
- sleep (1000 );
458
+ // sleep(1000);
449
459
lcand = computeLcand ();
450
460
rcand = computeRcand ();
451
461
System .out .println (lcand .getTwin () == rcand || lcand == rcand );
452
462
453
463
if (isValid (lcand )) System .out .println ("lcand valid!" );
454
464
else System .out .println ("lcand invalid!" );
455
465
lcand .draw (scene , 0 , Color .MAGENTA );
456
- sleep (2000 );
466
+ // sleep(2000);
457
467
if (isValid (rcand )) System .out .println ("rcand valid!" );
458
468
else System .out .println ("rcand invalid!" );
459
469
rcand .draw (scene , 0 , Color .CYAN );
@@ -492,8 +502,14 @@ public HalfEdge delaunay(ArrayList<KDSPoint> points) throws Exception {
492
502
break ;
493
503
}
494
504
}
495
- else if (isValid (lcand )) {System .out .println ("2" ); base = connectLeft ();}
496
- else if (isValid (rcand )) {System .out .println ("3" ); base = connectRight ();}
505
+ else if (isValid (lcand )) {
506
+ System .out .println ("2" );
507
+ base = connectLeft ();
508
+ }
509
+ else if (isValid (rcand )) {
510
+ System .out .println ("3" );
511
+ base = connectRight ();
512
+ }
497
513
else if (shape .inInfCircle (rcand .getDestination (), base .getOrigin (), base .getDestination ()) == infCircleEnum .AFTER ) {
498
514
System .out .println ("4" );
499
515
while (shape .inInfCircle (lcand .getDestination (), lcand .getOrigin (), rcand .getDestination ()) == infCircleEnum .INSIDE ) {
0 commit comments