Skip to content

Commit c7312e6

Browse files
committed
update find_all_paths syntax
1 parent 44c1db9 commit c7312e6

File tree

1 file changed

+33
-32
lines changed

1 file changed

+33
-32
lines changed

src/traces/contour/find_all_paths.js

+33-32
Original file line numberDiff line numberDiff line change
@@ -102,18 +102,13 @@ function makePath(pi, loc, edgeflag, xtol, ytol) {
102102
if(cnt === 10000) {
103103
Lib.log('Infinite loop in contour?');
104104
}
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;
117112

118113
/*
119114
* Check for points that are too close together (<1/5 the average dist
@@ -198,42 +193,48 @@ function makePath(pi, loc, edgeflag, xtol, ytol) {
198193

199194
// edge path - does it start where an existing edge path ends, or vice versa?
200195
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)) {
203199
pts.pop();
204200
merged = true;
205201

206202
// now does it ALSO meet the end of another (or the same) path?
207203
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)) {
211207
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) {
215211
// the path is now closed
216-
pi.paths.push(pts.concat(edgepath2));
212+
pi.paths.push(pts.concat(edgepathj));
217213
}
218214
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);
222220
}
221+
break;
223222
}
224-
});
223+
}
225224
if(!doublemerged) {
226-
pi.edgepaths[edgei] = pts.concat(edgepath);
225+
pi.edgepaths[i] = pts.concat(edgepathi);
227226
}
228227
}
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);
234235
merged = true;
235236
}
236-
});
237+
}
237238

238239
if(!merged) pi.edgepaths.push(pts);
239240
}

0 commit comments

Comments
 (0)