Skip to content

Commit 86e7135

Browse files
authored
Merge pull request #2091 from plotly/contour-edge-bug
yet another contour algorithm bug fix
2 parents cad8e06 + c293cf7 commit 86e7135

File tree

3 files changed

+90
-31
lines changed

3 files changed

+90
-31
lines changed

src/traces/contour/find_all_paths.js

+30-31
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,41 +193,45 @@ 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-
pi.edgepaths[edgei2] =
220-
pi.edgepaths[edgei2].concat(pts, edgepath2);
215+
if(j > i) j--;
216+
pi.edgepaths[j] = edgepathj.concat(pts, edgepathi);
221217
}
218+
break;
222219
}
223-
});
220+
}
224221
if(!doublemerged) {
225-
pi.edgepaths[edgei] = pts.concat(edgepath);
222+
pi.edgepaths[i] = pts.concat(edgepathi);
226223
}
227224
}
228-
});
229-
pi.edgepaths.forEach(function(edgepath, edgei) {
230-
if(!merged && equalPts(edgepath[edgepath.length - 1], pts[0], xtol, ytol)) {
231-
pts.splice(0, 1);
232-
pi.edgepaths[edgei] = edgepath.concat(pts);
225+
}
226+
for(i = 0; i < pi.edgepaths.length; i++) {
227+
if(merged) break;
228+
edgepathi = pi.edgepaths[i];
229+
if(equalPts(edgepathi[edgepathi.length - 1], pts[0], xtol, ytol)) {
230+
pts.shift();
231+
pi.edgepaths[i] = edgepathi.concat(pts);
233232
merged = true;
234233
}
235-
});
234+
}
236235

237236
if(!merged) pi.edgepaths.push(pts);
238237
}
96.2 KB
Loading
+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{
2+
"data": [{
3+
"z": [
4+
[2.38,2.34,2.36,2.37,2.36,2.37,2.36,2.36,2.34,2.35,2.34,2.36,2.38,2.37,2.35,2.34,2.35,2.36,2.36,2.34,2.33,2.34,2.33,2.37],
5+
[2.38,2.35,2.37,2.38,2.35,2.35,2.36,2.38,2.34,2.35,2.35,2.35,2.38,2.36,2.35,2.35,2.34,2.35,2.35,2.33,2.34,2.34,2.33,2.36],
6+
[2.36,2.33,2.32,2.33,2.34,2.34,2.35,2.31,2.31,2.32,2.30,2.33,2.35,2.33,2.32,2.31,2.35,2.33,2.33,2.31,2.32,2.30,2.31,2.34],
7+
[2.36,2.34,2.32,2.31,2.32,2.34,2.35,2.33,2.31,2.34,2.33,2.33,2.35,2.33,2.32,2.32,2.35,2.33,2.33,2.33,2.33,2.30,2.32,2.34],
8+
[2.35,2.35,2.32,2.31,2.30,2.31,2.32,2.32,2.31,2.31,2.32,2.33,2.32,2.32,2.32,2.29,2.32,2.31,2.31,2.31,2.30,2.31,2.30,2.32],
9+
[2.34,2.33,2.31,2.35,2.31,2.33,2.34,2.34,2.32,2.31,2.32,2.33,2.33,2.32,2.33,2.33,2.33,2.33,2.32,2.32,2.32,2.33,2.33,2.32],
10+
[2.33,2.32,2.32,2.31,2.31,2.32,2.33,2.31,2.32,2.31,2.30,2.31,2.34,2.32,2.32,2.31,2.32,2.32,2.32,2.31,2.31,2.31,2.30,2.34],
11+
[2.34,2.32,2.33,2.33,2.32,2.32,2.32,2.31,2.32,2.30,2.32,2.33,2.33,2.32,2.32,2.32,2.32,2.32,2.33,2.32,2.32,2.31,2.32,2.32],
12+
[2.32,2.32,2.31,2.30,2.31,2.31,2.31,2.29,2.31,2.32,2.30,2.33,2.33,2.29,2.31,2.32,2.31,2.33,2.32,2.31,2.31,2.31,2.30,2.32],
13+
[2.33,2.33,2.32,2.33,2.33,2.33,2.32,2.32,2.32,2.32,2.30,2.32,2.31,2.33,2.32,2.33,2.32,2.33,2.34,2.31,2.32,2.31,2.31,2.32],
14+
[2.33,2.31,2.31,2.30,2.30,2.31,2.32,2.33,2.29,2.29,2.30,2.31,2.32,2.32,2.32,2.31,2.32,2.30,2.32,2.30,2.31,2.29,2.29,2.30],
15+
[2.32,2.31,2.32,2.32,2.31,2.32,2.33,2.33,2.31,2.31,2.32,2.33,2.33,2.32,2.33,2.33,2.30,2.32,2.31,2.30,2.30,2.31,2.31,2.31],
16+
[2.33,2.32,2.32,2.30,2.30,2.30,2.30,2.31,2.30,2.31,2.31,2.30,2.32,2.31,2.29,2.31,2.31,2.31,2.31,2.31,2.31,2.30,2.30,2.32],
17+
[2.33,2.33,2.32,2.32,2.30,2.33,2.31,2.31,2.32,2.32,2.32,2.32,2.34,2.31,2.32,2.32,2.32,2.33,2.32,2.31,2.31,2.31,2.31,2.32],
18+
[2.33,2.33,2.30,2.33,2.31,2.32,2.31,2.31,2.30,2.31,2.30,2.32,2.33,2.32,2.31,2.30,2.31,2.33,2.31,2.32,2.30,2.31,2.31,2.32],
19+
[2.33,2.33,2.31,2.32,2.32,2.33,2.33,2.32,2.32,2.34,2.33,2.33,2.33,2.34,2.32,2.31,2.31,2.32,2.32,2.32,2.30,2.32,2.32,2.32],
20+
[2.32,2.31,2.32,2.33,2.31,2.33,2.32,2.32,2.32,2.31,2.31,2.37,2.32,2.31,2.31,2.30,2.31,2.32,2.31,2.31,2.30,2.31,2.31,2.35],
21+
[2.33,2.32,2.32,2.31,2.34,2.35,2.32,2.33,2.33,2.32,2.33,2.34,2.33,2.33,2.32,2.32,2.33,2.34,2.32,2.32,2.31,2.31,2.32,2.33],
22+
[2.32,2.34,2.30,2.33,2.30,2.32,2.33,2.33,2.32,2.31,2.30,2.31,2.32,2.30,2.31,2.29,2.31,2.31,2.31,2.31,2.30,2.32,2.30,2.31],
23+
[2.32,2.32,2.32,2.32,2.32,2.33,2.34,2.34,2.32,2.32,2.32,2.32,2.34,2.30,2.31,2.34,2.32,2.33,2.32,2.30,2.31,2.34,2.31,2.32],
24+
[2.31,2.30,2.33,2.30,2.29,2.30,2.31,2.32,2.30,2.30,2.32,2.31,2.32,2.32,2.31,2.31,2.30,2.32,2.31,2.31,2.31,2.31,2.30,2.29],
25+
[2.32,2.32,2.31,2.31,2.31,2.34,2.32,2.32,2.33,2.30,2.32,2.33,2.32,2.32,2.31,2.31,2.31,2.32,2.29,2.32,2.31,2.31,2.31,2.32],
26+
[2.32,2.30,2.31,2.31,2.29,2.32,2.32,2.33,2.30,2.31,2.30,2.30,2.31,2.32,2.30,2.30,2.31,2.31,2.32,2.31,2.30,2.31,2.32,2.31],
27+
[2.32,2.31,2.32,2.34,2.32,2.32,2.32,2.32,2.32,2.32,2.32,2.34,2.34,2.32,2.32,2.34,2.31,2.30,2.33,2.31,2.34,2.31,2.33,2.31],
28+
[2.33,2.31,2.29,2.31,2.32,2.30,2.34,2.31,2.31,2.32,2.32,2.31,2.31,2.30,2.31,2.29,2.31,2.31,2.31,2.29,2.31,2.31,2.33,2.30],
29+
[2.33,2.30,2.31,2.31,2.31,2.32,2.35,2.33,2.32,2.31,2.31,2.31,2.32,2.32,2.31,2.32,2.31,2.33,2.31,2.33,2.33,2.33,2.32,2.33],
30+
[2.30,2.30,2.31,2.33,2.30,2.31,2.31,2.31,2.29,2.32,2.29,2.31,2.31,2.31,2.31,2.30,2.29,2.32,2.31,2.31,2.31,2.32,2.32,2.30],
31+
[2.32,2.31,2.31,2.31,2.32,2.33,2.32,2.34,2.30,2.32,2.33,2.31,2.33,2.32,2.31,2.32,2.32,2.32,2.32,2.30,2.32,2.32,2.32,2.32],
32+
[2.34,2.33,2.30,2.30,2.33,2.30,2.31,2.31,2.31,2.30,2.31,2.31,2.35,2.31,2.32,2.32,2.30,2.31,2.32,2.32,2.31,2.31,2.31,2.31],
33+
[2.35,2.32,2.30,2.32,2.31,2.32,2.33,2.34,2.34,2.31,2.33,2.32,2.35,2.36,2.31,2.34,2.33,2.33,2.32,2.33,2.32,2.32,2.33,2.34],
34+
[2.34,2.31,2.30,2.31,2.32,2.34,2.34,2.29,2.29,2.30,2.30,2.32,2.31,2.32,2.32,2.31,2.30,2.31,2.33,2.32,2.33,2.32,2.29,2.32],
35+
[2.33,2.34,2.33,2.33,2.32,2.34,2.34,2.33,2.32,2.33,2.33,2.33,2.33,2.32,2.33,2.33,2.31,2.33,2.33,2.32,2.33,2.34,2.32,2.31],
36+
[2.33,2.32,2.31,2.30,2.32,2.31,2.31,2.32,2.31,2.30,2.29,2.32,2.33,2.31,2.33,2.30,2.30,2.31,2.31,2.31,2.32,2.32,2.34,2.32],
37+
[2.32,2.32,2.31,2.32,2.32,2.32,2.35,2.33,2.33,2.31,2.32,2.34,2.32,2.32,2.36,2.33,2.33,2.33,2.32,2.34,2.36,2.32,2.34,2.32],
38+
[2.32,2.30,2.30,2.32,2.32,2.32,2.31,2.31,2.31,2.29,2.30,2.34,2.32,2.32,2.30,2.31,2.34,2.32,2.32,2.32,2.32,2.30,2.30,2.30],
39+
[2.32,2.30,2.33,2.33,2.34,2.32,2.32,2.31,2.32,2.31,2.33,2.32,2.34,2.33,2.31,2.33,2.33,2.32,2.32,2.31,2.33,2.31,2.31,2.32],
40+
[2.30,2.33,2.30,2.31,2.32,2.30,2.31,2.31,2.31,2.30,2.31,2.33,2.32,2.30,2.30,2.32,2.30,2.31,2.31,2.31,2.30,2.30,2.30,2.31],
41+
[2.34,2.32,2.33,2.34,2.33,2.33,2.33,2.32,2.32,2.32,2.33,2.34,2.32,2.32,2.32,2.31,2.34,2.32,2.31,2.31,2.32,2.31,2.31,2.33],
42+
[2.32,2.32,2.31,2.30,2.31,2.30,2.31,2.30,2.31,2.31,2.30,2.32,2.33,2.31,2.31,2.30,2.31,2.32,2.31,2.31,2.31,2.30,2.31,2.32],
43+
[2.33,2.32,2.33,2.32,2.32,2.33,2.32,2.32,2.33,2.31,2.33,2.32,2.32,2.32,2.33,2.31,2.32,2.34,2.33,2.31,2.33,2.31,2.34,2.34],
44+
[2.34,2.31,2.31,2.32,2.30,2.34,2.32,2.31,2.30,2.30,2.31,2.32,2.33,2.31,2.30,2.32,2.30,2.32,2.32,2.32,2.29,2.32,2.31,2.31],
45+
[2.33,2.33,2.32,2.34,2.34,2.33,2.32,2.31,2.32,2.33,2.33,2.31,2.33,2.32,2.32,2.36,2.31,2.33,2.31,2.32,2.31,2.32,2.33,2.31],
46+
[2.33,2.31,2.30,2.31,2.31,2.31,2.31,2.31,2.31,2.29,2.30,2.31,2.31,2.30,2.29,2.30,2.31,2.31,2.31,2.30,2.31,2.30,2.30,2.33],
47+
[2.32,2.31,2.33,2.29,2.30,2.32,2.31,2.32,2.31,2.30,2.32,2.33,2.32,2.32,2.32,2.33,2.31,2.32,2.32,2.32,2.32,2.32,2.30,2.32],
48+
[2.33,2.32,2.32,2.32,2.30,2.33,2.31,2.32,2.31,2.30,2.31,2.33,2.33,2.32,2.32,2.31,2.31,2.31,2.31,2.31,2.29,2.31,2.31,2.31],
49+
[2.33,2.33,2.33,2.32,2.31,2.33,2.33,2.32,2.34,2.33,2.34,2.34,2.33,2.33,2.31,2.32,2.31,2.33,2.34,2.31,2.32,2.32,2.32,2.33],
50+
[2.35,2.33,2.31,2.32,2.32,2.34,2.35,2.31,2.32,2.30,2.31,2.33,2.33,2.32,2.32,2.32,2.32,2.40,2.33,2.32,2.34,2.31,2.31,2.34],
51+
[2.35,2.33,2.33,2.32,2.33,2.34,2.34,2.32,2.33,2.32,2.33,2.34,2.36,2.33,2.33,2.34,2.34,2.34,2.34,2.34,2.34,2.32,2.34,2.35]],
52+
"type": "contour",
53+
"contours": {
54+
"start": 2.2,
55+
"end": 2.4,
56+
"size": 0.02
57+
}
58+
}],
59+
"layout": {"width": 400, "height": 600}
60+
}

0 commit comments

Comments
 (0)