Skip to content

Commit a149b31

Browse files
committed
drysdale algorithm for circle works!
1 parent 1847f05 commit a149b31

File tree

6 files changed

+452
-214
lines changed

6 files changed

+452
-214
lines changed

.idea/workspace.xml

Lines changed: 213 additions & 150 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/java/convex_dt/ConvexDT.java

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import ProGAL.geom2d.viewer.J2DScene;
44
import dcel.DCEL;
5+
import dcel.Face;
56
import dcel.HalfEdge;
67
import kds.KDSPoint;
78
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) {
3132
this.points = points;
3233
this.shape = shape;
3334
this.scene = scene;
34-
this.dcel = new DCEL(scene);
35+
this.dcel = new DCEL(scene, points);
3536
}
3637

3738
public DCEL getDcel() {
@@ -49,12 +50,13 @@ public HalfEdge computeSmallDelaunay(ArrayList<KDSPoint> points) throws Exceptio
4950
KDSPoint a = points.get(0);
5051
KDSPoint b = points.get(1);
5152
HalfEdge e1 = dcel.createEdge(a, b);
53+
e1.setFace(dcel.createFace(e1));
5254
if (e1.getOrigin().getPoint(0).y() < e1.getDestination().getPoint(0).y())
5355
return e1;
5456
return e1.getTwin();
5557
} else if (points.size() == 3) {
5658
// sort them, is it really needed though?
57-
// sort(points);
59+
sort(points);
5860
KDSPoint a = points.get(0);
5961
KDSPoint b = points.get(1);
6062
KDSPoint c = points.get(2);
@@ -63,9 +65,15 @@ public HalfEdge computeSmallDelaunay(ArrayList<KDSPoint> points) throws Exceptio
6365
HalfEdge e2 = dcel.createEdge(b, c);
6466
// connect a -> b with b -> c and a <- b with b <- c
6567
e1.setNext(e2);
68+
e1.setFace(dcel.createFace(e1));
6669
e1.getTwin().setPrev(e2.getTwin());
70+
e1.getTwin().setFace(dcel.createFace(e1.getTwin()));
71+
6772
e2.setPrev(e1);
73+
e2.setFace(e1.getFace());
6874
e2.getTwin().setNext(e1.getTwin());
75+
e2.getTwin().setFace(e1.getTwin().getFace());
76+
6977

7078
// don't create a triangle if they are collinear
7179
if (leftOf(a, b, c) || rightOf(a, b, c)) {
@@ -111,19 +119,19 @@ infCircleEnum.INSIDE && lessThan(rNext(right).getOrigin(), right.getOrigin())) {
111119
} else {
112120
// TODO I think it should move CW around left as the 'candidate' for lower support can't be on the right
113121
// 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);
118126
}
119127
while (true) {
120128
if (shape.inInfCircle(left.getDestination(), left.getOrigin(), right.getOrigin()) == infCircleEnum.INSIDE) {
121129
left = rPrev(left);
122130
} else if (shape.inInfCircle(right.getDestination(), left.getOrigin(), right.getOrigin()) == infCircleEnum.INSIDE) {
123131
right = rPrev(right);
124132
} 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));
127135
}
128136
System.out.println("Am I stuck in lowersupport2?");
129137
}
@@ -232,7 +240,7 @@ public HalfEdge computeLcand() throws Exception {
232240
boolean foundLcand = false;
233241
lcand = rPrev(base);
234242
lcand.draw(scene, 0, Color.ORANGE);
235-
sleep(1000);
243+
//sleep(1000);
236244
assert lcand != null;
237245
assert base != null;
238246

@@ -243,12 +251,12 @@ public HalfEdge computeLcand() throws Exception {
243251
if (produceONext(lcand) == null) break;
244252
lcand = produceONext(lcand);
245253
lcand.draw(scene, 0, Color.ORANGE);
246-
sleep(1000);
254+
//sleep(1000);
247255
}
248256
if (isValid(lcand)) delete(oPrev(lcand));
249257
else lcand = oPrev(lcand);
250258
lcand.draw(scene, 0, Color.ORANGE);
251-
sleep(1000);
259+
//sleep(1000);
252260
}
253261

254262
if (isValid(lcand)) {
@@ -297,9 +305,9 @@ public HalfEdge computeLcand() throws Exception {
297305
break;
298306
}
299307
lcand.draw(scene, 0, Color.ORANGE);
300-
sleep(1000);
308+
//sleep(1000);
301309
current.draw(scene, 0, Color.GREEN);
302-
sleep(1000);
310+
//sleep(1000);
303311
System.out.println("Am I stuck in lcand?");
304312
}
305313
} else {
@@ -424,10 +432,10 @@ public HalfEdge delaunay(ArrayList<KDSPoint> points) throws Exception {
424432
//lleft.draw(scene, 0, Color.MAGENTA);
425433
HalfEdge lright = delaunay(right);
426434
//lright.draw(scene, 0, 0);
427-
sleep(1000);
435+
//sleep(1000);
428436
base = findLowerSupport(lleft, lright);
429437
base.draw(scene, 0, Color.black);
430-
sleep(1000);
438+
//sleep(1000);
431439
boolean leftLower = lowerThan(lleft.getOrigin(), lright.getOrigin());
432440
HalfEdge lower;
433441
if (leftLower) {
@@ -440,20 +448,22 @@ public HalfEdge delaunay(ArrayList<KDSPoint> points) throws Exception {
440448
// merge step
441449
int iteration = 0;
442450
while (true) {
451+
scene.repaint();
452+
sleep(100);
443453
if (iteration > 0) {
444454
System.out.println("ROUND TWO");
445455
}
446456
++iteration;
447457
base.draw(scene, 0, Color.BLACK);
448-
sleep(1000);
458+
//sleep(1000);
449459
lcand = computeLcand();
450460
rcand = computeRcand();
451461
System.out.println(lcand.getTwin() == rcand || lcand == rcand);
452462

453463
if (isValid(lcand)) System.out.println("lcand valid!");
454464
else System.out.println("lcand invalid!");
455465
lcand.draw(scene, 0, Color.MAGENTA);
456-
sleep(2000);
466+
//sleep(2000);
457467
if (isValid(rcand)) System.out.println("rcand valid!");
458468
else System.out.println("rcand invalid!");
459469
rcand.draw(scene, 0, Color.CYAN);
@@ -492,8 +502,14 @@ public HalfEdge delaunay(ArrayList<KDSPoint> points) throws Exception {
492502
break;
493503
}
494504
}
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+
}
497513
else if (shape.inInfCircle(rcand.getDestination(), base.getOrigin(), base.getDestination()) == infCircleEnum.AFTER) {
498514
System.out.println("4");
499515
while (shape.inInfCircle(lcand.getDestination(), lcand.getOrigin(), rcand.getDestination()) == infCircleEnum.INSIDE) {

src/main/java/convex_dt/run.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import dcel.HalfEdge;
55
import kds.KDSPoint;
66

7+
import java.awt.*;
78
import java.util.ArrayList;
89
import java.util.Random;
910

@@ -32,13 +33,24 @@ public static void main(String[] args) throws Exception {
3233
points.add(new KDSPoint(new double[]{2}, new double[]{0.5}));
3334
points.add(new KDSPoint(new double[]{2.5}, new double[]{0.8}));
3435
points.add(new KDSPoint(new double[]{2.6}, new double[]{0.3}));
35-
} else if (true){
36+
} else if (false){
3637
points.add(new KDSPoint(new double[]{0}, new double[]{1}));
3738
points.add(new KDSPoint(new double[]{0.3}, new double[]{0.7}));
3839
points.add(new KDSPoint(new double[]{0.5}, new double[]{1.1}));
3940
points.add(new KDSPoint(new double[]{1}, new double[]{0.2}));
4041
points.add(new KDSPoint(new double[]{1.2}, new double[]{0.5}));
4142
points.add(new KDSPoint(new double[]{1.4}, new double[]{0.22}));
43+
} else if (true) {
44+
points.add(new KDSPoint(new double[]{0}, new double[]{0.5}));
45+
points.add(new KDSPoint(new double[]{0.2}, new double[]{0.55}));
46+
points.add(new KDSPoint(new double[]{0.5}, new double[]{0.2}));
47+
points.add(new KDSPoint(new double[]{0.55}, new double[]{0}));
48+
points.add(new KDSPoint(new double[]{0.62}, new double[]{0.21}));
49+
points.add(new KDSPoint(new double[]{0.67}, new double[]{-0.01}));
50+
points.add(new KDSPoint(new double[]{0.75}, new double[]{0.35}));
51+
points.add(new KDSPoint(new double[]{0.8}, new double[]{0.6}));
52+
points.add(new KDSPoint(new double[]{0.85}, new double[]{-0.2}));
53+
points.add(new KDSPoint(new double[]{0.9}, new double[]{0.05}));
4254
}
4355

4456
else{
@@ -73,10 +85,16 @@ public static void main(String[] args) throws Exception {
7385
System.out.println("Printing DCEL!");
7486
scene.removeAllShapes();
7587
scene.repaint();
76-
sleep(1000);
88+
sleep(500);
7789
for (KDSPoint p : points) {
7890
p.draw(scene, 0);
7991
}
92+
for (HalfEdge e : dt.getDcel().getEdges()) {
93+
e.draw(scene, 0, Color.CYAN);
94+
}
95+
System.out.println("Faces: " + dt.getDcel().getFaces().size());
8096
dt.getDcel().draw(scene);
97+
System.out.println("DONE");
98+
//String.format("Faces: %1$s", dt.getDcel().getFaces().size()));
8199
}
82100
}

0 commit comments

Comments
 (0)