Skip to content

Commit 2b54f14

Browse files
committed
pass 2 removed some extra checks
1 parent a041e51 commit 2b54f14

File tree

2 files changed

+34
-53
lines changed

2 files changed

+34
-53
lines changed

src/traces/mesh3d/convert.js

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

17-
var isIndex = require('../../lib').isIndex;
1817
var parseColorScale = require('../../lib/gl_format_color').parseColorScale;
1918
var str2RgbaArray = require('../../lib/str2rgbarray');
2019
var zip3 = require('../../plots/gl3d/zip3');
@@ -71,8 +70,8 @@ function toDataCoords(axis, coord, scale, calendar) {
7170
return b;
7271
}
7372

74-
// round indices if passed as floats
75-
function toIndex(a) {
73+
// Round indices if passed as floats
74+
function toRoundIndex(a) {
7675
var b = [];
7776
var len = a.length;
7877
for(var i = 0; i < len; i++) {
@@ -81,7 +80,6 @@ function toIndex(a) {
8180
return b;
8281
}
8382

84-
// create cells
8583
function delaunayCells(delaunayaxis, positions) {
8684
var d = ['x', 'y', 'z'].indexOf(delaunayaxis);
8785
var b = [];
@@ -92,26 +90,11 @@ function delaunayCells(delaunayaxis, positions) {
9290
return triangulate(b);
9391
}
9492

95-
// validate indices
93+
// Validate indices
9694
function hasValidIndices(list, numVertices) {
9795
var len = list.length;
9896
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-
) {
97+
if(list[i] < 0 || list[i] >= numVertices) {
11598
return false;
11699
}
117100
}
@@ -140,16 +123,14 @@ proto.update = function(data) {
140123
data.j.length !== data.k.length ||
141124
!hasValidIndices(data.i, numVertices) ||
142125
!hasValidIndices(data.j, numVertices) ||
143-
!hasValidIndices(data.k, numVertices) ||
144-
!isTriangle([data.i, data.j, data.k])
126+
!hasValidIndices(data.k, numVertices)
145127
) {
146-
data.visible = false;
147128
return;
148129
}
149130
cells = zip3(
150-
toIndex(data.i),
151-
toIndex(data.j),
152-
toIndex(data.k)
131+
toRoundIndex(data.i),
132+
toRoundIndex(data.j),
133+
toRoundIndex(data.k)
153134
);
154135
} else if(data.alphahull === 0) {
155136
cells = convexHull(positions);

test/jasmine/tests/mesh3d_test.js

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,18 @@ describe('Test mesh3d', function() {
8282
y: [0, 0.5, 1, 0.5],
8383
z: [0, 0.5, 0.5, 1],
8484
i: [0, 0, 0, 1.00001],
85-
j: [1, 1, 2, 2],
86-
k: [2, 3, 3, 2.99999],
85+
j: [1, 1, 2, 1.99999],
86+
k: [2, 3, 3, 3.00001],
8787
type: 'mesh3d'
8888
}])
8989
.then(function() {
90-
assertVisibility(false, 'not to be visible');
90+
assertVisibility(true, 'to be visible');
9191
})
9292
.catch(failTest)
9393
.then(done);
9494
});
9595

96-
it('@gl mesh3d should be invisible when the indices are equal or greater than the number of vertices', function(done) {
96+
it('@gl mesh3d should be visible when the indices are equal or greater than the number of vertices', function(done) {
9797
Plotly.plot(gd, [{
9898
x: [0, 1, 0.5, 0.5],
9999
y: [0, 0.5, 1, 0.5],
@@ -104,13 +104,13 @@ describe('Test mesh3d', function() {
104104
type: 'mesh3d'
105105
}])
106106
.then(function() {
107-
assertVisibility(false, 'not to be visible');
107+
assertVisibility(true, 'to be visible');
108108
})
109109
.catch(failTest)
110110
.then(done);
111111
});
112112

113-
it('@gl mesh3d should be invisible when the indices are negative', function(done) {
113+
it('@gl mesh3d should be visible when the indices are negative', function(done) {
114114
Plotly.plot(gd, [{
115115
x: [0, 1, 0.5, 0.5],
116116
y: [0, 0.5, 1, 0.5],
@@ -121,13 +121,13 @@ describe('Test mesh3d', function() {
121121
type: 'mesh3d'
122122
}])
123123
.then(function() {
124-
assertVisibility(false, 'not to be visible');
124+
assertVisibility(true, 'to be visible');
125125
})
126126
.catch(failTest)
127127
.then(done);
128128
});
129129

130-
it('@gl mesh3d should be invisible when the indices have different sizes', function(done) {
130+
it('@gl mesh3d should be visible when the indices have different sizes', function(done) {
131131
Plotly.plot(gd, [{
132132
x: [0, 1, 0.5, 0.5],
133133
y: [0, 0.5, 1, 0.5],
@@ -138,24 +138,7 @@ describe('Test mesh3d', function() {
138138
type: 'mesh3d'
139139
}])
140140
.then(function() {
141-
assertVisibility(false, 'not to be visible');
142-
})
143-
.catch(failTest)
144-
.then(done);
145-
});
146-
147-
it('@gl mesh3d should be invisible when the indices of a triangle point to identical vertex twice', function(done) {
148-
Plotly.plot(gd, [{
149-
x: [0, 1, 0.5, 0.5],
150-
y: [0, 0.5, 1, 0.5],
151-
z: [0, 0.5, 0.5, 1],
152-
i: [0, 0, 0, 1],
153-
j: [1, 1, 2, 3],
154-
k: [2, 3, 3, 3],
155-
type: 'mesh3d'
156-
}])
157-
.then(function() {
158-
assertVisibility(false, 'not to be visible');
141+
assertVisibility(true, 'to be visible');
159142
})
160143
.catch(failTest)
161144
.then(done);
@@ -222,6 +205,23 @@ describe('Test mesh3d', function() {
222205
.catch(failTest)
223206
.then(done);
224207
});
208+
209+
it('@gl mesh3d should be visible when values are passed in string format', function(done) {
210+
Plotly.plot(gd, [{
211+
x: ['0', '1', '0.5', '0.5'],
212+
y: ['0', '0.5', '1', '0.5'],
213+
z: ['0', '0.5', '0.5', '1'],
214+
i: ['0', '0', '0', '1'],
215+
j: ['1', '1', '2', '2'],
216+
k: ['2', '3', '3', '3'],
217+
type: 'mesh3d'
218+
}]).then(function() {
219+
assertVisibility(true, 'not to be visible');
220+
})
221+
.catch(failTest)
222+
.then(done);
223+
});
224+
225225
});
226226

227227
});

0 commit comments

Comments
 (0)