test: verify published layers stay on pavement
This commit is contained in:
1 parent
0f9dcace3d
commit
edadf98df1
2 files changed
+55
No files matched your search
@@ -278,6 +278,57 @@ assert.ok(
|
||||
complexModel.roads.some((road) => !surfacedIds.has(road.id)),
|
||||
'fixture exercises omitted roads',
|
||||
);
|
||||
const pointInRing = (point, ring) => {
|
||||
let inside = false;
|
||||
for (let index = 0, previous = ring.length - 1; index < ring.length; previous = index++) {
|
||||
const [x, y] = ring[index];
|
||||
const [px, py] = ring[previous];
|
||||
if (y > point[1] !== py > point[1] && point[0] < ((px - x) * (point[1] - y)) / (py - y) + x) inside = !inside;
|
||||
}
|
||||
return inside;
|
||||
};
|
||||
const distanceToSegmentMeters = (point, start, end) => {
|
||||
const scale = 111320 * Math.cos((point[1] * Math.PI) / 180);
|
||||
const px = point[0] * scale;
|
||||
const py = point[1] * 111320;
|
||||
const ax = start[0] * scale;
|
||||
const ay = start[1] * 111320;
|
||||
const bx = end[0] * scale;
|
||||
const by = end[1] * 111320;
|
||||
const dx = bx - ax;
|
||||
const dy = by - ay;
|
||||
const ratio =
|
||||
dx * dx + dy * dy ? Math.max(0, Math.min(1, ((px - ax) * dx + (py - ay) * dy) / (dx * dx + dy * dy))) : 0;
|
||||
return Math.hypot(px - (ax + ratio * dx), py - (ay + ratio * dy));
|
||||
};
|
||||
const coordinatesOf = (feature) =>
|
||||
feature.geometry.type === 'Polygon' ? feature.geometry.coordinates.flat() : feature.geometry.coordinates;
|
||||
const surfaceForRoad = (roadId) =>
|
||||
exteriorBaseline.roadSurface.features.filter((feature) =>
|
||||
String(feature.properties.directional_road_ids || '')
|
||||
.split(',')
|
||||
.includes(roadId),
|
||||
);
|
||||
for (const name of ['edgeLines', 'centerLines', 'laneCenterlines', 'laneSeparators']) {
|
||||
for (const feature of exteriorBaseline[name].features) {
|
||||
if (feature.properties.cluster_preview || String(feature.properties.native_id).startsWith('complex-')) continue;
|
||||
const roadId = feature.properties.road_id || String(feature.properties.directional_road_ids || '').split(',')[0];
|
||||
const surfaces = surfaceForRoad(roadId);
|
||||
assert.ok(surfaces.length > 0, `${name} must reference a published road surface`);
|
||||
for (const point of coordinatesOf(feature)) {
|
||||
assert.ok(
|
||||
surfaces.some((surface) => {
|
||||
const ring = surface.geometry.coordinates[0];
|
||||
return (
|
||||
pointInRing(point, ring) ||
|
||||
ring.some((vertex, index) => distanceToSegmentMeters(point, vertex, ring[index + 1] || ring[0]) <= 0.3)
|
||||
);
|
||||
}),
|
||||
`${name} feature ${feature.properties.native_id} must stay on its road surface`,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const name of ['edgeLines', 'centerLines', 'laneCenterlines', 'laneSeparators', 'directionArrows', 'turnArrows']) {
|
||||
for (const feature of exteriorBaseline[name].features) {
|
||||
if (feature.properties.cluster_preview || String(feature.properties.native_id).startsWith('complex-')) continue;
|
||||
|
||||
Reference in new issue
Block a user