commit 1608d2626061ec81251e67eab55730355edb4544
parent ca02f5c4fa2d50cede60a1c683c1c2db551c8597
Author: Daniel Barlow <dan@telent.net>
Date: Wed, 2 Jul 2025 22:22:32 +0100
draw road labels always left->right
Diffstat:
2 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/pkgs/maps/main.fnl b/pkgs/maps/main.fnl
@@ -217,7 +217,7 @@ label.readout {
(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 math.pi) (clamp-angle (- rad circle))
rad)))
@@ -246,7 +246,7 @@ label.readout {
(g:fill)
(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)))
(cairo-roads g lines bounds)
@@ -266,7 +266,13 @@ label.readout {
(g:save)
(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:text_path n)
(g:fill)
diff --git a/pkgs/maps/tiles.fnl b/pkgs/maps/tiles.fnl
@@ -77,7 +77,7 @@
(set biggest-n (- i 1)))))
(let [[x y] (. points 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]))
@@ -92,8 +92,7 @@
(icollect [_ nd (ipairs e.nodes)]
(let [node (. nodes nd)
(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
lines
e.id