Skip to content

Commit

Permalink
Add getCenterAnchor unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisLoer committed Jul 3, 2018
1 parent f860569 commit ab807d2
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion test/unit/symbol/get_anchors.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { test } from 'mapbox-gl-js-test';
import Point from '@mapbox/point-geometry';
import { getAnchors } from '../../../src/symbol/get_anchors';
import { getAnchors, getCenterAnchor } from '../../../src/symbol/get_anchors';

const TILE_EXTENT = 4096;

Expand Down Expand Up @@ -98,5 +98,29 @@ test('getAnchors', (t) => {
{ x: 1, y: 2, angle: 1.5707963267948966, segment: 0 }]);
t.end();
});

test('getCenterAnchor', (t) => {
const line = [new Point(1, 1), new Point(1, 3.1), new Point(3, 6), new Point(4, 7)];
const anchor = getCenterAnchor(line, Math.PI, shapedText, shapedIcon, glyphSize, 1);
t.deepEqual(anchor,
{ x: 2, y: 4, angle: 0.9670469933974603, segment: 1 });
t.end();
});

test('getCenterAnchor with center outside tile bounds', (t) => {
const line = [new Point(-10, -10), new Point(5, 5)];
const anchor = getCenterAnchor(line, 2, Math.PI, shapedText, shapedIcon, glyphSize, 1);
t.deepEqual(anchor,
{ x: -2, y: -2, angle: 0.7853981633974483, segment: 0 });
t.end();
});

test('getCenterAnchor failing maxAngle test', (t) => {
const line = [new Point(1, 1), new Point(1, 3), new Point(3, 3)];
const anchor = getCenterAnchor(line, Math.PI / 4, shapedText, shapedIcon, glyphSize, 1);
t.notOk(anchor);
t.end();
});

t.end();
});

0 comments on commit ab807d2

Please sign in to comment.