1
1
package convex_dt ;
2
2
3
+ import ProGAL .dataStructures .SortToolPoint2dAroundOrigo ;
3
4
import ProGAL .geom2d .viewer .J2DScene ;
4
5
import convex_dt .shapes .ConvexShape ;
5
6
import dcel .DCEL ;
6
7
import dcel .HalfEdge ;
7
8
import kds .KDSPoint ;
9
+ import utils .Helpers ;
10
+
8
11
import static utils .Helpers .*; // not very nice, but it's to avoid having to write Helpers.<func> everywhere
9
12
import static convex_dt .shapes .ConvexShape .*;
10
13
import static java .lang .Thread .sleep ;
11
14
import static java .util .Collections .sort ;
12
15
13
16
import java .awt .*;
14
17
import java .util .ArrayList ;
18
+ import java .util .Collections ;
15
19
16
20
/**
17
21
* Created by cvium on 29-11-2016.
@@ -55,32 +59,74 @@ public HalfEdge computeSmallDelaunay(ArrayList<KDSPoint> points) throws Exceptio
55
59
return e1 ;
56
60
return e1 .getTwin ();
57
61
} else if (points .size () == 3 ) {
58
- // sort them, is it really needed though?
59
- sort (points );
60
- KDSPoint a = points .get (0 );
61
- KDSPoint b = points .get (1 );
62
- KDSPoint c = points .get (2 );
62
+ // sort them in ccw order
63
+ ArrayList < KDSPoint > sorted = Helpers . sortCCW (points );
64
+ KDSPoint a = sorted .get (0 );
65
+ KDSPoint b = sorted .get (1 );
66
+ KDSPoint c = sorted .get (2 );
63
67
64
- HalfEdge e1 = dcel .createEdge (a , b );
65
- HalfEdge e2 = dcel .createEdge (b , c );
66
- // connect a -> b with b -> c and a <- b with b <- c
67
- e1 .setNext (e2 );
68
- e1 .setFace (dcel .createFace (e1 ));
69
- e1 .getTwin ().setPrev (e2 .getTwin ());
70
- e1 .getTwin ().setFace (dcel .createFace (e1 .getTwin ()));
68
+ HalfEdge last = null ;
69
+
70
+ if (shape .inInfCircle (c , a , b ) != infCircleEnum .INSIDE || shape .inInfCircle (c , a , b ) != infCircleEnum .INSIDE ) {
71
+ last = dcel .createEdge (a , b );
72
+ last .setFace (dcel .createFace (last ));
73
+ }
71
74
72
- e2 .setPrev (e1 );
73
- e2 .setFace (e1 .getFace ());
74
- e2 .getTwin ().setNext (e1 .getTwin ());
75
- e2 .getTwin ().setFace (e1 .getTwin ().getFace ());
75
+ // EVER HEARD OF DRY CODE????? ME NEITHER
76
+ if (shape .inInfCircle (a , b , c ) != infCircleEnum .INSIDE || shape .inInfCircle (a , c , b ) != infCircleEnum .INSIDE ) {
77
+ HalfEdge current = dcel .createEdge (b , c );
78
+ if (last != null ) {
79
+ last .setNext (current );
80
+ last .getTwin ().setPrev (current .getTwin ());
81
+ last .getTwin ().setFace (dcel .createFace (last .getTwin ()));
82
+
83
+ current .setPrev (last );
84
+ current .setFace (last .getFace ());
85
+ current .getTwin ().setNext (last .getTwin ());
86
+ current .getTwin ().setFace (last .getTwin ().getFace ());
87
+ }
88
+ last = current ;
89
+ }
90
+
91
+ if (shape .inInfCircle (b , c , a ) != infCircleEnum .INSIDE || shape .inInfCircle (b , a , c ) != infCircleEnum .INSIDE ) {
92
+ // last should NEVER be null but intellij is a bitch and I hate warnings
93
+ HalfEdge current = dcel .createEdge (c , a );
94
+ if (last != null && last .getPrev () != null ) {
95
+ connect (last , last .getPrev ());
96
+ }
97
+ else if (last != null ) {
76
98
99
+ last .setNext (current );
100
+ last .getTwin ().setPrev (current .getTwin ());
101
+ last .getTwin ().setFace (dcel .createFace (last .getTwin ()));
77
102
78
- // don't create a triangle if they are collinear
79
- if ( leftOf ( a , b , c ) || rightOf ( a , b , c )) {
80
- // connect and create a triangle
81
- System . out . println ( "Creating triangle!" );
82
- connect ( e2 , e1 );
103
+ current . setPrev ( last );
104
+ current . setFace ( last . getFace ());
105
+ current . getTwin (). setNext ( last . getTwin ());
106
+ current . getTwin (). setFace ( last . getTwin (). getFace () );
107
+ }
83
108
}
109
+
110
+ // HalfEdge e1 = dcel.createEdge(a, b);
111
+ // HalfEdge e2 = dcel.createEdge(b, c);
112
+ // // connect a -> b with b -> c and a <- b with b <- c
113
+ // e1.setNext(e2);
114
+ // e1.setFace(dcel.createFace(e1));
115
+ // e1.getTwin().setPrev(e2.getTwin());
116
+ // e1.getTwin().setFace(dcel.createFace(e1.getTwin()));
117
+ //
118
+ // e2.setPrev(e1);
119
+ // e2.setFace(e1.getFace());
120
+ // e2.getTwin().setNext(e1.getTwin());
121
+ // e2.getTwin().setFace(e1.getTwin().getFace());
122
+
123
+
124
+ // // don't create a triangle if they are collinear
125
+ // if (leftOf(a, b, c) || rightOf(a, b, c)) {
126
+ // // connect and create a triangle
127
+ // System.out.println("Creating triangle!");
128
+ // connect(e2, e1);
129
+ // }
84
130
// find the lowest point (y-coordinate only)
85
131
KDSPoint lowestPoint ;
86
132
if (a .getY () < b .getY ()) lowestPoint = a ;
@@ -89,7 +135,7 @@ public HalfEdge computeSmallDelaunay(ArrayList<KDSPoint> points) throws Exceptio
89
135
90
136
// find the ccw edge incident to lowest point
91
137
HalfEdge candidateEdge = lowestPoint .getIncidentEdge ();
92
- if (!isCCW (candidateEdge .getPrev ().getOrigin (), candidateEdge .getOrigin (), candidateEdge .getDestination ()))
138
+ if (candidateEdge . getPrev () != null && !isCCW (candidateEdge .getPrev ().getOrigin (), candidateEdge .getOrigin (), candidateEdge .getDestination ()))
93
139
candidateEdge = candidateEdge .getTwin ().getNext ();
94
140
return candidateEdge ;
95
141
} else {
@@ -456,7 +502,8 @@ public HalfEdge delaunay(ArrayList<KDSPoint> points) throws Exception {
456
502
if (lleft .getOrigin () == base .getDestination ()) lower = base .getTwin ();
457
503
else lower = lleft ;
458
504
} else {
459
- lower = rNext (lright );
505
+ if (rNext (lright ) == null ) lower = lright ;
506
+ else lower = rNext (lright );
460
507
}
461
508
462
509
// merge step
0 commit comments