#!/usr/bin/env python3 """Print the canonical Rust heading table; integer arithmetic only. Run: python3 scripts/generate-heading-table.py > crates/hexwork-core/src/heading_table.rs Pi is a fixed, independently published decimal constant, not host libm output. Taylor series in [0, pi/2], at 70 decimal fixed-point digits, then quadrant reflection gives reproducible rounded 1e9 unit vectors on every Python host. """ SCALE = 10**70 PI = 314159265358979323846264338327950288419716939937510582097494459230781640628620899 # PI above is floor(pi * 10**80). PI_FIXED = PI // 10**10 UNIT = 10**9 def nearest(n, d): return (n + d // 2) // d if n >= 0 else -((-n + d // 2) // d) def sine(angle): term = angle total = term k = 1 while term: term = -nearest(term * angle * angle, SCALE * SCALE * (2*k) * (2*k+1)) total += term k += 1 return nearest(total * UNIT, SCALE) quarter = [sine(nearest(PI_FIXED * i, 2048)) for i in range(1025)] assert quarter[0] == 0 and quarter[1024] == UNIT assert quarter[512] == 707106781 vectors = [] for heading in range(4096): quadrant, offset = divmod(heading, 1024) s, c = quarter[offset], quarter[1024-offset] vectors.append(((s, -c), (c, s), (-s, c), (-c, -s))[quadrant]) print('// @generated by scripts/generate-heading-table.py; do not edit.') print('pub(super) const UNIT_VECTORS: [[i64; 2]; 4096] = [') for x, y in vectors: print(f' [{x}, {y}],') print('];')