"""Joint line / circular-fillet geometry with exact shared junctions. No scene coordinates or class masks are embedded in this module. Fillets are constructed from the same line intersections used by both adjacent straights; there is no independently movable arc endpoint. Image evidence is an adapter. """ import numpy as np def unit(v): v=np.asarray(v,float) return v/max(float(np.linalg.norm(v)),1e-12) def line_intersection(origin_a,axis_a,origin_b,axis_b): a=np.column_stack([axis_a,-np.asarray(axis_b)]) if abs(np.linalg.det(a))<1e-5:return None t=np.linalg.solve(a,np.asarray(origin_b)-origin_a) return np.asarray(origin_a)+t[0]*np.asarray(axis_a) def fillet(previous,vertex,following,radius): p,x,q=map(lambda a:np.asarray(a,float),(previous,vertex,following)) u=unit(p-x);v=unit(q-x);half=np.arccos(np.clip(u@v,-1,1))/2 if radius<=1e-5 or half<.03 or half>np.pi/2-.01: return dict(kind='corner',start=x,end=x,vertex=x,radius=0.) reach=float(radius/np.tan(half)) start=x+reach*u;end=x+reach*v;center=x+unit(u+v)*radius/np.sin(half) a=np.arctan2(*(start-center)[::-1]);b=np.arctan2(*(end-center)[::-1]);sweep=(b-a+np.pi)%(2*np.pi)-np.pi return dict(kind='arc',start=start,end=end,center=center,radius=float(radius),angle=a,sweep=sweep,vertex=x,reach=reach) def build_chain(vertices,radii): vertices=np.asarray(vertices,float);radii=np.asarray(radii,float) if len(vertices)<2 or len(radii)!=max(0,len(vertices)-2):raise ValueError('One radius per internal vertex is required') if not np.isfinite(vertices).all() or not np.isfinite(radii).all() or (radii<0).any():raise ValueError('Finite vertices and nonnegative radii required') turns=[fillet(*vertices[i-1:i+2],radii[i-1]) for i in range(1,len(vertices)-1)] # Overlapping trims are a rejected hypothesis, never an implicit connector. for i in range(len(vertices)-1): start=vertices[0] if i==0 else turns[i-1]['end'] end=vertices[-1] if i==len(vertices)-2 else turns[i]['start'] if (end-start)@(vertices[i+1]-vertices[i]) < -1e-7:raise ValueError('Fillets overlap on a straight approach') primitives=[] for i in range(len(vertices)-1): a=vertices[0] if i==0 else turns[i-1]['end'];b=vertices[-1] if i==len(vertices)-2 else turns[i]['start'] primitives.append(dict(kind='line',start=a,end=b)) if i b. Keep distant anchors fixed and rebuild only the terminal neighbourhood. Opposing or backward chains are rejected. """ from scipy.interpolate import CubicHermiteSpline from shapely.geometry import LineString from plan_continuity import resample,distances a,b=resample(np.asarray(a,float),step),resample(np.asarray(b,float),step) gap=float(np.linalg.norm(a[-1,:2]-b[0,:2])) if not 1e-51.3*length:return None return joined,curve,gap def competing_fragment(fragment,reference,max_length=8.,max_distance=3.): """Nominate a short detached parallel alternative for a review layer. This is an ambiguity test, not a semantic deletion rule. Keep nominated geometry available: a real narrow island can have the same 2D signature. """ from shapely.geometry import LineString,Point from plan_continuity import resample p=resample(np.asarray(fragment,float),.25)[:,:2];line=LineString(p);ref=LineString(np.asarray(reference)[:,:2]) if line.is_ring or not 0max_distance:return False projected=np.array([ref.project(Point(q))for q in p]);span=abs(projected[-1]-projected[0]) return bool(.8*line.length=-.05).all()or .8*line.length