From d6eaee23ecfe84a64f1ba8000f85dd70a659d4ac Mon Sep 17 00:00:00 2001 From: frederic wagner Date: Fri, 30 Jun 2023 11:10:49 +0200 Subject: [PATCH] gipy: fixing tile_is_on_screen previous algorithm was incorrect --- apps/gipy/ChangeLog | 1 + apps/gipy/app.js | 58 +++++++++++++++++++++++++++------------------ 2 files changed, 36 insertions(+), 23 deletions(-) diff --git a/apps/gipy/ChangeLog b/apps/gipy/ChangeLog index 6371fbdf1..8646ba11a 100644 --- a/apps/gipy/ChangeLog +++ b/apps/gipy/ChangeLog @@ -86,3 +86,4 @@ * Display path in leaflet * Reduce framerate if locked * Stroke to move around in the map + * Fix for missing paths in display diff --git a/apps/gipy/app.js b/apps/gipy/app.js index 94f9ab450..ddd1a2c08 100644 --- a/apps/gipy/app.js +++ b/apps/gipy/app.js @@ -1,4 +1,4 @@ -let simulated = false; +let simulated = true; let displaying = false; let in_menu = false; let go_backwards = false; @@ -243,6 +243,7 @@ class Map { let local_y = displayed_y - this.start_coordinates[1]; let tile_x = Math.floor(local_x / this.side); let tile_y = Math.floor(local_y / this.side); + let limit = 1; if (!zoomed) { limit = 2; @@ -266,6 +267,18 @@ class Map { sin_direction ) ) { +// let colors = [ +// [0, 0, 0], +// [0, 0, 1], +// [0, 1, 0], +// [0, 1, 1], +// [1, 0, 0], +// [1, 0, 1], +// [1, 1, 0], +// [1, 1, 0.5], +// [0.5, 0, 0.5], +// [0, 0.5, 0.5], +// ]; if (this.color[0] == 1 && this.color[1] == 0 && this.color[2] == 0) { this.display_thick_tile( x, @@ -301,33 +314,32 @@ class Map { cos_direction, sin_direction ) { - let center_x = g.getWidth() / 2; - let center_y = g.getHeight() / 2 + Y_OFFSET; + let width = g.getWidth(); + let height = g.getHeight(); + let center_x = width / 2; + let center_y = height / 2 + Y_OFFSET; let side = this.side; - let x1 = tile_x * side; - let y1 = tile_y * side; - let x2 = x1 + side; - let y2 = y1 + side; - let scaled_x1 = (x1 - current_x) * scale_factor; - let scaled_y1 = (y1 - current_y) * scale_factor; - let rotated_x1 = scaled_x1 * cos_direction - scaled_y1 * sin_direction; - let rotated_y1 = scaled_x1 * sin_direction + scaled_y1 * cos_direction; - let scaled_x2 = (x2 - current_x) * scale_factor; - let scaled_y2 = (y2 - current_y) * scale_factor; - let rotated_x2 = scaled_x2 * cos_direction - scaled_y2 * sin_direction; - let rotated_y2 = scaled_x2 * sin_direction + scaled_y2 * cos_direction; + let tile_center_x = (tile_x + 0.5) * side; + let tile_center_y = (tile_y + 0.5) * side; + let scaled_center_x = (tile_center_x - current_x) * scale_factor; + let scaled_center_y = (tile_center_y - current_y) * scale_factor; + let rotated_center_x = scaled_center_x * cos_direction - scaled_center_y * sin_direction; + let rotated_center_y = scaled_center_x * sin_direction + scaled_center_y * cos_direction; + let on_screen_center_x = center_x - rotated_center_x; + let on_screen_center_y = center_y + rotated_center_y; - if (center_x < rotated_x1 && center_x < rotated_x2) { - return false; - } - if (-center_x > rotated_x1 && -center_x > rotated_x2) { - return false; - } + let scaled_side = side * scale_factor; - if (center_y < rotated_y1 && center_y < rotated_y2) { + if (on_screen_center_x + scaled_side <= 0) { return false; } - if (-center_y > rotated_y1 && -center_y > rotated_y2) { + if (on_screen_center_x - scaled_side >= width) { + return false; + } + if (on_screen_center_y + scaled_side <= 0) { + return false; + } + if (on_screen_center_y - scaled_side >= height) { return false; } return true;