Skip to content

Commit a041e51

Browse files
committed
moved certain condition checks to convert step
1 parent 83060bc commit a041e51

File tree

3 files changed

+43
-40
lines changed

3 files changed

+43
-40
lines changed

src/traces/mesh3d/convert.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ var triangulate = require('delaunay-triangulate');
1414
var alphaShape = require('alpha-shape');
1515
var convexHull = require('convex-hull');
1616

17+
var isIndex = require('../../lib').isIndex;
1718
var parseColorScale = require('../../lib/gl_format_color').parseColorScale;
1819
var str2RgbaArray = require('../../lib/str2rgbarray');
1920
var zip3 = require('../../plots/gl3d/zip3');
@@ -91,12 +92,40 @@ function delaunayCells(delaunayaxis, positions) {
9192
return triangulate(b);
9293
}
9394

95+
// validate indices
96+
function hasValidIndices(list, numVertices) {
97+
var len = list.length;
98+
for(var i = 0; i < len; i++) {
99+
if(!isIndex(list[i], numVertices)) {
100+
return false;
101+
}
102+
}
103+
return true;
104+
}
105+
106+
// avoid pointing to an identical vertex twice
107+
function isTriangle(lists) {
108+
var len = lists[0].length;
109+
for(var i = 0; i < len; i++) {
110+
if(
111+
lists[0][i] === lists[1][i] ||
112+
lists[1][i] === lists[2][i] ||
113+
lists[2][i] === lists[0][i]
114+
) {
115+
return false;
116+
}
117+
}
118+
return true;
119+
}
120+
94121
proto.update = function(data) {
95122
var scene = this.scene;
96123
var layout = scene.fullSceneLayout;
97124

98125
this.data = data;
99126

127+
var numVertices = data.x.length;
128+
100129
var positions = zip3(
101130
toDataCoords(layout.xaxis, data.x, scene.dataScale[0], data.xcalendar),
102131
toDataCoords(layout.yaxis, data.y, scene.dataScale[1], data.ycalendar),
@@ -105,6 +134,18 @@ proto.update = function(data) {
105134

106135
var cells;
107136
if(data.i && data.j && data.k) {
137+
138+
if(
139+
data.i.length !== data.j.length ||
140+
data.j.length !== data.k.length ||
141+
!hasValidIndices(data.i, numVertices) ||
142+
!hasValidIndices(data.j, numVertices) ||
143+
!hasValidIndices(data.k, numVertices) ||
144+
!isTriangle([data.i, data.j, data.k])
145+
) {
146+
data.visible = false;
147+
return;
148+
}
108149
cells = zip3(
109150
toIndex(data.i),
110151
toIndex(data.j),

src/traces/mesh3d/defaults.js

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -48,45 +48,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
4848
traceOut.visible = false;
4949
return;
5050
}
51-
52-
// test for size of indices
53-
if(
54-
traceIn.i && Lib.isArrayOrTypedArray(traceIn.i) &&
55-
traceIn.j && Lib.isArrayOrTypedArray(traceIn.j) &&
56-
traceIn.k && Lib.isArrayOrTypedArray(traceIn.k)
57-
) {
58-
if(traceIn.k.length !== 0 && (
59-
traceIn.i.length !== traceIn.j.length ||
60-
traceIn.j.length !== traceIn.k.length)) {
61-
traceOut.visible = false;
62-
return;
63-
}
64-
}
65-
66-
var allIndices = readComponents(['i', 'j', 'k']);
67-
if(allIndices) {
68-
var numVertices = coords[0].length;
69-
allIndices.forEach(function(indices) {
70-
indices.forEach(function(index) {
71-
if(!Lib.isIndex(index, numVertices)) {
72-
traceOut.visible = false;
73-
return;
74-
}
75-
});
76-
});
77-
78-
var numFaces = allIndices[0].length;
79-
for(var q = 0; q < numFaces; q++) {
80-
if(
81-
allIndices[0][q] === allIndices[1][q] ||
82-
allIndices[0][q] === allIndices[2][q] ||
83-
allIndices[1][q] === allIndices[2][q]
84-
) {
85-
traceOut.visible = false;
86-
return;
87-
}
88-
}
89-
}
51+
readComponents(['i', 'j', 'k']);
9052

9153
var handleCalendarDefaults = Registry.getComponentMethod('calendars', 'handleTraceDefaults');
9254
handleCalendarDefaults(traceIn, traceOut, ['x', 'y', 'z'], layout);

test/jasmine/tests/mesh3d_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ describe('Test mesh3d', function() {
7676
expect(gd._fullData[0].visible).toBe(exp, msg);
7777
}
7878

79-
it('@gl mesh3d should be invisible when the indices are not integer', function(done) {
79+
it('@gl mesh3d should be visible when the indices are not integer', function(done) {
8080
Plotly.plot(gd, [{
8181
x: [0, 1, 0.5, 0.5],
8282
y: [0, 0.5, 1, 0.5],

0 commit comments

Comments
 (0)