Compare commits
2 Commits
c56943e6e1
...
1608d26260
Author | SHA1 | Date | |
---|---|---|---|
1608d26260 | |||
ca02f5c4fa |
@ -211,6 +211,24 @@ label.readout {
|
|||||||
(when (not (. tbl k))
|
(when (not (. tbl k))
|
||||||
(tiles.fetch cq x y zoom #(tset tbl k $1)))))))
|
(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 (+ rad circle))
|
||||||
|
(> 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]
|
(fn draw-onto-map-surface [surface bounds zoom]
|
||||||
(let [{ : num-tiles-x : num-tiles-y } bounds
|
(let [{ : num-tiles-x : num-tiles-y } bounds
|
||||||
road-width 14
|
road-width 14
|
||||||
@ -228,7 +246,7 @@ label.readout {
|
|||||||
(g:fill)
|
(g:fill)
|
||||||
|
|
||||||
(g:translate (+ (// bounds.pixels.x 2)) (+ (// bounds.pixels.y 2)))
|
(g:translate (+ (// bounds.pixels.x 2)) (+ (// bounds.pixels.y 2)))
|
||||||
(g:rotate (* (/ (- app-state.orientation-target) 180) math.pi))
|
(g:rotate (deg->rad (- app-state.orientation-target)))
|
||||||
(g:translate (- (// bounds.pixels.x 2)) (- (// bounds.pixels.y 2)))
|
(g:translate (- (// bounds.pixels.x 2)) (- (// bounds.pixels.y 2)))
|
||||||
|
|
||||||
(cairo-roads g lines bounds)
|
(cairo-roads g lines bounds)
|
||||||
@ -248,7 +266,13 @@ label.readout {
|
|||||||
|
|
||||||
(g:save)
|
(g:save)
|
||||||
(g:move_to x y)
|
(g:move_to x y)
|
||||||
(g:rotate angle)
|
|
||||||
|
(let [theta (clamp-angle
|
||||||
|
(- angle (deg->rad app-state.orientation-target)))]
|
||||||
|
(if (and (> theta 0) (< theta math.pi))
|
||||||
|
(g:rotate (- angle (/ math.pi 2)))
|
||||||
|
(g:rotate (- angle (* math.pi 1.5)))))
|
||||||
|
|
||||||
(g:rel_move_to (- (// w 2)) 3)
|
(g:rel_move_to (- (// w 2)) 3)
|
||||||
(g:text_path n)
|
(g:text_path n)
|
||||||
(g:fill)
|
(g:fill)
|
||||||
|
@ -77,7 +77,7 @@
|
|||||||
(set biggest-n (- i 1)))))
|
(set biggest-n (- i 1)))))
|
||||||
(let [[x y] (. points biggest-n)
|
(let [[x y] (. points biggest-n)
|
||||||
[nx ny] (. points (+ 1 biggest-n))
|
[nx ny] (. points (+ 1 biggest-n))
|
||||||
angle (math.atan (- ny y) (- nx x))]
|
angle (math.atan (- nx x) (- y ny))]
|
||||||
[(/ (+ nx x) 2) (/ (+ ny y) 2) angle]))
|
[(/ (+ nx x) 2) (/ (+ ny y) 2) angle]))
|
||||||
|
|
||||||
|
|
||||||
@ -92,7 +92,6 @@
|
|||||||
(icollect [_ nd (ipairs e.nodes)]
|
(icollect [_ nd (ipairs e.nodes)]
|
||||||
(let [node (. nodes nd)
|
(let [node (. nodes nd)
|
||||||
(tx ty) (latlon->tile node.lat node.lon zoom)]
|
(tx ty) (latlon->tile node.lat node.lon zoom)]
|
||||||
;;(print e.tags.name e.id e.name node.lat node.lon)
|
|
||||||
[ tx ty ]))]
|
[ tx ty ]))]
|
||||||
(tset
|
(tset
|
||||||
lines
|
lines
|
||||||
|
Loading…
Reference in New Issue
Block a user