biscuit

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit ca02f5c4fa2d50cede60a1c683c1c2db551c8597
parent c56943e6e12da3bd98dd7824a5901bac42da348f
Author: Daniel Barlow <dan@telent.net>
Date:   Tue,  1 Jul 2025 13:27:13 +0100

clamp angle to -pi..pi

Diffstat:
Mpkgs/maps/main.fnl | 18++++++++++++++++++
1 file changed, 18 insertions(+), 0 deletions(-)

diff --git a/pkgs/maps/main.fnl b/pkgs/maps/main.fnl @@ -211,6 +211,24 @@ label.readout { (when (not (. tbl k)) (tiles.fetch cq x y zoom #(tset tbl k $1))))))) +;; iso 9899:1999 says +;; "The atan2 functions return arctan y/x in the interval [−π , +π ] radians" + +(fn clamp-angle [rad] + (let [circle (* 2 math.pi)] + (if + (< rad (- math.pi)) (clamp-angle (+ circle rad)) + (> rad math.pi) (clamp-angle (- rad circle)) + rad))) + +(define-tests :clamp-angle + (expect= (clamp-angle 2) 2) + (expect= (clamp-angle (+ (* 4 math.pi) 2)) 2) + (expect= (clamp-angle (- 2 (* 4 math.pi))) 2)) + +(fn deg->rad [deg] + (* math.pi (/ deg 180))) + (fn draw-onto-map-surface [surface bounds zoom] (let [{ : num-tiles-x : num-tiles-y } bounds road-width 14