Files
NODEDC_MISSION_CORE/simulation/urban-plan-research/plan_boundaries.py
T
DCCONSTRUCTIONS 69dc566665 feat(research): preserve urban geometry pipelines and qualification suites
Preserve offline geometry, marking, replay and evaluation pipelines with source manifests and synthetic tests. Research qualification does not activate these methods as production navigation.
2026-10-29 09:10:00 +03:00

44 lines
2.0 KiB
Python

"""Observed boundaries are line chains, never observation-footprint closures."""
from dataclasses import dataclass
import numpy as np
@dataclass(frozen=True)
class ObservedChain:
points: np.ndarray
closed: bool
start_reason: str
end_reason: str
def split_observed_boundary(points, physical, observed, *, cyclic=True, minimum_length=0.0):
"""Split a sampled perimeter using independent physical-edge evidence.
`physical` identifies an actual interface (e.g. road/sidewalk), while
`observed` describes scan coverage. A semantic frontier inside an observed
scan is unresolved, not a road end. No extrapolation or gap filling occurs.
A fully supported traffic island may remain closed.
"""
p=np.asarray(points,float);edge=np.asarray(physical,bool);seen=np.asarray(observed,bool)
if p.ndim!=2 or p.shape[1] not in (2,3) or len(p)<2:
raise ValueError('Expected at least two XY or XYZ samples')
if edge.shape!=(len(p),) or seen.shape!=edge.shape or not np.isfinite(p).all():
raise ValueError('Boundary evidence must be finite and aligned')
valid=edge&seen
if cyclic and valid.all():
q=np.vstack([p,p[0]]) if not np.allclose(p[0],p[-1]) else p.copy()
if np.linalg.norm(np.diff(q[:,:2],axis=0),axis=1).sum()<minimum_length:return []
return [ObservedChain(q,True,'physical-loop','physical-loop')]
if not valid.any():return []
if cyclic:
k=int(np.flatnonzero(~valid)[0]);p=np.roll(p,-k,axis=0);valid=np.roll(valid,-k);seen=np.roll(seen,-k)
cuts=np.r_[0,np.flatnonzero(np.diff(valid.astype(int)))+1,len(valid)]
result=[]
def reason(i):
if not cyclic and (i<0 or i>=len(p)):return 'input-end'
return 'semantic-frontier' if seen[i%len(p)] else 'coverage-frontier'
for a,b in zip(cuts[:-1],cuts[1:]):
if not valid[a] or b-a<2:continue
q=p[a:b].copy();length=np.linalg.norm(np.diff(q[:,:2],axis=0),axis=1).sum()
if length<minimum_length:continue
result.append(ObservedChain(q,False,reason(a-1),reason(b)))
return result