commit 3db50cefe0557befb6d30a60204e851961a6cd2c
parent 538b9dc79c3601ec979a8bbdb9a786f8f3148f5e
Author: Daniel Barlow <dan@telent.net>
Date: Tue, 17 Mar 2026 13:47:45 +0000
add bounds.to-pixels method
Diffstat:
1 file changed, 10 insertions(+), 13 deletions(-)
diff --git a/pkgs/maps/main.fnl b/pkgs/maps/main.fnl
@@ -157,6 +157,10 @@ label.readout {
:x (/ (+ min-tile-x max-tile-x 1) 2)
:y (/ (+ min-tile-y max-tile-y 1) 2)
}
+ :to-pixels (fn [tile-x tile-y]
+ (values (* tile-size (- tile-x min-tile-x))
+ (* tile-size (- tile-y min-tile-y))))
+
}))
(define-tests
@@ -199,12 +203,9 @@ label.readout {
(fn cairo-road-path [g [[sx sy] & points] bounds]
(let [min bounds.min
{ : line_to } g]
- (g:move_to (* tile-size (- sx min.x))
- (* tile-size (- sy min.y)))
+ (g:move_to (bounds.to-pixels sx sy))
(each [_ [x y] (ipairs points)]
- (let [x1 (* tile-size (- x min.x))
- y1 (* tile-size (- y min.y))]
- (line_to g x1 y1)))))
+ (line_to g (bounds.to-pixels x y)))))
(fn cairo-roads [g lines bounds]
(g:set_source_rgb 0 0 0)
@@ -222,15 +223,12 @@ label.readout {
(g:set_source_rgba 0.8 0 0 0.5)
(each [_ track (pairs tracks)]
(g:set_line_width 10)
- (let [min bounds.min
- xypoints (tile-xy-for-track track app-state.zoom)
+ (let [xypoints (tile-xy-for-track track app-state.zoom)
[sx sy] (. xypoints 1)
{ : line_to } g]
- (g:move_to (* tile-size (- sx min.x)) (* tile-size (- sy min.y)))
+ (g:move_to (bounds.to-pixels sx sy))
(each [_ [x y] (ipairs xypoints)]
- (let [x1 (* tile-size (- x min.x))
- y1 (* tile-size (- y min.y))]
- (line_to g x1 y1))))
+ (line_to g (bounds.to-pixels x y))))
(g:stroke)))
@@ -295,8 +293,7 @@ label.readout {
w ext.width
h ext.height]
(when (and tx ty (not (. seen-road-names n)))
- (let [x (* tile-size (- tx bounds.min.x))
- y (* tile-size (- ty bounds.min.y))]
+ (let [(x y) (bounds.to-pixels tx ty)]
(tset seen-road-names n true)
(g:save)