MCPcopy Create free account
hub / github.com/plotly/plotly.js / tryCreateTri

Function tryCreateTri

src/traces/isosurface/convert.js:398–477  ·  view source on GitHub ↗
(style, xyzv, abc, min, max, nPass)

Source from the content-addressed store, hash-verified

396 var MAX_PASS = 3;
397
398 function tryCreateTri(style, xyzv, abc, min, max, nPass) {
399 if(!nPass) nPass = 1;
400
401 abc = [-1, -1, -1]; // Note: for the moment we override indices
402 // to run faster! But it is possible to comment this line
403 // to reduce the number of vertices.
404
405 var result = false;
406
407 var ok = [
408 inRange(xyzv[0][3], min, max),
409 inRange(xyzv[1][3], min, max),
410 inRange(xyzv[2][3], min, max)
411 ];
412
413 if(!ok[0] && !ok[1] && !ok[2]) {
414 return false;
415 }
416
417 var tryDrawTri = function(style, xyzv, abc) {
418 if( // we check here if the points are in `real` iso-min/max range
419 almostInFinalRange(xyzv[0][3]) &&
420 almostInFinalRange(xyzv[1][3]) &&
421 almostInFinalRange(xyzv[2][3])
422 ) {
423 drawTri(style, xyzv, abc);
424 return true;
425 } else if(nPass < MAX_PASS) {
426 return tryCreateTri(style, xyzv, abc, vMin, vMax, ++nPass); // i.e. second pass using actual vMin vMax bounds
427 }
428 return false;
429 };
430
431 if(ok[0] && ok[1] && ok[2]) {
432 return tryDrawTri(style, xyzv, abc) || result;
433 }
434
435 var interpolated = false;
436
437 [
438 [0, 1, 2],
439 [2, 0, 1],
440 [1, 2, 0]
441 ].forEach(function(e) {
442 if(ok[e[0]] && ok[e[1]] && !ok[e[2]]) {
443 var A = xyzv[e[0]];
444 var B = xyzv[e[1]];
445 var C = xyzv[e[2]];
446
447 var p1 = calcIntersection(C, A, min, max);
448 var p2 = calcIntersection(C, B, min, max);
449
450 result = tryDrawTri(style, [p2, p1, A], [-1, -1, abc[e[0]]]) || result;
451 result = tryDrawTri(style, [A, B, p2], [abc[e[0]], abc[e[1]], -1]) || result;
452
453 interpolated = true;
454 }
455 });

Callers 3

tryDrawTriFunction · 0.85
addRectFunction · 0.85
makeSectionFunction · 0.85

Calls 3

inRangeFunction · 0.85
tryDrawTriFunction · 0.85
calcIntersectionFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…