-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathclose_boundaries.js
65 lines (58 loc) · 1.89 KB
/
close_boundaries.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/**
* Copyright 2012-2019, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';
module.exports = function(pathinfo, operation, perimeter, trace) {
// Abandon all hope, ye who enter here.
var i, v1, v2;
var pi0 = pathinfo[0];
var na = pi0.x.length;
var nb = pi0.y.length;
var z = pi0.z;
var contours = trace.contours;
var boundaryMax = -Infinity;
var boundaryMin = Infinity;
for(i = 0; i < nb; i++) {
boundaryMin = Math.min(boundaryMin, z[i][0]);
boundaryMin = Math.min(boundaryMin, z[i][na - 1]);
boundaryMax = Math.max(boundaryMax, z[i][0]);
boundaryMax = Math.max(boundaryMax, z[i][na - 1]);
}
for(i = 1; i < na - 1; i++) {
boundaryMin = Math.min(boundaryMin, z[0][i]);
boundaryMin = Math.min(boundaryMin, z[nb - 1][i]);
boundaryMax = Math.max(boundaryMax, z[0][i]);
boundaryMax = Math.max(boundaryMax, z[nb - 1][i]);
}
pi0.prefixBoundary = false;
switch(operation) {
case '>':
if(contours.value > boundaryMax) {
pi0.prefixBoundary = true;
}
break;
case '<':
if(contours.value < boundaryMin) {
pi0.prefixBoundary = true;
}
break;
case '[]':
v1 = Math.min.apply(null, contours.value);
v2 = Math.max.apply(null, contours.value);
if(v2 < boundaryMin || v1 > boundaryMax) {
pi0.prefixBoundary = true;
}
break;
case '][':
v1 = Math.min.apply(null, contours.value);
v2 = Math.max.apply(null, contours.value);
if(v1 < boundaryMin && v2 > boundaryMax) {
pi0.prefixBoundary = true;
}
break;
}
};