Skip to content

Commit

Permalink
Add line intersection unit test.
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisLoer committed Mar 13, 2023
1 parent 9a73fab commit 66f0950
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
26 changes: 25 additions & 1 deletion src/symbol/projection.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {project} from './projection';
import {findIntersectionPoint, project} from './projection';

import Point from '@mapbox/point-geometry';
import {mat4} from 'gl-matrix';
Expand All @@ -9,4 +9,28 @@ describe('Projection', () => {
const matrix = mat4.create();
expect(project(point, matrix).point.x).toBeCloseTo(point.x, 10);
});

test('line intersection', () => {
const horizontal = [
new Point(0, 0),
new Point(10, 0)];
const vertical = [
new Point(30, -20),
new Point(30, -10)
];
const intersection = findIntersectionPoint(horizontal[0], horizontal[1], vertical[0], vertical[1]);
expect(intersection).toEqual(new Point(30, 0));
});

test('parallel line intersection', () => {
const first = [
new Point(0, 0),
new Point(10, 0)];
const second = [
new Point(10, 0),
new Point(30, 0)
];
const intersection = findIntersectionPoint(first[0], first[1], second[0], second[1]);
expect(intersection).toEqual(new Point(10, 0));
});
});
2 changes: 1 addition & 1 deletion src/symbol/projection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type {
} from '../data/array_types.g';
import {WritingMode} from '../symbol/shaping';

export {updateLineLabels, hideGlyphs, getLabelPlaneMatrix, getGlCoordMatrix, project, getPerspectiveRatio, placeFirstAndLastGlyph, placeGlyphAlongLine, xyTransformMat4};
export {updateLineLabels, hideGlyphs, getLabelPlaneMatrix, getGlCoordMatrix, project, getPerspectiveRatio, placeFirstAndLastGlyph, placeGlyphAlongLine, xyTransformMat4, findIntersectionPoint};

/*
* # Overview of coordinate spaces
Expand Down

0 comments on commit 66f0950

Please sign in to comment.