elm_gun: single aim computation, explicit deg/rad fire boundary + test

predictAim folded the learned correction into the bearing and derived x/y
once instead of recomputing them per branch. New gunAimErrorDeg carries the
degree unit in its name so the FireSlopDeg comparison cannot fall back to the
old degrees-vs-radians mix-up; test_online.nim adds a regression block for it.
This commit is contained in:
2026-10-06 19:54:25 +02:00
parent 6bec6a41cd
commit eb7f750a3f
2 changed files with 46 additions and 10 deletions
@@ -71,6 +71,23 @@ block:
check("pending cleared", g.pending.len == 0)
check("trace cleared", g.traceTick.len == 0)
# ── 6. deg/rad fire boundary (regression: the FireSlopDeg mix-up) ───────────
block:
echo "test 6: gun-aim error is DEGREES at the fire boundary"
# aim 0 rad = east; gun at +1 deg -> short-way error -1 deg, NOT -0.0175.
check("1 deg off gives a -1 deg error",
abs(gunAimErrorDeg(0.0, 1.0) + 1.0) < 1e-9, $gunAimErrorDeg(0.0, 1.0))
# short way round: gun 350 deg from an east(0) aim is +10 deg to reach it.
check("350 deg wraps to +10 deg",
abs(gunAimErrorDeg(0.0, 350.0) - 10.0) < 1e-6, $gunAimErrorDeg(0.0, 350.0))
# THE historical bug: a degree error compared against degToRad(FireSlopDeg)
# (radians) admitted only 0.052 deg. At exactly FireSlopDeg degrees off, the
# degrees-vs-degrees predicate admits the shot; the radian mix-up rejects it.
const slop = 1.0'f64
let err = gunAimErrorDeg(0.0, slop) # exactly `slop` degrees off
check("|err| <= FireSlopDeg admits the boundary", abs(err) <= slop, $err)
check("the radian mix-up would REJECT it", abs(err) > degToRad(slop), $err)
if failed > 0:
echo "\n", failed, " check(s) FAILED"
quit(1)