Skip to content

Commit

Permalink
add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiaoji Chen committed Dec 20, 2019
1 parent a1d1403 commit 932e3c7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
10 changes: 2 additions & 8 deletions modules/geo-layers/src/tile-3d-layer/get-frame-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function getFrameState(viewport, frameNumber) {
enuToFixedTransform.transformAsVector(new Vector3(cameraUp).scale(metersPerUnit))
).normalize();

commonSpacePlanesToWGS84(viewport);
commonSpacePlanesToWGS84(viewport, viewportCenterCartesian);

// TODO: make a file/class for frameState and document what needs to be attached to this so that traversal can function
return {
Expand All @@ -59,14 +59,8 @@ export function getFrameState(viewport, frameNumber) {
};
}

function commonSpacePlanesToWGS84(viewport) {
function commonSpacePlanesToWGS84(viewport, viewportCenterCartesian) {
// Extract frustum planes based on current view.
const viewportCenterCartographic = [viewport.longitude, viewport.latitude, 0];
const viewportCenterCartesian = Ellipsoid.WGS84.cartographicToCartesian(
viewportCenterCartographic,
new Vector3()
);

const frustumPlanes = viewport.getFrustumPlanes();
let i = 0;
for (const dir in frustumPlanes) {
Expand Down
16 changes: 15 additions & 1 deletion test/modules/geo-layers/tile-3d-layer/get-frame-state.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
import test from 'tape-catch';
import {getFrameState} from '@deck.gl/geo-layers/tile-3d-layer/get-frame-state';
import {Viewport} from 'deck.gl';
import {equals} from 'math.gl';
import {equals, Vector3} from 'math.gl';
import {Ellipsoid} from '@math.gl/geospatial';

const EPSILON = 1e-5;
const expected = {
Expand All @@ -41,6 +42,8 @@ test('getFrameState', t => {
height: 775,
latitude: 50.751537058389985,
longitude: 42.42694203247012,
pitch: 30,
bearing: -120,
zoom: 15.5
});

Expand All @@ -58,5 +61,16 @@ test('getFrameState', t => {
t.ok(equals(results.camera.up, expected.camera.up, EPSILON), 'camera.up should match.');
t.ok(results.cullingVolume.planes.length, 6, 'Should have 6 planes.');

const viewportCenterCartesian = Ellipsoid.WGS84.cartographicToCartesian(
[viewport.longitude, viewport.latitude, 0],
new Vector3()
);
for (const plane of results.cullingVolume.planes) {
t.ok(
plane.getPointDistance(viewportCenterCartesian) > 0,
'viewport center is on the inside of the frustum plane'
);
}

t.end();
});

0 comments on commit 932e3c7

Please sign in to comment.