From 3c02e3ba097fa4139d2d3465e56c9fb4c031cd52 Mon Sep 17 00:00:00 2001 From: Jelle Raaijmakers Date: Mon, 2 Oct 2023 22:29:34 +0200 Subject: [PATCH] Maps: Pad grid size to prevent missing tiles Previously, we would divide the widget width and height by the tile size and round up, which did not result in enough tiles to cover the entire widget. Although this calculation is correct if you starting drawing tiles in the top left corner, we have an additional offset to account for. Now, we take the number of tiles that fit in the widget completely and pad it with 2 tiles to account for the partial left/right and top/bottom sides. An additional tile is added to account for the iterator translating by width / 2, which rounds down again. The resulting tile rects are always intersected with the widget dimensions, so even if we're generating more tile coordinates than strictly necessary, we're not performing the actual download or draw operations. --- Userland/Applications/Maps/MapWidget.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Userland/Applications/Maps/MapWidget.cpp b/Userland/Applications/Maps/MapWidget.cpp index cda31d44c6..d5cdd75141 100644 --- a/Userland/Applications/Maps/MapWidget.cpp +++ b/Userland/Applications/Maps/MapWidget.cpp @@ -438,10 +438,11 @@ void MapWidget::paint_map(GUI::Painter& painter) double offset_x = (longitude_to_tile_x(m_center.longitude, m_zoom) - center_tile_x) * TILE_SIZE; double offset_y = (latitude_to_tile_y(m_center.latitude, m_zoom) - center_tile_y) * TILE_SIZE; - // Draw grid around center tile - int grid_width = (width() + TILE_SIZE - 1) / TILE_SIZE; - int grid_height = (height() + TILE_SIZE - 1) / TILE_SIZE; - for (auto const delta : CenterOutwardsIterable { grid_width + 1, grid_height + 1 }) { + // Draw grid around center tile; always pad the dimensions with 2 tiles for left/right and top/bottom edges + // plus one additional tile to account for the width() / 2 in CenterOutwardsIterable. + int grid_width = width() / TILE_SIZE + 3; + int grid_height = height() / TILE_SIZE + 3; + for (auto const delta : CenterOutwardsIterable { grid_width, grid_height }) { int tile_x = center_tile_x + delta.x(); int tile_y = center_tile_y + delta.y();