diff --git a/pkgs/maps/main.fnl b/pkgs/maps/main.fnl index 18a98b6..e0077f0 100644 --- 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