mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-17 23:39:18 +02:00
The dumb3d->glm / utilities-simplification refactor replaced the old custom clamp() (which tolerated Lo>Hi, returning the upper bound) with std::clamp, where inverted bounds are undefined behaviour. Only a few sites were patched afterwards, by hand, with std::minmax plumbing (incl. a stray `static` inside a per-axle loop). Others silently produced wrong results in the AI braking / acceleration path. Add a safe_clamp() helper (normalizes inverted bounds) and use it ONLY where Lo<=Hi cannot be proven at compile time (config min/max pairs, sign-dependent expressions, container underflow). Sites with constant bounds or [0, x>=0] keep std::clamp. Remove the manual std::minmax workarounds and rewrite the damaged-track jolt code value-first.