@@ -102,18 +102,13 @@ function makePath(pi, loc, edgeflag, xtol, ytol) {
102
102
if ( cnt === 10000 ) {
103
103
Lib . log ( 'Infinite loop in contour?' ) ;
104
104
}
105
- var closedpath = equalPts ( pts [ 0 ] , pts [ pts . length - 1 ] , xtol , ytol ) ,
106
- totaldist = 0 ,
107
- distThresholdFactor = 0.2 * pi . smoothing ,
108
- alldists = [ ] ,
109
- cropstart = 0 ,
110
- distgroup ,
111
- cnt2 ,
112
- cnt3 ,
113
- newpt ,
114
- ptcnt ,
115
- ptavg ,
116
- thisdist ;
105
+ var closedpath = equalPts ( pts [ 0 ] , pts [ pts . length - 1 ] , xtol , ytol ) ;
106
+ var totaldist = 0 ;
107
+ var distThresholdFactor = 0.2 * pi . smoothing ;
108
+ var alldists = [ ] ;
109
+ var cropstart = 0 ;
110
+ var distgroup , cnt2 , cnt3 , newpt , ptcnt , ptavg , thisdist ,
111
+ i , j , edgepathi , edgepathj ;
117
112
118
113
/*
119
114
* Check for points that are too close together (<1/5 the average dist
@@ -198,42 +193,48 @@ function makePath(pi, loc, edgeflag, xtol, ytol) {
198
193
199
194
// edge path - does it start where an existing edge path ends, or vice versa?
200
195
var merged = false ;
201
- pi . edgepaths . forEach ( function ( edgepath , edgei ) {
202
- if ( ! merged && equalPts ( edgepath [ 0 ] , pts [ pts . length - 1 ] , xtol , ytol ) ) {
196
+ for ( i = 0 ; i < pi . edgepaths . length ; i ++ ) {
197
+ edgepathi = pi . edgepaths [ i ] ;
198
+ if ( ! merged && equalPts ( edgepathi [ 0 ] , pts [ pts . length - 1 ] , xtol , ytol ) ) {
203
199
pts . pop ( ) ;
204
200
merged = true ;
205
201
206
202
// now does it ALSO meet the end of another (or the same) path?
207
203
var doublemerged = false ;
208
- pi . edgepaths . forEach ( function ( edgepath2 , edgei2 ) {
209
- if ( ! doublemerged && equalPts (
210
- edgepath2 [ edgepath2 . length - 1 ] , pts [ 0 ] , xtol , ytol ) ) {
204
+ for ( j = 0 ; j < pi . edgepaths . length ; j ++ ) {
205
+ edgepathj = pi . edgepaths [ j ] ;
206
+ if ( equalPts ( edgepathj [ edgepathj . length - 1 ] , pts [ 0 ] , xtol , ytol ) ) {
211
207
doublemerged = true ;
212
- pts . splice ( 0 , 1 ) ;
213
- pi . edgepaths . splice ( edgei , 1 ) ;
214
- if ( edgei2 === edgei ) {
208
+ pts . shift ( ) ;
209
+ pi . edgepaths . splice ( i , 1 ) ;
210
+ if ( j === i ) {
215
211
// the path is now closed
216
- pi . paths . push ( pts . concat ( edgepath2 ) ) ;
212
+ pi . paths . push ( pts . concat ( edgepathj ) ) ;
217
213
}
218
214
else {
219
- if ( edgei2 > edgei ) edgei2 -- ;
220
- pi . edgepaths [ edgei2 ] =
221
- pi . edgepaths [ edgei2 ] . concat ( pts , edgepath2 ) ;
215
+ if ( j > i ) {
216
+ j -- ;
217
+ }
218
+ pi . edgepaths [ j ] =
219
+ pi . edgepaths [ j ] . concat ( pts , edgepathj ) ;
222
220
}
221
+ break ;
223
222
}
224
- } ) ;
223
+ }
225
224
if ( ! doublemerged ) {
226
- pi . edgepaths [ edgei ] = pts . concat ( edgepath ) ;
225
+ pi . edgepaths [ i ] = pts . concat ( edgepathi ) ;
227
226
}
228
227
}
229
- } ) ;
230
- pi . edgepaths . forEach ( function ( edgepath , edgei ) {
231
- if ( ! merged && equalPts ( edgepath [ edgepath . length - 1 ] , pts [ 0 ] , xtol , ytol ) ) {
232
- pts . splice ( 0 , 1 ) ;
233
- pi . edgepaths [ edgei ] = edgepath . concat ( pts ) ;
228
+ }
229
+ for ( i = 0 ; i < pi . edgepaths . length ; i ++ ) {
230
+ if ( merged ) break ;
231
+ edgepathi = pi . edgepaths [ i ] ;
232
+ if ( equalPts ( edgepathi [ edgepathi . length - 1 ] , pts [ 0 ] , xtol , ytol ) ) {
233
+ pts . shift ( ) ;
234
+ pi . edgepaths [ i ] = edgepathi . concat ( pts ) ;
234
235
merged = true ;
235
236
}
236
- } ) ;
237
+ }
237
238
238
239
if ( ! merged ) pi . edgepaths . push ( pts ) ;
239
240
}
0 commit comments