mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2026-10-19 17:22:12 +00:00
routing
This commit is contained in:
1 parent
29850c1c8f
commit
594dd8979a
35 files changed
+3135
-1171
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import { describe, it } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { closestPointIndex } from './closest-point';
|
||||
import { closestPointIndex, closestPointIndexIn } from './closest-point';
|
||||
|
||||
describe('closestPointIndex', () => {
|
||||
const line = [0, 0, 1, 0, 2, 0, 2, 1];
|
||||
@@ -27,3 +27,24 @@ describe('closestPointIndex', () => {
|
||||
assert.equal(closestPointIndex(coordinates, { lng: 3, lat: 0.01 }), 0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('closestPointIndexIn', () => {
|
||||
const lng = [0, 1, 2, 2, 5, 6];
|
||||
const lat = [0, 0, 0, 1, 5, 5];
|
||||
|
||||
it('gives the index in the arrays, looking at the given range only', () => {
|
||||
assert.equal(closestPointIndexIn(lng, lat, 0, 4, { lng: 0.8, lat: 0.1 }), 1);
|
||||
// the range starts after the closest points
|
||||
assert.equal(closestPointIndexIn(lng, lat, 4, 6, { lng: 0.8, lat: 0.1 }), 4);
|
||||
assert.equal(closestPointIndexIn(lng, lat, 4, 6, { lng: 5.9, lat: 5.1 }), 5);
|
||||
});
|
||||
|
||||
it('has no point in an empty range', () => {
|
||||
assert.equal(closestPointIndexIn(lng, lat, 3, 3, { lng: 0, lat: 0 }), undefined);
|
||||
assert.equal(closestPointIndexIn(lng, lat, 4, 2, { lng: 0, lat: 0 }), undefined);
|
||||
});
|
||||
|
||||
it('is the point itself for a range of one point', () => {
|
||||
assert.equal(closestPointIndexIn(lng, lat, 3, 4, { lng: 9, lat: 9 }), 3);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user