Skip to content

Commit be99193

Browse files
committed
fixes for parametric cases e.g. torus
1 parent b8047c3 commit be99193

File tree

3 files changed

+36
-27
lines changed

3 files changed

+36
-27
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
"gl-select-box": "^1.0.2",
8585
"gl-spikes2d": "^1.0.1",
8686
"gl-streamtube3d": "^1.1.1",
87-
"gl-surface3d": "git://github.com/gl-vis/gl-surface3d.git#359ba6528379f412727cb2ac35edfd4c288f8cb9",
87+
"gl-surface3d": "git://github.com/gl-vis/gl-surface3d.git#0d9201dfdc3bee7c4157e4602357d28f75ba2b00",
8888
"gl-text": "^1.1.6",
8989
"glslify": "^6.3.1",
9090
"has-hover": "^1.0.1",

src/traces/surface/convert.js

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,7 @@ function arrayLCM(A) {
218218
}
219219

220220
proto.calcXnums = function(xlen) {
221-
var maxDist = Math.abs(
222-
this.getXat(0, 0) -
223-
this.getXat(xlen - 1, 0)
224-
);
221+
225222
var nums = [];
226223
for(var i = 1; i < xlen; i++) {
227224
var a = this.getXat(i - 1, 0);
@@ -230,21 +227,30 @@ proto.calcXnums = function(xlen) {
230227
if(b !== a &&
231228
a !== undefined && a !== null &&
232229
b !== undefined && b !== null) {
233-
nums[i - 1] = Math.round(
234-
maxDist / Math.abs(b - a)
235-
);
230+
nums[i - 1] = Math.abs(b - a);
236231
} else {
232+
nums[i - 1] = 0;
233+
}
234+
}
235+
236+
var totalDist = 0;
237+
for(var i = 1; i < xlen; i++) {
238+
totalDist += nums[i - 1];
239+
}
240+
241+
for(var i = 1; i < xlen; i++) {
242+
if(nums[i - 1] === 0) {
237243
nums[i - 1] = 1;
244+
} else {
245+
nums[i - 1] = Math.round(totalDist);
238246
}
239247
}
248+
240249
return nums;
241250
};
242251

243252
proto.calcYnums = function(ylen) {
244-
var maxDist = Math.abs(
245-
this.getYat(0, 0) -
246-
this.getYat(0, ylen - 1)
247-
);
253+
248254
var nums = [];
249255
for(var i = 1; i < ylen; i++) {
250256
var a = this.getYat(0, i - 1);
@@ -253,13 +259,25 @@ proto.calcYnums = function(ylen) {
253259
if(b !== a &&
254260
a !== undefined && a !== null &&
255261
b !== undefined && b !== null) {
256-
nums[i - 1] = Math.round(
257-
maxDist / Math.abs(b - a)
258-
);
262+
nums[i - 1] = Math.abs(b - a);
259263
} else {
264+
nums[i - 1] = 0;
265+
}
266+
}
267+
268+
var totalDist = 0;
269+
for(var i = 1; i < ylen; i++) {
270+
totalDist += nums[i - 1];
271+
}
272+
273+
for(var i = 1; i < ylen; i++) {
274+
if(nums[i - 1] === 0) {
260275
nums[i - 1] = 1;
276+
} else {
277+
nums[i - 1] = Math.round(totalDist);
261278
}
262279
}
280+
263281
return nums;
264282
};
265283

@@ -269,21 +287,16 @@ var MIN_RESOLUTION = highlyComposites[9];
269287
var MAX_RESOLUTION = highlyComposites[13];
270288

271289
proto.estimateScale = function(resSrc, axis) {
272-
// console.log("axis=", axis);
273-
// console.log("resSrc=", resSrc);
274-
275290
var nums = (axis === 0) ?
276291
this.calcXnums(resSrc) :
277292
this.calcYnums(resSrc);
278293

279-
// console.log("nums=", nums);
280-
281294
var resDst = 1 + arrayLCM(nums);
282295

283-
// console.log("BEFORE: resDst=", resDst);
284296
while(resDst < MIN_RESOLUTION) {
285297
resDst *= 2;
286298
}
299+
287300
while(resDst > MAX_RESOLUTION) {
288301
resDst--;
289302
resDst /= smallestDivisor(resDst);
@@ -294,12 +307,8 @@ proto.estimateScale = function(resSrc, axis) {
294307
resDst = MAX_RESOLUTION; // option 2: use max resolution
295308
}
296309
}
297-
// console.log("AFTER: resDst=", resDst);
298310

299311
var scale = Math.round(resDst / resSrc);
300-
301-
// console.log("scale=", resDst, "/", resSrc, "=", scale);
302-
303312
return (scale > 1) ? scale : 1;
304313
};
305314

0 commit comments

Comments
 (0)