@@ -54,57 +54,54 @@ export default class Delaunator {
5454 minDist = d ;
5555 }
5656 }
57+ const i0x = coords [ 2 * i0 ] ;
58+ const i0y = coords [ 2 * i0 + 1 ] ;
5759
5860 minDist = Infinity ;
5961
6062 // find the point closest to the seed
6163 for ( let i = 0 ; i < n ; i ++ ) {
6264 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 ] ) ;
6466 if ( d < minDist && d > 0 ) {
6567 i1 = i ;
6668 minDist = d ;
6769 }
6870 }
71+ let i1x = coords [ 2 * i1 ] ;
72+ let i1y = coords [ 2 * i1 + 1 ] ;
6973
7074 let minRadius = Infinity ;
7175
7276 // find the third point which forms the smallest circumcircle with the first two
7377 for ( let i = 0 ; i < n ; i ++ ) {
7478 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 ] ) ;
8180 if ( r < minRadius ) {
8281 i2 = i ;
8382 minRadius = r ;
8483 }
8584 }
85+ let i2x = coords [ 2 * i2 ] ;
86+ let i2y = coords [ 2 * i2 + 1 ] ;
8687
8788 if ( minRadius === Infinity ) {
8889 throw new Error ( 'No Delaunay triangulation exists for this input.' ) ;
8990 }
9091
9192 // 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 ;
9797 i1 = i2 ;
98- i2 = tmp ;
98+ i1x = i2x ;
99+ i1y = i2y ;
100+ i2 = i ;
101+ i2x = x ;
102+ i2y = y ;
99103 }
100104
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-
108105 const center = circumcenter ( i0x , i0y , i1x , i1y , i2x , i2y ) ;
109106 this . _cx = center . x ;
110107 this . _cy = center . y ;
@@ -114,8 +111,7 @@ export default class Delaunator {
114111
115112 // initialize a hash table for storing edges of the advancing convex hull
116113 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 ) ;
119115
120116 // initialize a circular doubly-linked list that will hold an advancing convex hull
121117 let e = this . hull = insertNode ( coords , i0 ) ;
@@ -136,8 +132,8 @@ export default class Delaunator {
136132
137133 this . _addTriangle ( i0 , i1 , i2 , - 1 , - 1 , - 1 ) ;
138134
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 ) {
141137 const x = coords [ 2 * i ] ;
142138 const y = coords [ 2 * i + 1 ] ;
143139
@@ -147,9 +143,7 @@ export default class Delaunator {
147143 yp = y ;
148144
149145 // 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 ;
153147
154148 // find a visible edge on the convex hull using edge hash
155149 const startKey = this . _hashKey ( x , y ) ;
0 commit comments