Skip to content

Commit 4eb6d1e

Browse files
committedJan 1, 2019
Tests
1 parent 9029745 commit 4eb6d1e

File tree

2 files changed

+155
-30
lines changed

2 files changed

+155
-30
lines changed
 

‎Specs/Scene/PickSpec.js

+147-22
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ defineSuite([
2525
'Specs/Cesium3DTilesTester',
2626
'Specs/createCanvas',
2727
'Specs/createScene',
28-
'Specs/pollToPromise'
28+
'Specs/pollToPromise',
29+
'ThirdParty/when'
2930
], 'Scene/Pick', function(
3031
Cartesian3,
3132
Cartographic,
@@ -53,7 +54,8 @@ defineSuite([
5354
Cesium3DTilesTester,
5455
createCanvas,
5556
createScene,
56-
pollToPromise) {
57+
pollToPromise,
58+
when) {
5759
'use strict';
5860

5961
// It's not easily possible to mock the asynchronous pick functions
@@ -69,6 +71,9 @@ defineSuite([
6971
var primitiveRay;
7072
var offscreenRay;
7173

74+
var batchedTilesetUrl = 'Data/Cesium3DTiles/Batched/BatchedWithTransformBox/tileset.json';
75+
var pointCloudTilesetUrl = 'Data/Cesium3DTiles/PointCloud/PointCloudWithTransform/tileset.json';
76+
7277
beforeAll(function() {
7378
scene = createScene({
7479
canvas : createCanvas(10, 10)
@@ -138,8 +143,7 @@ defineSuite([
138143
return createRectangle(height, smallRectangle);
139144
}
140145

141-
function createTileset() {
142-
var url = 'Data/Cesium3DTiles/Batched/BatchedWithTransformBox/tileset.json';
146+
function createTileset(url) {
143147
var options = {
144148
maximumScreenSpaceError : 0
145149
};
@@ -442,7 +446,7 @@ defineSuite([
442446
});
443447

444448
function picksFromRayTileset(style) {
445-
return createTileset().then(function(tileset) {
449+
return createTileset(batchedTilesetUrl).then(function(tileset) {
446450
tileset.style = style;
447451
expect(scene).toPickFromRayAndCall(function(result) {
448452
var primitive = result.object.primitive;
@@ -561,7 +565,18 @@ defineSuite([
561565
expect(scene).toPickFromRayAndCall(function(result) {
562566
expect(result.object.primitive).toBe(point);
563567
expect(result.position).toBeUndefined();
564-
}, primitiveRay);
568+
}, primitiveRay, [], 0.01);
569+
});
570+
571+
it('changes width', function() {
572+
return createTileset(pointCloudTilesetUrl).then(function(tileset) {
573+
expect(scene).toPickFromRayAndCall(function(result) {
574+
expect(result).toBeUndefined();
575+
}, primitiveRay, [], 0.1);
576+
expect(scene).toPickFromRayAndCall(function(result) {
577+
expect(result).toBeDefined();
578+
}, primitiveRay, [], 1.0);
579+
});
565580
});
566581

567582
it('throws if ray is undefined', function() {
@@ -812,6 +827,17 @@ defineSuite([
812827
}, primitiveRay, 2, [rectangle5, rectangle3]);
813828
});
814829

830+
it('changes width', function() {
831+
return createTileset(pointCloudTilesetUrl).then(function(tileset) {
832+
expect(scene).toDrillPickFromRayAndCall(function(result) {
833+
expect(result.length).toBe(0);
834+
}, primitiveRay, [], 0.1);
835+
expect(scene).toDrillPickFromRayAndCall(function(result) {
836+
expect(result.length).toBe(1);
837+
}, primitiveRay, Number.POSITIVE_INFINITY, [], 1.0);
838+
});
839+
});
840+
815841
it('throws if ray is undefined', function() {
816842
expect(function() {
817843
scene.drillPickFromRay(undefined);
@@ -840,7 +866,7 @@ defineSuite([
840866
}
841867

842868
var cartographic = new Cartographic(0.0, 0.0);
843-
return createTileset().then(function(tileset) {
869+
return createTileset(batchedTilesetUrl).then(function(tileset) {
844870
expect(scene).toSampleHeightAndCall(function(height) {
845871
expect(height).toBeGreaterThan(0.0);
846872
expect(height).toBeLessThan(20.0); // Rough height of tile
@@ -940,6 +966,22 @@ defineSuite([
940966
}, cartographic);
941967
});
942968

969+
it('changes width', function() {
970+
if (!scene.sampleHeightSupported) {
971+
return;
972+
}
973+
974+
var cartographic = new Cartographic(0.0, 0.0);
975+
return createTileset(pointCloudTilesetUrl).then(function(tileset) {
976+
expect(scene).toSampleHeightAndCall(function(height) {
977+
expect(height).toBeUndefined();
978+
}, cartographic, [], 0.1);
979+
expect(scene).toSampleHeightAndCall(function(height) {
980+
expect(height).toBeDefined();
981+
}, cartographic, [], 1.0);
982+
});
983+
});
984+
943985
it('throws if position is undefined', function() {
944986
if (!scene.sampleHeightSupported) {
945987
return;
@@ -999,7 +1041,7 @@ defineSuite([
9991041
}
10001042

10011043
var cartesian = Cartesian3.fromRadians(0.0, 0.0, 100000.0);
1002-
return createTileset().then(function(tileset) {
1044+
return createTileset(batchedTilesetUrl).then(function(tileset) {
10031045
expect(scene).toClampToHeightAndCall(function(position) {
10041046
var minimumHeight = Cartesian3.fromRadians(0.0, 0.0).x;
10051047
var maximumHeight = minimumHeight + 20.0; // Rough height of tile
@@ -1105,6 +1147,22 @@ defineSuite([
11051147
}, cartesian);
11061148
});
11071149

1150+
it('changes width', function() {
1151+
if (!scene.clampToHeightSupported) {
1152+
return;
1153+
}
1154+
1155+
var cartesian = Cartesian3.fromRadians(0.0, 0.0, 100.0);
1156+
return createTileset(pointCloudTilesetUrl).then(function(tileset) {
1157+
expect(scene).toClampToHeightAndCall(function(clampedCartesian) {
1158+
expect(clampedCartesian).toBeUndefined();
1159+
}, cartesian, [], 0.1);
1160+
expect(scene).toClampToHeightAndCall(function(clampedCartesian) {
1161+
expect(clampedCartesian).toBeDefined();
1162+
}, cartesian, [], 1.0);
1163+
});
1164+
});
1165+
11081166
it('throws if cartesian is undefined', function() {
11091167
if (!scene.clampToHeightSupported) {
11101168
return;
@@ -1157,10 +1215,10 @@ defineSuite([
11571215
});
11581216
});
11591217

1160-
function pickFromRayMostDetailed(ray, objectsToExclude) {
1218+
function pickFromRayMostDetailed(ray, objectsToExclude, width) {
11611219
var result;
11621220
var completed = false;
1163-
scene.pickFromRayMostDetailed(ray, objectsToExclude).then(function(pickResult) {
1221+
scene.pickFromRayMostDetailed(ray, objectsToExclude, width).then(function(pickResult) {
11641222
result = pickResult;
11651223
completed = true;
11661224
});
@@ -1173,10 +1231,10 @@ defineSuite([
11731231
});
11741232
}
11751233

1176-
function drillPickFromRayMostDetailed(ray, limit, objectsToExclude) {
1234+
function drillPickFromRayMostDetailed(ray, limit, objectsToExclude, width) {
11771235
var result;
11781236
var completed = false;
1179-
scene.drillPickFromRayMostDetailed(ray, limit, objectsToExclude).then(function(pickResult) {
1237+
scene.drillPickFromRayMostDetailed(ray, limit, objectsToExclude, width).then(function(pickResult) {
11801238
result = pickResult;
11811239
completed = true;
11821240
});
@@ -1189,10 +1247,10 @@ defineSuite([
11891247
});
11901248
}
11911249

1192-
function sampleHeightMostDetailed(cartographics, objectsToExclude) {
1250+
function sampleHeightMostDetailed(cartographics, objectsToExclude, width) {
11931251
var result;
11941252
var completed = false;
1195-
scene.sampleHeightMostDetailed(cartographics, objectsToExclude).then(function(pickResult) {
1253+
scene.sampleHeightMostDetailed(cartographics, objectsToExclude, width).then(function(pickResult) {
11961254
result = pickResult;
11971255
completed = true;
11981256
});
@@ -1205,10 +1263,10 @@ defineSuite([
12051263
});
12061264
}
12071265

1208-
function clampToHeightMostDetailed(cartesians, objectsToExclude) {
1266+
function clampToHeightMostDetailed(cartesians, objectsToExclude, width) {
12091267
var result;
12101268
var completed = false;
1211-
scene.clampToHeightMostDetailed(cartesians, objectsToExclude).then(function(pickResult) {
1269+
scene.clampToHeightMostDetailed(cartesians, objectsToExclude, width).then(function(pickResult) {
12121270
result = pickResult;
12131271
completed = true;
12141272
});
@@ -1227,7 +1285,7 @@ defineSuite([
12271285
return;
12281286
}
12291287
scene.camera.setView({ destination : offscreenRectangle });
1230-
return createTileset().then(function(tileset) {
1288+
return createTileset(batchedTilesetUrl).then(function(tileset) {
12311289
return pickFromRayMostDetailed(primitiveRay).then(function(result) {
12321290
var primitive = result.object.primitive;
12331291
var position = result.position;
@@ -1251,7 +1309,7 @@ defineSuite([
12511309
return;
12521310
}
12531311
scene.camera.setView({ destination : offscreenRectangle });
1254-
return createTileset().then(function(tileset) {
1312+
return createTileset(batchedTilesetUrl).then(function(tileset) {
12551313
var objectsToExclude = [tileset];
12561314
return pickFromRayMostDetailed(primitiveRay, objectsToExclude).then(function(result) {
12571315
expect(result).toBeUndefined();
@@ -1264,7 +1322,7 @@ defineSuite([
12641322
return;
12651323
}
12661324
scene.camera.setView({ destination : offscreenRectangle });
1267-
return createTileset().then(function(tileset) {
1325+
return createTileset(batchedTilesetUrl).then(function(tileset) {
12681326
tileset.show = false;
12691327
return pickFromRayMostDetailed(primitiveRay).then(function(result) {
12701328
expect(result).toBeUndefined();
@@ -1345,12 +1403,27 @@ defineSuite([
13451403
});
13461404

13471405
scene.camera.setView({ destination : offscreenRectangle });
1348-
return pickFromRayMostDetailed(primitiveRay).then(function(result) {
1406+
return pickFromRayMostDetailed(primitiveRay, [], 0.01).then(function(result) {
13491407
expect(result.object.primitive).toBe(point);
13501408
expect(result.position).toBeUndefined();
13511409
});
13521410
});
13531411

1412+
it('changes width', function() {
1413+
if (webglStub) {
1414+
return;
1415+
}
1416+
return createTileset(pointCloudTilesetUrl).then(function(tileset) {
1417+
var promise1 = pickFromRayMostDetailed(primitiveRay, [], 0.1).then(function(result) {
1418+
expect(result).toBeUndefined();
1419+
});
1420+
var promise2 = pickFromRayMostDetailed(primitiveRay, [], 1.0).then(function(result) {
1421+
expect(result).toBeDefined();
1422+
});
1423+
return when.all([promise1, promise2]);
1424+
});
1425+
});
1426+
13541427
it('throws if ray is undefined', function() {
13551428
expect(function() {
13561429
scene.pickFromRayMostDetailed(undefined);
@@ -1639,6 +1712,21 @@ defineSuite([
16391712
});
16401713
});
16411714

1715+
it('changes width', function() {
1716+
if (webglStub) {
1717+
return;
1718+
}
1719+
return createTileset(pointCloudTilesetUrl).then(function(tileset) {
1720+
var promise1 = drillPickFromRayMostDetailed(primitiveRay, 1, [], 0.1).then(function(result) {
1721+
expect(result.length).toBe(0);
1722+
});
1723+
var promise2 = drillPickFromRayMostDetailed(primitiveRay, 1, [], 1.0).then(function(result) {
1724+
expect(result.length).toBe(1);
1725+
});
1726+
return when.all([promise1, promise2]);
1727+
});
1728+
});
1729+
16421730
it('throws if ray is undefined', function() {
16431731
expect(function() {
16441732
scene.drillPickFromRayMostDetailed(undefined);
@@ -1667,7 +1755,7 @@ defineSuite([
16671755
}
16681756

16691757
var cartographics = [new Cartographic(0.0, 0.0)];
1670-
return createTileset().then(function() {
1758+
return createTileset(batchedTilesetUrl).then(function() {
16711759
return sampleHeightMostDetailed(cartographics).then(function(updatedCartographics) {
16721760
var height = updatedCartographics[0].height;
16731761
expect(height).toBeGreaterThan(0.0);
@@ -1829,6 +1917,24 @@ defineSuite([
18291917
});
18301918
});
18311919

1920+
it('changes width', function() {
1921+
if (!scene.sampleHeightSupported) {
1922+
return;
1923+
}
1924+
1925+
var cartographics1 = [new Cartographic(0.0, 0.0)];
1926+
var cartographics2 = [new Cartographic(0.0, 0.0)];
1927+
return createTileset(pointCloudTilesetUrl).then(function(tileset) {
1928+
var promise1 = sampleHeightMostDetailed(cartographics1, [], 0.1).then(function(updatedCartographics1) {
1929+
expect(updatedCartographics1[0].height).toBeUndefined();
1930+
});
1931+
var promise2 = sampleHeightMostDetailed(cartographics2, [], 1.0).then(function(updatedCartographics2) {
1932+
expect(updatedCartographics2[0].height).toBeDefined();
1933+
});
1934+
return when.all([promise1, promise2]);
1935+
});
1936+
});
1937+
18321938
it('handles empty array', function() {
18331939
if (!scene.sampleHeightSupported) {
18341940
return;
@@ -1899,7 +2005,7 @@ defineSuite([
18992005
}
19002006

19012007
var cartesians = [Cartesian3.fromRadians(0.0, 0.0, 100000.0)];
1902-
return createTileset().then(function() {
2008+
return createTileset(batchedTilesetUrl).then(function() {
19032009
return clampToHeightMostDetailed(cartesians).then(function(updatedCartesians) {
19042010
var minimumHeight = Cartesian3.fromRadians(0.0, 0.0).x;
19052011
var maximumHeight = minimumHeight + 20.0; // Rough height of tile
@@ -2073,6 +2179,25 @@ defineSuite([
20732179
});
20742180
});
20752181

2182+
it('changes width', function() {
2183+
if (!scene.clampToHeightSupported) {
2184+
return;
2185+
}
2186+
2187+
var cartesian = Cartesian3.fromRadians(0.0, 0.0, 100.0);
2188+
var cartesians1 = [Cartesian3.clone(cartesian)];
2189+
var cartesians2 = [Cartesian3.clone(cartesian)];
2190+
return createTileset(pointCloudTilesetUrl).then(function(tileset) {
2191+
var promise1 = clampToHeightMostDetailed(cartesians1, [], 0.1).then(function(clampedCartesians1) {
2192+
expect(clampedCartesians1[0]).toBeUndefined();
2193+
});
2194+
var promise2 = clampToHeightMostDetailed(cartesians2, [], 1.0).then(function(clampedCartesians2) {
2195+
expect(clampedCartesians2[0]).toBeDefined();
2196+
});
2197+
return when.all([promise1, promise2]);
2198+
});
2199+
});
2200+
20762201
it('handles empty array', function() {
20772202
if (!scene.clampToHeightSupported) {
20782203
return;

‎Specs/addDefaultMatchers.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,9 @@ define([
359359

360360
toPickFromRayAndCall : function(util, customEqualityTesters) {
361361
return {
362-
compare : function(actual, expected, ray, objectsToExclude) {
362+
compare : function(actual, expected, ray, objectsToExclude, width) {
363363
var scene = actual;
364-
var result = scene.pickFromRay(ray, objectsToExclude);
364+
var result = scene.pickFromRay(ray, objectsToExclude, width);
365365

366366
var webglStub = !!window.webglStub;
367367
if (!webglStub) {
@@ -380,9 +380,9 @@ define([
380380

381381
toDrillPickFromRayAndCall : function(util, customEqualityTesters) {
382382
return {
383-
compare : function(actual, expected, ray, limit, objectsToExclude) {
383+
compare : function(actual, expected, ray, limit, objectsToExclude, width) {
384384
var scene = actual;
385-
var results = scene.drillPickFromRay(ray, limit, objectsToExclude);
385+
var results = scene.drillPickFromRay(ray, limit, objectsToExclude, width);
386386

387387
var webglStub = !!window.webglStub;
388388
if (!webglStub) {
@@ -401,9 +401,9 @@ define([
401401

402402
toSampleHeightAndCall : function(util, customEqualityTesters) {
403403
return {
404-
compare : function(actual, expected, position, objectsToExclude) {
404+
compare : function(actual, expected, position, objectsToExclude, width) {
405405
var scene = actual;
406-
var results = scene.sampleHeight(position, objectsToExclude);
406+
var results = scene.sampleHeight(position, objectsToExclude, width);
407407

408408
var webglStub = !!window.webglStub;
409409
if (!webglStub) {
@@ -422,9 +422,9 @@ define([
422422

423423
toClampToHeightAndCall : function(util, customEqualityTesters) {
424424
return {
425-
compare : function(actual, expected, cartesian, objectsToExclude) {
425+
compare : function(actual, expected, cartesian, objectsToExclude, width) {
426426
var scene = actual;
427-
var results = scene.clampToHeight(cartesian, objectsToExclude);
427+
var results = scene.clampToHeight(cartesian, objectsToExclude, width);
428428

429429
var webglStub = !!window.webglStub;
430430
if (!webglStub) {

0 commit comments

Comments
 (0)
Please sign in to comment.