Skip to content

Commit

Permalink
Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lilleyse committed Jan 1, 2019
1 parent 9029745 commit e9236ec
Show file tree
Hide file tree
Showing 2 changed files with 149 additions and 30 deletions.
163 changes: 141 additions & 22 deletions Specs/Scene/PickSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ defineSuite([
'Specs/Cesium3DTilesTester',
'Specs/createCanvas',
'Specs/createScene',
'Specs/pollToPromise'
'Specs/pollToPromise',
'ThirdParty/when'
], 'Scene/Pick', function(
Cartesian3,
Cartographic,
Expand Down Expand Up @@ -53,7 +54,8 @@ defineSuite([
Cesium3DTilesTester,
createCanvas,
createScene,
pollToPromise) {
pollToPromise,
when) {
'use strict';

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

var batchedTilesetUrl = 'Data/Cesium3DTiles/Batched/BatchedWithTransformBox/tileset.json';
var pointCloudTilesetUrl = 'Data/Cesium3DTiles/PointCloud/PointCloudWithTransform/tileset.json';

beforeAll(function() {
scene = createScene({
canvas : createCanvas(10, 10)
Expand Down Expand Up @@ -138,8 +143,7 @@ defineSuite([
return createRectangle(height, smallRectangle);
}

function createTileset() {
var url = 'Data/Cesium3DTiles/Batched/BatchedWithTransformBox/tileset.json';
function createTileset(url) {
var options = {
maximumScreenSpaceError : 0
};
Expand Down Expand Up @@ -442,7 +446,7 @@ defineSuite([
});

function picksFromRayTileset(style) {
return createTileset().then(function(tileset) {
return createTileset(batchedTilesetUrl).then(function(tileset) {
tileset.style = style;
expect(scene).toPickFromRayAndCall(function(result) {
var primitive = result.object.primitive;
Expand Down Expand Up @@ -561,7 +565,18 @@ defineSuite([
expect(scene).toPickFromRayAndCall(function(result) {
expect(result.object.primitive).toBe(point);
expect(result.position).toBeUndefined();
}, primitiveRay);
}, primitiveRay, [], 0.01);
});

it('changes width', function() {
return createTileset(pointCloudTilesetUrl).then(function(tileset) {
expect(scene).toPickFromRayAndCall(function(result) {
expect(result).toBeUndefined();
}, primitiveRay, [], 0.1);
expect(scene).toPickFromRayAndCall(function(result) {
expect(result).toBeDefined();
}, primitiveRay, [], 1.0);
});
});

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

it('changes width', function() {
return createTileset(pointCloudTilesetUrl).then(function(tileset) {
expect(scene).toDrillPickFromRayAndCall(function(result) {
expect(result.length).toBe(0);
}, primitiveRay, [], 0.1);
expect(scene).toDrillPickFromRayAndCall(function(result) {
expect(result.length).toBe(1);
}, primitiveRay, Number.POSITIVE_INFINITY, [], 1.0);
});
});

it('throws if ray is undefined', function() {
expect(function() {
scene.drillPickFromRay(undefined);
Expand Down Expand Up @@ -840,7 +866,7 @@ defineSuite([
}

var cartographic = new Cartographic(0.0, 0.0);
return createTileset().then(function(tileset) {
return createTileset(batchedTilesetUrl).then(function(tileset) {
expect(scene).toSampleHeightAndCall(function(height) {
expect(height).toBeGreaterThan(0.0);
expect(height).toBeLessThan(20.0); // Rough height of tile
Expand Down Expand Up @@ -940,6 +966,22 @@ defineSuite([
}, cartographic);
});

it('changes width', function() {
if (!scene.sampleHeightSupported) {
return;
}

var cartographic = new Cartographic(0.0, 0.0);
return createTileset(pointCloudTilesetUrl).then(function(tileset) {
expect(scene).toSampleHeightAndCall(function(height) {
expect(height).toBeUndefined();
}, cartographic, [], 0.1);
expect(scene).toSampleHeightAndCall(function(height) {
expect(height).toBeDefined();
}, cartographic, [], 1.0);
});
});

it('throws if position is undefined', function() {
if (!scene.sampleHeightSupported) {
return;
Expand Down Expand Up @@ -999,7 +1041,7 @@ defineSuite([
}

var cartesian = Cartesian3.fromRadians(0.0, 0.0, 100000.0);
return createTileset().then(function(tileset) {
return createTileset(batchedTilesetUrl).then(function(tileset) {
expect(scene).toClampToHeightAndCall(function(position) {
var minimumHeight = Cartesian3.fromRadians(0.0, 0.0).x;
var maximumHeight = minimumHeight + 20.0; // Rough height of tile
Expand Down Expand Up @@ -1105,6 +1147,22 @@ defineSuite([
}, cartesian);
});

it('changes width', function() {
if (!scene.clampToHeightSupported) {
return;
}

var cartesian = Cartesian3.fromRadians(0.0, 0.0, 100.0);
return createTileset(pointCloudTilesetUrl).then(function(tileset) {
expect(scene).toClampToHeightAndCall(function(clampedCartesian) {
expect(clampedCartesian).toBeUndefined();
}, cartesian, [], 0.1);
expect(scene).toClampToHeightAndCall(function(clampedCartesian) {
expect(clampedCartesian).toBeDefined();
}, cartesian, [], 1.0);
});
});

it('throws if cartesian is undefined', function() {
if (!scene.clampToHeightSupported) {
return;
Expand Down Expand Up @@ -1157,10 +1215,10 @@ defineSuite([
});
});

function pickFromRayMostDetailed(ray, objectsToExclude) {
function pickFromRayMostDetailed(ray, objectsToExclude, width) {
var result;
var completed = false;
scene.pickFromRayMostDetailed(ray, objectsToExclude).then(function(pickResult) {
scene.pickFromRayMostDetailed(ray, objectsToExclude, width).then(function(pickResult) {
result = pickResult;
completed = true;
});
Expand All @@ -1173,10 +1231,10 @@ defineSuite([
});
}

function drillPickFromRayMostDetailed(ray, limit, objectsToExclude) {
function drillPickFromRayMostDetailed(ray, limit, objectsToExclude, width) {
var result;
var completed = false;
scene.drillPickFromRayMostDetailed(ray, limit, objectsToExclude).then(function(pickResult) {
scene.drillPickFromRayMostDetailed(ray, limit, objectsToExclude, width).then(function(pickResult) {
result = pickResult;
completed = true;
});
Expand All @@ -1189,10 +1247,10 @@ defineSuite([
});
}

function sampleHeightMostDetailed(cartographics, objectsToExclude) {
function sampleHeightMostDetailed(cartographics, objectsToExclude, width) {
var result;
var completed = false;
scene.sampleHeightMostDetailed(cartographics, objectsToExclude).then(function(pickResult) {
scene.sampleHeightMostDetailed(cartographics, objectsToExclude, width).then(function(pickResult) {
result = pickResult;
completed = true;
});
Expand All @@ -1205,10 +1263,10 @@ defineSuite([
});
}

function clampToHeightMostDetailed(cartesians, objectsToExclude) {
function clampToHeightMostDetailed(cartesians, objectsToExclude, width) {
var result;
var completed = false;
scene.clampToHeightMostDetailed(cartesians, objectsToExclude).then(function(pickResult) {
scene.clampToHeightMostDetailed(cartesians, objectsToExclude, width).then(function(pickResult) {
result = pickResult;
completed = true;
});
Expand All @@ -1227,7 +1285,7 @@ defineSuite([
return;
}
scene.camera.setView({ destination : offscreenRectangle });
return createTileset().then(function(tileset) {
return createTileset(batchedTilesetUrl).then(function(tileset) {
return pickFromRayMostDetailed(primitiveRay).then(function(result) {
var primitive = result.object.primitive;
var position = result.position;
Expand All @@ -1251,7 +1309,7 @@ defineSuite([
return;
}
scene.camera.setView({ destination : offscreenRectangle });
return createTileset().then(function(tileset) {
return createTileset(batchedTilesetUrl).then(function(tileset) {
var objectsToExclude = [tileset];
return pickFromRayMostDetailed(primitiveRay, objectsToExclude).then(function(result) {
expect(result).toBeUndefined();
Expand All @@ -1264,7 +1322,7 @@ defineSuite([
return;
}
scene.camera.setView({ destination : offscreenRectangle });
return createTileset().then(function(tileset) {
return createTileset(batchedTilesetUrl).then(function(tileset) {
tileset.show = false;
return pickFromRayMostDetailed(primitiveRay).then(function(result) {
expect(result).toBeUndefined();
Expand Down Expand Up @@ -1345,12 +1403,24 @@ defineSuite([
});

scene.camera.setView({ destination : offscreenRectangle });
return pickFromRayMostDetailed(primitiveRay).then(function(result) {
return pickFromRayMostDetailed(primitiveRay, [], 0.01).then(function(result) {
expect(result.object.primitive).toBe(point);
expect(result.position).toBeUndefined();
});
});

it('changes width', function() {
return createTileset(pointCloudTilesetUrl).then(function(tileset) {
var promise1 = pickFromRayMostDetailed(primitiveRay, [], 0.1).then(function(result) {
expect(result).toBeUndefined();
});
var promise2 = pickFromRayMostDetailed(primitiveRay, [], 1.0).then(function(result) {
expect(result).toBeDefined();
});
return when.all([promise1, promise2]);
});
});

it('throws if ray is undefined', function() {
expect(function() {
scene.pickFromRayMostDetailed(undefined);
Expand Down Expand Up @@ -1639,6 +1709,18 @@ defineSuite([
});
});

it('changes width', function() {
return createTileset(pointCloudTilesetUrl).then(function(tileset) {
var promise1 = drillPickFromRayMostDetailed(primitiveRay, 1, [], 0.1).then(function(result) {
expect(result.length).toBe(0);
});
var promise2 = drillPickFromRayMostDetailed(primitiveRay, 1, [], 1.0).then(function(result) {
expect(result.length).toBe(1);
});
return when.all([promise1, promise2]);
});
});

it('throws if ray is undefined', function() {
expect(function() {
scene.drillPickFromRayMostDetailed(undefined);
Expand Down Expand Up @@ -1667,7 +1749,7 @@ defineSuite([
}

var cartographics = [new Cartographic(0.0, 0.0)];
return createTileset().then(function() {
return createTileset(batchedTilesetUrl).then(function() {
return sampleHeightMostDetailed(cartographics).then(function(updatedCartographics) {
var height = updatedCartographics[0].height;
expect(height).toBeGreaterThan(0.0);
Expand Down Expand Up @@ -1829,6 +1911,24 @@ defineSuite([
});
});

it('changes width', function() {
if (!scene.sampleHeightSupported) {
return;
}

var cartographics1 = [new Cartographic(0.0, 0.0)];
var cartographics2 = [new Cartographic(0.0, 0.0)];
return createTileset(pointCloudTilesetUrl).then(function(tileset) {
var promise1 = sampleHeightMostDetailed(cartographics1, [], 0.1).then(function(updatedCartographics1) {
expect(updatedCartographics1[0].height).toBeUndefined();
});
var promise2 = sampleHeightMostDetailed(cartographics2, [], 1.0).then(function(updatedCartographics2) {
expect(updatedCartographics2[0].height).toBeDefined();
});
return when.all([promise1, promise2]);
});
});

it('handles empty array', function() {
if (!scene.sampleHeightSupported) {
return;
Expand Down Expand Up @@ -1899,7 +1999,7 @@ defineSuite([
}

var cartesians = [Cartesian3.fromRadians(0.0, 0.0, 100000.0)];
return createTileset().then(function() {
return createTileset(batchedTilesetUrl).then(function() {
return clampToHeightMostDetailed(cartesians).then(function(updatedCartesians) {
var minimumHeight = Cartesian3.fromRadians(0.0, 0.0).x;
var maximumHeight = minimumHeight + 20.0; // Rough height of tile
Expand Down Expand Up @@ -2073,6 +2173,25 @@ defineSuite([
});
});

it('changes width', function() {
if (!scene.clampToHeightSupported) {
return;
}

var cartesian = Cartesian3.fromRadians(0.0, 0.0, 100.0);
var cartesians1 = [Cartesian3.clone(cartesian)];
var cartesians2 = [Cartesian3.clone(cartesian)];
return createTileset(pointCloudTilesetUrl).then(function(tileset) {
var promise1 = clampToHeightMostDetailed(cartesians1, [], 0.1).then(function(clampedCartesians1) {
expect(clampedCartesians1[0]).toBeUndefined();
});
var promise2 = clampToHeightMostDetailed(cartesians2, [], 1.0).then(function(clampedCartesians2) {
expect(clampedCartesians2[0]).toBeDefined();
});
return when.all([promise1, promise2]);
});
});

it('handles empty array', function() {
if (!scene.clampToHeightSupported) {
return;
Expand Down
16 changes: 8 additions & 8 deletions Specs/addDefaultMatchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,9 @@ define([

toPickFromRayAndCall : function(util, customEqualityTesters) {
return {
compare : function(actual, expected, ray, objectsToExclude) {
compare : function(actual, expected, ray, objectsToExclude, width) {
var scene = actual;
var result = scene.pickFromRay(ray, objectsToExclude);
var result = scene.pickFromRay(ray, objectsToExclude, width);

var webglStub = !!window.webglStub;
if (!webglStub) {
Expand All @@ -380,9 +380,9 @@ define([

toDrillPickFromRayAndCall : function(util, customEqualityTesters) {
return {
compare : function(actual, expected, ray, limit, objectsToExclude) {
compare : function(actual, expected, ray, limit, objectsToExclude, width) {
var scene = actual;
var results = scene.drillPickFromRay(ray, limit, objectsToExclude);
var results = scene.drillPickFromRay(ray, limit, objectsToExclude, width);

var webglStub = !!window.webglStub;
if (!webglStub) {
Expand All @@ -401,9 +401,9 @@ define([

toSampleHeightAndCall : function(util, customEqualityTesters) {
return {
compare : function(actual, expected, position, objectsToExclude) {
compare : function(actual, expected, position, objectsToExclude, width) {
var scene = actual;
var results = scene.sampleHeight(position, objectsToExclude);
var results = scene.sampleHeight(position, objectsToExclude, width);

var webglStub = !!window.webglStub;
if (!webglStub) {
Expand All @@ -422,9 +422,9 @@ define([

toClampToHeightAndCall : function(util, customEqualityTesters) {
return {
compare : function(actual, expected, cartesian, objectsToExclude) {
compare : function(actual, expected, cartesian, objectsToExclude, width) {
var scene = actual;
var results = scene.clampToHeight(cartesian, objectsToExclude);
var results = scene.clampToHeight(cartesian, objectsToExclude, width);

var webglStub = !!window.webglStub;
if (!webglStub) {
Expand Down

0 comments on commit e9236ec

Please sign in to comment.