Preserve offline geometry, marking, replay and evaluation pipelines with source manifests and synthetic tests. Research qualification does not activate these methods as production navigation.
46 lines
2.0 KiB
Python
46 lines
2.0 KiB
Python
"""Transfer only whole conserved sources; leave neighbor choices to the solver.
|
|
|
|
An intersecting source outside this replacement's measurement domain is not
|
|
deleted or clipped. It remains owned by its keep/replacement alternatives.
|
|
The joint overlap and seam constraints prohibit selecting it with this body.
|
|
"""
|
|
|
|
import numpy as np
|
|
import shapely
|
|
from marking_rules import POLICY, validate_removed
|
|
from shapely.geometry import shape
|
|
|
|
|
|
def plan(candidate, current, readers):
|
|
p = shapely.union_all(candidate["polygons"])
|
|
domain = p.buffer(POLICY["max_join_gap_m"])
|
|
ids, neighbors = [], []
|
|
for ident, feature in current.items():
|
|
if feature["properties"].get("class") != "road_marking":
|
|
continue
|
|
q = shapely.force_2d(shape(feature["geometry"]))
|
|
if q.intersection(domain).area < POLICY["max_overlap_m2"]:
|
|
continue
|
|
if feature["properties"].get("subtype") != "linear_marking":
|
|
# Protected symbols retain the original hard ownership boundary.
|
|
return None, dict(reason="protected-owner")
|
|
if q.difference(domain).area > POLICY["max_overlap_m2"]:
|
|
neighbors.append(ident)
|
|
else:
|
|
ids.append(ident)
|
|
old = shapely.union_all([shapely.force_2d(shape(current[i]["geometry"])) for i in ids])
|
|
removed = old.difference(p.buffer(POLICY["retained_paint_tolerance_m"]))
|
|
if not removed.is_empty:
|
|
normal = np.array([-candidate["axis"][1], candidate["axis"][0]])
|
|
transverse = (shapely.get_coordinates(removed) - candidate["origin"]) @ normal
|
|
if np.max(abs(transverse)) > 0.7:
|
|
return None, dict(reason="removed-paint-outside-measurement")
|
|
okay, evidence = validate_removed(old, p, candidate, readers)
|
|
if not okay:
|
|
return None, dict(reason="positive-or-unobserved-removed-paint", views=evidence)
|
|
return sorted(ids), dict(
|
|
reason="conserved-whole-sources-conditional-neighbors",
|
|
views=evidence,
|
|
conditional_neighbors=sorted(neighbors),
|
|
)
|