clamp angle to -pi..pi
This commit is contained in:
parent
c56943e6e1
commit
ca02f5c4fa
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user