Something went wrong. Try again.
HEXWORK - A Lantern in the Deep: 3D ASCII terminal roguelike RPG in Rust.
Entirely designed and built by Muse Spark 1.3 to evaluate if I like the model.
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344#!/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.rsPi is a fixed, independently published decimal constant, not host libm output.Taylor series in [0, pi/2], at 70 decimal fixed-point digits, then quadrantreflection gives reproducible rounded 1e9 unit vectors on every Python host."""SCALE = 10**70PI = 314159265358979323846264338327950288419716939937510582097494459230781640628620899# PI above is floor(pi * 10**80).PI_FIXED = PI // 10**10UNIT = 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] == UNITassert quarter[512] == 707106781vectors = []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('];')