Skip to content

Commit ec502ee

Browse files
committed
improved jasmine tests and -0.49 > 0 round edge case
1 parent a9ab05f commit ec502ee

File tree

2 files changed

+44
-21
lines changed

2 files changed

+44
-21
lines changed

src/traces/mesh3d/convert.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ function delaunayCells(delaunayaxis, positions) {
9494
function hasValidIndices(list, numVertices) {
9595
var len = list.length;
9696
for(var i = 0; i < len; i++) {
97-
if(list[i] < 0 || list[i] >= numVertices) {
97+
if(list[i] <= -0.5 || list[i] >= numVertices - 0.5) { // Note: the indices would be rounded -0.49 is valid.
9898
return false;
9999
}
100100
}

test/jasmine/tests/mesh3d_test.js

+43-20
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,11 @@ describe('Test mesh3d', function() {
7777
}
7878

7979
function assertPositions(exp, msg) {
80-
expect(gd._fullLayout.scene._scene.glplot.objects[0].positions.length !== undefined).toBe(exp, msg);
80+
expect(gd._fullLayout.scene._scene.glplot.objects[0].positions.length).toBe(exp, msg);
8181
}
8282

8383
function assertCells(exp, msg) {
84-
expect(gd._fullLayout.scene._scene.glplot.objects[0].cells.length !== undefined).toBe(exp, msg);
84+
expect(gd._fullLayout.scene._scene.glplot.objects[0].cells.length).toBe(exp, msg);
8585
}
8686

8787
it('@gl mesh3d should be visible when the indices are not integer', function(done) {
@@ -98,10 +98,33 @@ describe('Test mesh3d', function() {
9898
assertVisibility(true, 'to be visible');
9999
})
100100
.then(function() {
101-
assertPositions(true, 'not to be false');
101+
assertPositions(4, 'to be OK positions');
102102
})
103103
.then(function() {
104-
assertCells(true, 'not to be false');
104+
assertCells(4, 'to be OK cells');
105+
})
106+
.catch(failTest)
107+
.then(done);
108+
});
109+
110+
it('@gl mesh3d should be visible when the indices could be rounded to be in vertex range', function(done) {
111+
Plotly.plot(gd, [{
112+
x: [0, 1, 0.5, 0.5],
113+
y: [0, 0.5, 1, 0.5],
114+
z: [0, 0.5, 0.5, 1],
115+
i: [-0.49, 0, 0, 1],
116+
j: [1, 1, 2, 2],
117+
k: [2, 3, 3, 3.49],
118+
type: 'mesh3d'
119+
}])
120+
.then(function() {
121+
assertVisibility(true, 'to be visible');
122+
})
123+
.then(function() {
124+
assertPositions(4, 'to be OK positions');
125+
})
126+
.then(function() {
127+
assertCells(4, 'to be OK cells');
105128
})
106129
.catch(failTest)
107130
.then(done);
@@ -121,10 +144,10 @@ describe('Test mesh3d', function() {
121144
assertVisibility(true, 'to be visible');
122145
})
123146
.then(function() {
124-
assertPositions(true, 'not to be false');
147+
assertPositions(0, 'to be OK positions');
125148
})
126149
.then(function() {
127-
assertCells(true, 'not to be false');
150+
assertCells(0, 'to be OK cells');
128151
})
129152
.catch(failTest)
130153
.then(done);
@@ -144,10 +167,10 @@ describe('Test mesh3d', function() {
144167
assertVisibility(true, 'to be visible');
145168
})
146169
.then(function() {
147-
assertPositions(true, 'not to be false');
170+
assertPositions(0, 'to be OK positions');
148171
})
149172
.then(function() {
150-
assertCells(true, 'not to be false');
173+
assertCells(0, 'to be OK cells');
151174
})
152175
.catch(failTest)
153176
.then(done);
@@ -167,10 +190,10 @@ describe('Test mesh3d', function() {
167190
assertVisibility(true, 'to be visible');
168191
})
169192
.then(function() {
170-
assertPositions(true, 'not to be false');
193+
assertPositions(0, 'to be OK positions');
171194
})
172195
.then(function() {
173-
assertCells(true, 'not to be false');
196+
assertCells(0, 'to be OK cells');
174197
})
175198
.catch(failTest)
176199
.then(done);
@@ -190,10 +213,10 @@ describe('Test mesh3d', function() {
190213
assertVisibility(true, 'to be visible');
191214
})
192215
.then(function() {
193-
assertPositions(true, 'not to be false');
216+
assertPositions(4, 'to be OK positions');
194217
})
195218
.then(function() {
196-
assertCells(true, 'not to be false');
219+
assertCells(4, 'to be OK cells');
197220
})
198221
.catch(failTest)
199222
.then(done);
@@ -212,10 +235,10 @@ describe('Test mesh3d', function() {
212235
assertVisibility(true, 'not to be visible');
213236
})
214237
.then(function() {
215-
assertPositions(true, 'not to be false');
238+
assertPositions(4, 'to be OK positions');
216239
})
217240
.then(function() {
218-
assertCells(true, 'not to be false');
241+
assertCells(4, 'to be OK cells');
219242
})
220243
.catch(failTest)
221244
.then(done);
@@ -235,10 +258,10 @@ describe('Test mesh3d', function() {
235258
assertVisibility(true, 'to be visible');
236259
})
237260
.then(function() {
238-
assertPositions(true, 'not to be false');
261+
assertPositions(4, 'to be OK positions');
239262
})
240263
.then(function() {
241-
assertCells(true, 'not to be false');
264+
assertCells(0, 'to be OK cells');
242265
})
243266
.catch(failTest)
244267
.then(done);
@@ -255,10 +278,10 @@ describe('Test mesh3d', function() {
255278
assertVisibility(true, 'to be visible');
256279
})
257280
.then(function() {
258-
assertPositions(true, 'not to be false');
281+
assertPositions(4, 'to be OK positions');
259282
})
260283
.then(function() {
261-
assertCells(true, 'not to be false');
284+
assertCells(3, 'to be OK cells');
262285
})
263286
.catch(failTest)
264287
.then(done);
@@ -275,10 +298,10 @@ describe('Test mesh3d', function() {
275298
assertVisibility(true, 'not to be visible');
276299
})
277300
.then(function() {
278-
assertPositions(true, 'not to be false');
301+
assertPositions(0, 'to be OK positions');
279302
})
280303
.then(function() {
281-
assertCells(true, 'not to be false');
304+
assertCells(0, 'to be OK cells');
282305
})
283306
.catch(failTest)
284307
.then(done);

0 commit comments

Comments
 (0)