#!/usr/bin/env python3
"""M2 selected transform controls; never a membership certificate."""
import json, math
from pathlib import Path
p=Path(__file__).with_name('membership-transform-evidence.json')
d=json.loads(p.read_text())
def world(row, local, mirrored):
    x,y=local
    if mirrored:x=-x
    a=math.radians(row['rotation_deg']);c,s=math.cos(a),math.sin(a)
    return [row['center'][0]+c*x-s*y,row['center'][1]+s*x+c*y]
for row in d['controls']:
    for i in (1,2):
        l=row[f'local_p{i}'];sv=row['svg_named_world_approx'][i-1]
        a=world(row,l,True);b=world(row,l,False)
        out={'ref':row['ref'],'pad':f'P{i}','net':row['nets'][i-1],
             'hypothesis_R_M_local':a,'hypothesis_R_local':b,
             'SVG_named_approx':sv,'distance_R_M_to_SVG_mm':math.dist(a,sv),
             'distance_R_to_SVG_mm':math.dist(b,sv)}
        if 'historical_world' in row:
            out['historical_world']=row['historical_world'][i-1]
            assert math.dist(a,out['historical_world'])<1e-6
        print(json.dumps(out))
print('No hypothesis adopted: named SVG pads and trace/net controls conflict; obtain authoritative current world-space terminal polygons.')
print('Coverage:',json.dumps(d['coverage']))
print('NOT PERFORMED: active complete graph / connected components / all-terminal or singleton certification.')
