feat(junction): preserve known traffic island regions
This commit is contained in:
1 parent
b6f4dfeb0c
commit
4b8f37a219
3 files changed
+36
-4
No files matched your search
@@ -93,6 +93,7 @@ function buildComplexJunctionGeometry(model, cluster, helpers) {
|
||||
innerRadiusFor: () => coreRadius * 0.7,
|
||||
},
|
||||
helpers,
|
||||
model.exclusionRegions || [],
|
||||
);
|
||||
for (const section of boundaryGraph.sections) {
|
||||
const item = carriageways.find((candidate) => candidate.key === section.carriagewayKey);
|
||||
|
||||
@@ -56,7 +56,7 @@ function sectionAt(item, radius, center, helpers) {
|
||||
// The graph currently owns only source-derived entry edges. Core closure is
|
||||
// deliberately unresolved until a later stage can distinguish paved links,
|
||||
// medians, and exclusion regions from topology alone.
|
||||
function buildJunctionBoundaryGraph(topology, center, radii, helpers) {
|
||||
function buildJunctionBoundaryGraph(topology, center, radii, helpers, exclusionRegions = []) {
|
||||
const sections = topology.carriageways.map((item) => {
|
||||
const outerRadius = radii.outerRadiusFor(item);
|
||||
const innerRadius = radii.innerRadiusFor(item);
|
||||
@@ -88,6 +88,7 @@ function buildJunctionBoundaryGraph(topology, center, radii, helpers) {
|
||||
status: 'entry-sections-only',
|
||||
sections,
|
||||
edges,
|
||||
exclusionRegions: exclusionRegions.filter((region) => Array.isArray(region.ring) && region.ring.length >= 4),
|
||||
unresolvedClosures: topology.arms.map((arm) => arm.cornerKey),
|
||||
};
|
||||
}
|
||||
@@ -114,6 +115,17 @@ function signedArea(ring) {
|
||||
return ring.slice(1).reduce((area, point, index) => area + ring[index][0] * point[1] - point[0] * ring[index][1], 0);
|
||||
}
|
||||
|
||||
function pointInRing(point, ring) {
|
||||
return ring.slice(1).reduce((inside, candidate, index) => {
|
||||
const previous = ring[index];
|
||||
const crosses = previous[1] > point[1] !== candidate[1] > point[1];
|
||||
return crosses &&
|
||||
point[0] < ((candidate[0] - previous[0]) * (point[1] - previous[1])) / (candidate[1] - previous[1]) + previous[0]
|
||||
? !inside
|
||||
: inside;
|
||||
}, false);
|
||||
}
|
||||
|
||||
// A central paved region is safe to infer only when every arm has exactly one
|
||||
// source carriageway. Its shared entry seams are the sections' `inner` edges;
|
||||
// every remaining edge is an explicit closure between adjacent arms.
|
||||
@@ -145,6 +157,8 @@ function buildCoreClosure(topology, graph, center) {
|
||||
});
|
||||
if (ring.length < 7 || !paired || Math.abs(signedArea(ring)) < 1e-14 || ringSelfIntersects(ring))
|
||||
return { status: 'unsupported', reason: 'core-closure-invalid' };
|
||||
if (graph.exclusionRegions.some((region) => region.ring.some((point) => pointInRing(point, ring))))
|
||||
return { status: 'unsupported', reason: 'known-exclusion-region' };
|
||||
return {
|
||||
status: 'supported',
|
||||
ring,
|
||||
|
||||
@@ -91,17 +91,26 @@ function parseOsmRoads(xml) {
|
||||
crossingNodes.push({ id, coordinate, tags });
|
||||
}
|
||||
const ways = [];
|
||||
const exclusionRegions = [];
|
||||
for (const match of xml.matchAll(/<way\b([^>]*)>([\s\S]*?)<\/way>/g)) {
|
||||
const attrs = xmlAttrs(match[1]);
|
||||
const body = match[2];
|
||||
const tags = parseTags(body);
|
||||
if (attrs.action === 'delete' || !MOTOR_HIGHWAYS.has(tags.highway || '')) continue;
|
||||
const refs = [...body.matchAll(/<nd\b([^>]*)\/?\s*>/g)].map((item) => xmlAttrs(item[1]).ref).filter(Boolean);
|
||||
const coords = refs.map((ref) => nodes.get(String(ref))).filter(Boolean);
|
||||
if (
|
||||
attrs.action !== 'delete' &&
|
||||
refs.length >= 4 &&
|
||||
refs[0] === refs.at(-1) &&
|
||||
coords.length === refs.length &&
|
||||
(tags.highway === 'traffic_island' || tags.traffic_calming === 'island')
|
||||
)
|
||||
exclusionRegions.push({ id: String(attrs.id), source: 'osm-traffic-island', ring: coords, tags });
|
||||
if (attrs.action === 'delete' || !MOTOR_HIGHWAYS.has(tags.highway || '')) continue;
|
||||
if (coords.length < 2 || coords.length !== refs.length) continue;
|
||||
ways.push({ id: String(attrs.id), refs: refs.map(String), coords, tags });
|
||||
}
|
||||
return { nodes, ways, crossingNodes };
|
||||
return { nodes, ways, crossingNodes, exclusionRegions };
|
||||
}
|
||||
|
||||
function compileRoadModel(xml, overrides) {
|
||||
@@ -182,7 +191,15 @@ function compileRoadModel(xml, overrides) {
|
||||
...crossing,
|
||||
osmWayIds: parsed.ways.filter((way) => way.refs.includes(crossing.id)).map((way) => way.id),
|
||||
}));
|
||||
return { schema: 'native-road-model/v1', roads, endpoints, connections, crossings, diagnostics };
|
||||
return {
|
||||
schema: 'native-road-model/v1',
|
||||
roads,
|
||||
endpoints,
|
||||
connections,
|
||||
crossings,
|
||||
exclusionRegions: parsed.exclusionRegions,
|
||||
diagnostics,
|
||||
};
|
||||
}
|
||||
|
||||
function splitWayAtSharedNodes(way, sharedNodeWayIds) {
|
||||
|
||||
Reference in new issue
Block a user