From 431cac36f03bd6b37b77e755b2a6624cfafe4b0d Mon Sep 17 00:00:00 2001 From: Piotr Podusowski Date: Tue, 21 Nov 2023 19:46:28 +0100 Subject: [PATCH 1/3] minor docstring --- walkers/src/map.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/walkers/src/map.rs b/walkers/src/map.rs index 9e1c7ae8..cd1a77e7 100644 --- a/walkers/src/map.rs +++ b/walkers/src/map.rs @@ -60,7 +60,7 @@ impl<'a, 'b> Map<'a, 'b> { } } -/// Projects geographical position into screen pixels, suitable for [`egui::Painter`]. +/// Projects geographical position into pixels on the viewport, suitable for [`egui::Painter`]. #[derive(Clone)] pub struct Projector { clip_rect: Rect, @@ -69,6 +69,7 @@ pub struct Projector { } impl Projector { + /// Project `position` into pixels on the viewport. pub fn project(&self, position: Position) -> Vec2 { // Turn that into a flat, mercator projection. let projected_position = position.project(self.memory.zoom.round()); From e0319261a565322005debab1cefcd5d65bc8bb92 Mon Sep 17 00:00:00 2001 From: Piotr Podusowski Date: Tue, 21 Nov 2023 19:57:19 +0100 Subject: [PATCH 2/3] reuse existing type --- walkers/src/mercator.rs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/walkers/src/mercator.rs b/walkers/src/mercator.rs index e207e464..eed01ec1 100644 --- a/walkers/src/mercator.rs +++ b/walkers/src/mercator.rs @@ -58,12 +58,6 @@ impl Position { } } -impl From for (f64, f64) { - fn from(value: Position) -> Self { - (value.lon(), value.lat()) - } -} - /// Location projected on the screen or an abstract bitmap. pub type Pixels = geo_types::Point; @@ -82,10 +76,10 @@ impl PixelsExt for Pixels { /// Size of the tiles used by the services like the OSM. pub(crate) const TILE_SIZE: u32 = 256; -fn mercator_normalized((x, y): (f64, f64)) -> (f64, f64) { +fn mercator_normalized(position: Position) -> (f64, f64) { // Project into Mercator (cylindrical map projection). - let x = x.to_radians(); - let y = y.to_radians().tan().asinh(); + let x = position.lon().to_radians(); + let y = position.lat().to_radians().tan().asinh(); // Scale both x and y to 0-1 range. let x = (1. + (x / PI)) / 2.; From 1d174b83f396892940cbd2900a38c929467e2f5e Mon Sep 17 00:00:00 2001 From: Piotr Podusowski Date: Tue, 21 Nov 2023 20:00:35 +0100 Subject: [PATCH 3/3] no more into() --- walkers/src/mercator.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/walkers/src/mercator.rs b/walkers/src/mercator.rs index eed01ec1..8288822a 100644 --- a/walkers/src/mercator.rs +++ b/walkers/src/mercator.rs @@ -35,7 +35,7 @@ impl Position { /// Project geographical position into a 2D plane using Mercator. pub(crate) fn project(&self, zoom: u8) -> Pixels { - let (x, y) = mercator_normalized((*self).into()); + let (x, y) = mercator_normalized(*self); // Map that into a big bitmap made out of web tiles. let number_of_pixels = 2u32.pow(zoom as u32) * TILE_SIZE; @@ -47,7 +47,7 @@ impl Position { /// Tile this position is on. pub(crate) fn tile_id(&self, zoom: u8) -> TileId { - let (x, y) = mercator_normalized((*self).into()); + let (x, y) = mercator_normalized(*self); // Map that into a big bitmap made out of web tiles. let number_of_tiles = 2u32.pow(zoom as u32);