Skip to content

Commit

Permalink
Basic unit tests for fitScreenCoordinates.
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisLoer committed Jul 3, 2018
1 parent bb4ffa2 commit 6af3c63
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions test/unit/ui/camera.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1730,5 +1730,50 @@ test('camera', (t) => {
t.end();
});

t.test('#fitScreenCoordinates', (t) => {
t.test('bearing 225', (t) => {
const camera = createCamera();
const p0 = [128, 128];
const p1 = [256, 256];
const bearing = 225;

camera.fitScreenCoordinates(p0, p1, bearing, {duration:0});
t.deepEqual(fixedLngLat(camera.getCenter(), 4), { lng: -45, lat: 40.9799 }, 'centers, rotates 225 degrees, and zooms based on screen coordinates');
t.equal(fixedNum(camera.getZoom(), 3), 1.5);
t.equal(camera.getBearing(), -135);
t.end();
});

t.test('bearing 0', (t) => {
const camera = createCamera();

const p0 = [128, 128];
const p1 = [256, 256];
const bearing = 0;

camera.fitScreenCoordinates(p0, p1, bearing, {duration:0});
t.deepEqual(fixedLngLat(camera.getCenter(), 4), { lng: -45, lat: 40.9799 }, 'centers and zooms in based on screen coordinates');
t.equal(fixedNum(camera.getZoom(), 3), 2);
t.equal(camera.getBearing(), 0);
t.end();
});

t.test('inverted points', (t) => {
const camera = createCamera();
const p1 = [128, 128];
const p0 = [256, 256];
const bearing = 0;

camera.fitScreenCoordinates(p0, p1, bearing, {duration:0});
t.deepEqual(fixedLngLat(camera.getCenter(), 4), { lng: -45, lat: 40.9799 }, 'centers and zooms based on screen coordinates in opposite order');
t.equal(fixedNum(camera.getZoom(), 3), 2);
t.equal(camera.getBearing(), 0);
t.end();
});

t.end();
});


t.end();
});

0 comments on commit 6af3c63

Please sign in to comment.