diff --git a/pkgs/maps/main.fnl b/pkgs/maps/main.fnl index e0077f0..93839d5 100644 --- a/pkgs/maps/main.fnl +++ b/pkgs/maps/main.fnl @@ -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,8 +266,31 @@ label.readout { (g:save) (g:move_to x y) - (g:rotate angle) - (g:rel_move_to (- (// w 2)) 3) + + ;; we are rendering the map rotated by -orientation. + ;; the road angles are against north. + + ;; if orientation = 30 then rotation is -30 + ;; if the road angle is 70 then + + + + + ;; when the map is pointing north, an angle 0 < n < 180 + ;; will be pointing rightwards + + ;; when the orientation is 30 degrees, the map is pointing + ;; -30 degrees, so an angle 30 < n < (+ 180 30) is rightwards + + (let [theta (clamp-angle (+ angle (deg->rad app-state.orientation-target)))] + (if (and (> theta 0) (< theta math.pi)) + (do + (g:rotate (- angle)) + (g:rel_move_to (- (// w 2)) 3)) + (do + (g:rotate angle) + (g:rel_move_to (+ (// w 2)) 3)))) + (g:text_path n) (g:fill) (g:restore)))))) diff --git a/pkgs/maps/tiles.fnl b/pkgs/maps/tiles.fnl index 0c8f42f..285aa00 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 (- y ny) (- nx x))] [(/ (+ nx x) 2) (/ (+ ny y) 2) angle]))