main
John Lauer Land and record reviewed diode vias; reject colliding heatsink mounting pattern f197072
"""Audit the exact six documented native nanometre rounding differences, not a general tolerance bypass."""
import json
import math
from pathlib import Path

root = Path(__file__).resolve().parents[1]
source = root / 'design/diode-thermal-live/saved-comparison.json'
report = json.loads(source.read_text())
assert not report['copperMultisetEqual']
assert len(report['missing']) == len(report['extra']) == 6
remaining = list(report['extra'])
pairs = []
for old, count in report['missing']:
    assert count == 1 and old[0:2] == ['via', 'LOAD_POS'] and old[3:] == [.6, .3]
    match = min(remaining, key=lambda row: math.dist(old[2], row[0][2]))
    new, new_count = match
    assert new_count == 1 and old[:2] == new[:2] and old[3:] == new[3:]
    delta = math.dist(old[2], new[2])
    assert delta <= 1.415e-6  # at most one native nanometre on each axis
    pairs.append({'candidateMm': old[2], 'savedMm': new[2], 'distanceNm': delta * 1e6})
    remaining.remove(match)
assert not remaining and report['zoneKeysEqual']
assert max(report['zoneSymmetricDifferenceMm2'].values()) < 1e-6
result = {
    'status': 'documented-native-rounding-only',
    'candidateSha256': report['candidateSha256'], 'savedSha256': report['savedSha256'],
    'exactEquality': False, 'otherTrackViaMultisetDifferences': 0, 'pairs': pairs,
    'zoneSymmetricDifferenceMm2': report['zoneSymmetricDifferenceMm2'],
    'qualification': 'Geometric audit only. Actual saved-board native DRC required; no thermal or hardware qualification.',
}
(source.parent / 'rounding-review.json').write_text(json.dumps(result, indent=2) + '\n')
print(json.dumps(result, indent=2))