@@ -29,6 +29,16 @@ public class ConvexDT {
29
29
private J2DScene scene ;
30
30
private DCEL dcel ;
31
31
private ArrayList <infCircleEnum > illegalValues ;
32
+ private double t = 0 ;
33
+
34
+ public double getTime () {
35
+ return t ;
36
+ }
37
+
38
+ public void setTime (double t ) {
39
+ this .t = t ;
40
+ shape .setTime (t );
41
+ }
32
42
33
43
public ConvexDT () {
34
44
}
@@ -38,6 +48,7 @@ public ConvexDT(ArrayList<KDSPoint> points, ConvexShape shape, J2DScene scene) {
38
48
this .shape = shape ;
39
49
this .scene = scene ;
40
50
this .dcel = new DCEL (scene , points );
51
+ if (scene == null ) this .dcel .setVisualize (false );
41
52
illegalValues = new ArrayList <>();
42
53
illegalValues .add (infCircleEnum .INSIDE );
43
54
illegalValues .add (infCircleEnum .INVALID );
@@ -50,6 +61,9 @@ public DCEL getDcel() {
50
61
public void setScene (J2DScene scene ) {
51
62
this .scene = scene ;
52
63
}
64
+ public J2DScene getScene () {
65
+ return scene ;
66
+ }
53
67
54
68
public HalfEdge computeSmallDelaunay (ArrayList <KDSPoint > points ) throws Exception {
55
69
if (points .size () == 2 ) {
@@ -59,7 +73,7 @@ public HalfEdge computeSmallDelaunay(ArrayList<KDSPoint> points) throws Exceptio
59
73
KDSPoint b = points .get (1 );
60
74
HalfEdge e1 = dcel .createEdge (a , b );
61
75
e1 .setFace (dcel .createFace (e1 ));
62
- if (e1 .getOrigin ().getPoint (0 ).y () < e1 .getDestination ().getPoint (0 ).y ())
76
+ if (e1 .getOrigin ().getPoint (t ).y () < e1 .getDestination ().getPoint (t ).y ())
63
77
return e1 ;
64
78
return e1 .getTwin ();
65
79
} else if (points .size () == 3 ) {
@@ -140,8 +154,8 @@ else if (last != null) {
140
154
// connect(e2, e1);
141
155
// }
142
156
// find the lowest point (y-coordinate only)
143
- dcel .draw (scene );
144
- try {Thread .sleep (5000 );}catch (Exception ex ){}
157
+ //// dcel.draw(scene);
158
+ try {Thread .sleep (0 );}catch (Exception ex ){}
145
159
KDSPoint lowestPoint ;
146
160
if (a .getY () < b .getY ()) lowestPoint = a ;
147
161
else lowestPoint = b ;
@@ -169,9 +183,9 @@ infCircleEnum.INSIDE && lessThan(rNext(right).getOrigin(), right.getOrigin())) {
169
183
right = rNext (right );
170
184
}
171
185
while (true ) {
172
- right .draw (scene , 0 , Color .BLACK );
173
- left .draw (scene , 0 , Color .BLACK );
174
- try {Thread .sleep (100 );}catch (Exception ex ){}
186
+ //// right.draw(scene, 0, Color.BLACK);
187
+ //// left.draw(scene, 0, Color.BLACK);
188
+ try {Thread .sleep (0 );}catch (Exception ex ){}
175
189
if (shape .inInfCircle (right .getDestination (), left .getOrigin (), right .getOrigin ()) == infCircleEnum .INSIDE ) {
176
190
// see below
177
191
System .out .println ("right" );
@@ -197,10 +211,10 @@ infCircleEnum.INSIDE && lessThan(rNext(left).getOrigin(), left.getOrigin())) {
197
211
left = rNext (left );
198
212
}
199
213
while (true ) {
200
- right .draw (scene , 0 , Color .ORANGE );
201
- left .draw (scene , 0 , Color .ORANGE );
202
- try {Thread .sleep (100 );}catch (Exception ex ){}
203
- try {sleep (100 );} catch (InterruptedException e ) {}
214
+ //// right.draw(scene, 0, Color.ORANGE);
215
+ //// left.draw(scene, 0, Color.ORANGE);
216
+ try {Thread .sleep (0 );}catch (Exception ex ){}
217
+ try {sleep (0 );} catch (InterruptedException e ) {}
204
218
// if rNext.org is inside the inf circle with left.org and right.org on boundary, then it's a better candidate
205
219
if ((rNext (left ) != null && illegalValues .contains (shape .inInfCircle (rNext (left ).getOrigin (), left .getOrigin (), right .getOrigin ())))
206
220
&& illegalValues .contains (shape .inInfCircle (left .getDestination (), left .getOrigin (), right .getOrigin ()))) {
@@ -325,8 +339,8 @@ public HalfEdge computeLcand() throws Exception {
325
339
HalfEdge current = null , top = null , t = null ;
326
340
boolean foundLcand = false ;
327
341
lcand = rPrev (base );
328
- lcand .draw (scene , 0 , Color .ORANGE );
329
- sleep (100 );
342
+ //// lcand.draw(scene, 0, Color.ORANGE);
343
+ sleep (0 );
330
344
assert lcand != null ;
331
345
assert base != null ;
332
346
@@ -336,13 +350,13 @@ public HalfEdge computeLcand() throws Exception {
336
350
delete (oPrev (lcand ));
337
351
if (produceONext (lcand ) == null ) break ;
338
352
lcand = produceONext (lcand );
339
- lcand .draw (scene , 0 , Color .ORANGE );
340
- sleep (100 );
353
+ // lcand.draw(scene, 0, Color.ORANGE);
354
+ sleep (0 );
341
355
}
342
356
if (isValid (lcand )) delete (oPrev (lcand ));
343
357
else lcand = oPrev (lcand );
344
- lcand .draw (scene , 0 , Color .ORANGE );
345
- sleep (100 );
358
+ // lcand.draw(scene, 0, Color.ORANGE);
359
+ sleep (0 );
346
360
}
347
361
348
362
if (isValid (lcand )) {
@@ -390,10 +404,10 @@ public HalfEdge computeLcand() throws Exception {
390
404
foundLcand = true ;
391
405
break ;
392
406
}
393
- lcand .draw (scene , 0 , Color .ORANGE );
394
- sleep (100 );
395
- current .draw (scene , 0 , Color .YELLOW );
396
- sleep (100 );
407
+ // lcand.draw(scene, 0, Color.ORANGE);
408
+ sleep (0 );
409
+ // current.draw(scene, 0, Color.YELLOW);
410
+ sleep (0 );
397
411
System .out .println ("Am I stuck in lcand?" );
398
412
}
399
413
} else {
@@ -434,9 +448,9 @@ public HalfEdge computeRcand() throws Exception {
434
448
435
449
if (isValid (rcand )) {
436
450
current = oPrev (rcand );
437
- rcand .draw (scene , 0 , Color .green );
438
- current .draw (scene , 0 , Color .BLUE );
439
- sleep (100 );
451
+ // rcand.draw(scene, 0, Color.green);
452
+ // current.draw(scene, 0, Color.BLUE);
453
+ sleep (0 );
440
454
top = rcand ;
441
455
while (true ) {
442
456
assert rcand != null ;
@@ -501,6 +515,12 @@ public HalfEdge delaunay() throws Exception {
501
515
}
502
516
503
517
public HalfEdge delaunay (ArrayList <KDSPoint > points ) throws Exception {
518
+ // kind of a hack to get updated positions without changing too much code
519
+ for (KDSPoint p : points ) {
520
+ p .updatePosition (this .t );
521
+ }
522
+ Collections .sort (points );
523
+
504
524
if (points .size () < 4 ) return computeSmallDelaunay (points );
505
525
else {
506
526
int split = (int ) Math .floor (points .size () / 2 );
@@ -509,13 +529,13 @@ public HalfEdge delaunay(ArrayList<KDSPoint> points) throws Exception {
509
529
ArrayList <KDSPoint > right = new ArrayList <>(points .subList (split , points .size ()));
510
530
511
531
HalfEdge lleft = delaunay (left );
512
- lleft .draw (scene , 0 , Color .PINK );
532
+ // lleft.draw(scene, 0, Color.PINK);
513
533
HalfEdge lright = delaunay (right );
514
- lright .draw (scene , 0 , Color .PINK );
515
- //sleep(10000 );
534
+ // lright.draw(scene, 0, Color.PINK);
535
+ //sleep(0 );
516
536
base = findLowerSupport (lleft , lright );
517
- base .draw (scene , 0 , Color .black );
518
- //sleep(1000 );
537
+ // base.draw(scene, 0, Color.black);
538
+ //sleep(0 );
519
539
boolean leftLower = lowerThan (lleft .getOrigin (), lright .getOrigin ());
520
540
HalfEdge lower ;
521
541
if (leftLower ) {
@@ -529,41 +549,41 @@ public HalfEdge delaunay(ArrayList<KDSPoint> points) throws Exception {
529
549
// merge step
530
550
while (true ) {
531
551
boolean circleValid = true ;
532
- base .draw (scene , 0 , Color .BLACK );
533
- sleep (100 );
552
+ // base.draw(scene, 0, Color.BLACK);
553
+ sleep (0 );
534
554
lcand = computeLcand ();
535
555
rcand = computeRcand ();
536
556
//System.out.println(lcand.getTwin() == rcand || lcand == rcand);
537
557
538
558
if (isValid (lcand )) System .out .println ("lcand valid!" );
539
559
else System .out .println ("lcand invalid!" );
540
- lcand .draw (scene , 0 , Color .MAGENTA );
541
- sleep (100 );
560
+ // lcand.draw(scene, 0, Color.MAGENTA);
561
+ sleep (0 );
542
562
if (isValid (rcand )) System .out .println ("rcand valid!" );
543
563
else System .out .println ("rcand invalid!" );
544
- rcand .draw (scene , 0 , Color .CYAN );
545
- sleep (5000 );
564
+ // rcand.draw(scene, 0, Color.CYAN);
565
+ sleep (0 );
546
566
if (isValid (lcand ) && isValid (rcand )) {
547
567
System .out .println ("1" );
548
568
switch (shape .inCircle (base .getOrigin (), base .getDestination (), lcand .getDestination (), rcand .getDestination ())) {
549
569
case INSIDE :
550
570
System .out .println ("rcand.dest INSIDE" );
551
571
base = connectRight ();
552
- base .draw (scene , 0 , Color .BLACK );
553
- sleep (100 );
572
+ // base.draw(scene, 0, Color.BLACK);
573
+ sleep (0 );
554
574
break ;
555
575
case ON :
556
576
case ONBEFORE :
557
577
case ONAFTER :
558
578
System .out .println ("rcand.dest ON/ONBEFORE/ONAFTER" );
559
579
if (rightOf (lcand .getOrigin (), lcand .getDestination (), rcand .getDestination ())) {
560
580
base = connectRight ();
561
- base .draw (scene , 0 , Color .BLACK );
562
- sleep (100 );
581
+ // base.draw(scene, 0, Color.BLACK);
582
+ sleep (0 );
563
583
} else {
564
584
base = connectLeft ();
565
- base .draw (scene , 0 , Color .BLACK );
566
- sleep (100 );
585
+ // base.draw(scene, 0, Color.BLACK);
586
+ sleep (0 );
567
587
}
568
588
break ;
569
589
case INVALID :
@@ -573,8 +593,8 @@ public HalfEdge delaunay(ArrayList<KDSPoint> points) throws Exception {
573
593
default :
574
594
System .out .println ("rcand.dest OUTSIDE" );
575
595
base = connectLeft ();
576
- base .draw (scene , 0 , Color .BLACK );
577
- sleep (100 );
596
+ // base.draw(scene, 0, Color.BLACK);
597
+ sleep (0 );
578
598
break ;
579
599
}
580
600
}
@@ -586,7 +606,7 @@ else if (isValid(rcand)) {
586
606
System .out .println ("3" );
587
607
base = connectRight ();
588
608
}
589
- else if (shape .inInfCircle (rcand .getDestination (), base .getOrigin (), base .getDestination ()) == infCircleEnum .AFTER ) {
609
+ else if (shape .inInfCircle (lcand .getDestination (), base .getOrigin (), base .getDestination ()) == infCircleEnum .BEFORE ) {
590
610
System .out .println ("4" );
591
611
while (shape .inInfCircle (lcand .getDestination (), lcand .getOrigin (), rcand .getDestination ()) == infCircleEnum .INSIDE ) {
592
612
lcand = rPrev (lcand );
0 commit comments