24 lines
1.4 KiB
Python
24 lines
1.4 KiB
Python
"""Offline sanity check: intersection membership must match membership in both solids."""
|
|
import argparse,json,random,sys
|
|
from pathlib import Path
|
|
ROOT=Path(__file__).resolve().parents[1];sys.path.insert(0,str(ROOT))
|
|
from scripts.compare_geometry import centered,flat_geometry
|
|
from build123d import import_step,Rot
|
|
|
|
def audit(metric,samples=2048):
|
|
ref,_=centered(import_step(metric['reference_file']));actual,_=centered(import_step(metric['candidate_file']))
|
|
actual=flat_geometry(Rot(*metric['best_rotation_xyz_degrees'])*actual); common=actual&ref
|
|
box=ref.bounding_box(); rng=random.Random(714)
|
|
mismatches=[];shared=0
|
|
for _ in range(samples):
|
|
p=[a+rng.random()*s for a,s in zip(box.min,box.size)]
|
|
expected=ref.is_inside(p) and actual.is_inside(p); observed=bool(common and common.is_inside(p))
|
|
shared+=int(expected)
|
|
if expected!=observed:mismatches.append(p)
|
|
return {'samples':samples,'shared_material_samples':shared,'mismatch_count':len(mismatches),'mismatch_examples':mismatches[:10],'sanity_check_passed':not mismatches,'limitation':'Fixed random sample detects some Boolean inconsistencies; a pass is not proof of metric accuracy.'}
|
|
|
|
if __name__=='__main__':
|
|
p=argparse.ArgumentParser();p.add_argument('metrics',type=Path);p.add_argument('--output',type=Path,required=True);a=p.parse_args()
|
|
data=json.loads(a.metrics.read_text()); result={k:audit(v) for k,v in data.items()}
|
|
a.output.write_text(json.dumps(result,indent=2));print(json.dumps(result))
|