"""Keep the evidence footprint fixed across replacements within one fresh run. The tolerance belongs to the original observed paint, not to each edit in a chain. No baseline or previous-run geometry is loaded here. """ import numpy as np import shapely from marking_rules import POLICY,validate_removed class PaintConservation: def __init__(self): self.footprints={} def inherited(self,ids,current,geometry): return shapely.union_all([self.footprints.get(i,geometry(current[i])) for i in ids]) def validate(self,ids,current,geometry,new,candidate,readers): old=self.inherited(ids,current,geometry) removed=old.difference(new.buffer(POLICY['retained_paint_tolerance_m'])) if not removed.is_empty: normal=np.array([-candidate['axis'][1],candidate['axis'][0]]) offsets=(shapely.get_coordinates(removed)-candidate['origin'])@normal if np.max(abs(offsets))>.7: return False,dict(reason='ancestral-paint-outside-measurement') passed,evidence=validate_removed(old,new,candidate,readers) return passed,dict(reason='fixed-observation-footprint',views=evidence) def committed(self,ids,current_before,geometry,features): inherited=self.inherited(ids,current_before,geometry) complete=shapely.union_all([inherited]+[geometry(f) for f in features]) for i in ids:self.footprints.pop(i,None) for f in features: # A split transfers only the local footprint to each child. Its # preservation was checked jointly before the transaction committed. self.footprints[f['id']]=complete.intersection(geometry(f).buffer(POLICY['max_join_gap_m']))