@@ -54,57 +54,54 @@ export default class Delaunator {
54
54
minDist = d ;
55
55
}
56
56
}
57
+ const i0x = coords [ 2 * i0 ] ;
58
+ const i0y = coords [ 2 * i0 + 1 ] ;
57
59
58
60
minDist = Infinity ;
59
61
60
62
// find the point closest to the seed
61
63
for ( let i = 0 ; i < n ; i ++ ) {
62
64
if ( i === i0 ) continue ;
63
- const d = dist ( coords [ 2 * i0 ] , coords [ 2 * i0 + 1 ] , coords [ 2 * i ] , coords [ 2 * i + 1 ] ) ;
65
+ const d = dist ( i0x , i0y , coords [ 2 * i ] , coords [ 2 * i + 1 ] ) ;
64
66
if ( d < minDist && d > 0 ) {
65
67
i1 = i ;
66
68
minDist = d ;
67
69
}
68
70
}
71
+ let i1x = coords [ 2 * i1 ] ;
72
+ let i1y = coords [ 2 * i1 + 1 ] ;
69
73
70
74
let minRadius = Infinity ;
71
75
72
76
// find the third point which forms the smallest circumcircle with the first two
73
77
for ( let i = 0 ; i < n ; i ++ ) {
74
78
if ( i === i0 || i === i1 ) continue ;
75
-
76
- const r = circumradius (
77
- coords [ 2 * i0 ] , coords [ 2 * i0 + 1 ] ,
78
- coords [ 2 * i1 ] , coords [ 2 * i1 + 1 ] ,
79
- coords [ 2 * i ] , coords [ 2 * i + 1 ] ) ;
80
-
79
+ const r = circumradius ( i0x , i0y , i1x , i1y , coords [ 2 * i ] , coords [ 2 * i + 1 ] ) ;
81
80
if ( r < minRadius ) {
82
81
i2 = i ;
83
82
minRadius = r ;
84
83
}
85
84
}
85
+ let i2x = coords [ 2 * i2 ] ;
86
+ let i2y = coords [ 2 * i2 + 1 ] ;
86
87
87
88
if ( minRadius === Infinity ) {
88
89
throw new Error ( 'No Delaunay triangulation exists for this input.' ) ;
89
90
}
90
91
91
92
// swap the order of the seed points for counter-clockwise orientation
92
- if ( orient ( coords [ 2 * i0 ] , coords [ 2 * i0 + 1 ] ,
93
- coords [ 2 * i1 ] , coords [ 2 * i1 + 1 ] ,
94
- coords [ 2 * i2 ] , coords [ 2 * i2 + 1 ] ) ) {
95
-
96
- const tmp = i1 ;
93
+ if ( orient ( i0x , i0y , i1x , i1y , i2x , i2y ) ) {
94
+ const i = i1 ;
95
+ const x = i1x ;
96
+ const y = i1y ;
97
97
i1 = i2 ;
98
- i2 = tmp ;
98
+ i1x = i2x ;
99
+ i1y = i2y ;
100
+ i2 = i ;
101
+ i2x = x ;
102
+ i2y = y ;
99
103
}
100
104
101
- const i0x = coords [ 2 * i0 ] ;
102
- const i0y = coords [ 2 * i0 + 1 ] ;
103
- const i1x = coords [ 2 * i1 ] ;
104
- const i1y = coords [ 2 * i1 + 1 ] ;
105
- const i2x = coords [ 2 * i2 ] ;
106
- const i2y = coords [ 2 * i2 + 1 ] ;
107
-
108
105
const center = circumcenter ( i0x , i0y , i1x , i1y , i2x , i2y ) ;
109
106
this . _cx = center . x ;
110
107
this . _cy = center . y ;
@@ -114,8 +111,7 @@ export default class Delaunator {
114
111
115
112
// initialize a hash table for storing edges of the advancing convex hull
116
113
this . _hashSize = Math . ceil ( Math . sqrt ( n ) ) ;
117
- this . _hash = [ ] ;
118
- for ( let i = 0 ; i < this . _hashSize ; i ++ ) this . _hash [ i ] = null ;
114
+ this . _hash = new Array ( this . _hashSize ) ;
119
115
120
116
// initialize a circular doubly-linked list that will hold an advancing convex hull
121
117
let e = this . hull = insertNode ( coords , i0 ) ;
@@ -136,8 +132,8 @@ export default class Delaunator {
136
132
137
133
this . _addTriangle ( i0 , i1 , i2 , - 1 , - 1 , - 1 ) ;
138
134
139
- for ( let k = 0 , xp , yp ; k < ids . length ; k ++ ) {
140
- const i = ids [ k ] ;
135
+ let xp , yp ;
136
+ for ( const i of ids ) {
141
137
const x = coords [ 2 * i ] ;
142
138
const y = coords [ 2 * i + 1 ] ;
143
139
@@ -147,9 +143,7 @@ export default class Delaunator {
147
143
yp = y ;
148
144
149
145
// skip seed triangle points
150
- if ( ( x === i0x && y === i0y ) ||
151
- ( x === i1x && y === i1y ) ||
152
- ( x === i2x && y === i2y ) ) continue ;
146
+ if ( i === i0 || i === i1 || i === i2 ) continue ;
153
147
154
148
// find a visible edge on the convex hull using edge hash
155
149
const startKey = this . _hashKey ( x , y ) ;
0 commit comments