diff --git a/src/geopos.rs b/src/geopos.rs index 6d61819..cabcac4 100644 --- a/src/geopos.rs +++ b/src/geopos.rs @@ -1,6 +1,8 @@ use bevy::prelude::*; use std::f32::consts::PI; +use crate::tilemap::TileCoord; + /** * Geo-position on the (OSM-) world map (GPS position) * @@ -25,11 +27,11 @@ impl GeoPos { * @param zoom Zoom level of the OSM tile-name(x/y) system * @return coordinate in tile coordinates */ - pub fn to_tile_coordinates(self, zoom: u8) -> Vec2 { + pub fn to_tile_coordinates(self, zoom: u8) -> TileCoord { let pow_zoom = 2_u32.pow(zoom.into()) as f32; // return - Vec2 { + TileCoord(Vec2 { // Longitude, (Längengrad) West/East "index" x: ((self.lon + 180.) / 360. * pow_zoom), @@ -40,6 +42,6 @@ impl GeoPos { * pow_zoom), // The Nort/South y tile name part is not linear, the tiles gets stretched to the poles // to compensate the stretching if the stretching of the West/East projection - } + }) } } diff --git a/src/lib.rs b/src/lib.rs index 5d0ca9d..524da9e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,6 +14,7 @@ use bevy_screen_diagnostics::{ use geopos::GeoPos; use http_assets::HttpAssetReaderPlugin; use sun::Sky; +use tilemap::TileCoord; type TileMap = tilemap::TileMap<8145>; @@ -99,7 +100,7 @@ fn setup( if let Some((lat, lon)) = lat.zip(lon) { let pos = GeoPos { lat, lon }; - Vec2 { x, y } = pos.to_tile_coordinates(15); + TileCoord(Vec2 { x, y }) = pos.to_tile_coordinates(15); } commands.spawn(( diff --git a/src/tilemap.rs b/src/tilemap.rs index b1de7d4..2d3c710 100644 --- a/src/tilemap.rs +++ b/src/tilemap.rs @@ -191,3 +191,6 @@ impl TileMap { Transform::from_xyz(pos.x, 0., pos.y) } } + +/// A coordinate in the tile coordinate system. Allows for positions within a tile. +pub struct TileCoord(pub Vec2);