From 1608d2626061ec81251e67eab55730355edb4544 Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Wed, 2 Jul 2025 22:22:32 +0100 Subject: [PATCH] draw road labels always left->right --- pkgs/maps/main.fnl | 12 +++++++++--- pkgs/maps/tiles.fnl | 5 ++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/pkgs/maps/main.fnl b/pkgs/maps/main.fnl index e0077f0..59c09d8 100644 --- 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 index 0c8f42f..ace01ef 100644 --- 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