diff --git a/libs/mbtiles/src/lib.rs b/libs/mbtiles/src/lib.rs index 3e3e46b7..c6544bf0 100644 --- a/libs/mbtiles/src/lib.rs +++ b/libs/mbtiles/src/lib.rs @@ -77,7 +77,7 @@ pub fn extract, R: AsRef>( ])?; while let Ok(Some(tile)) = tiles_rows.next() { - extract_tile(&tile, &output_path)?; + extract_tile(tile, &output_path)?; } Ok(()) diff --git a/libs/vector_tile/src/encoding.rs b/libs/vector_tile/src/encoding.rs index b5c3ec17..99895746 100644 --- a/libs/vector_tile/src/encoding.rs +++ b/libs/vector_tile/src/encoding.rs @@ -5,8 +5,8 @@ use crate::geometry::{ MultiPoint, Point, }; use crate::protos::vector_tile::{ - Tile as ProtoTile, Tile_Feature as ProtoFeature, Tile_GeomType as ProtoGeomType, Tile_GeomType, - Tile_Layer as ProtoLayer, Tile_Value as ProtoValue, + Tile as ProtoTile, Tile_Feature as ProtoFeature, Tile_GeomType, Tile_Layer as ProtoLayer, + Tile_Value as ProtoValue, }; use crate::tile::{Feature, Layer, PropertyValue, Tile}; diff --git a/libs/vector_tile/src/geometry.rs b/libs/vector_tile/src/geometry.rs index 0f45d0c2..9d972407 100644 --- a/libs/vector_tile/src/geometry.rs +++ b/libs/vector_tile/src/geometry.rs @@ -1,5 +1,3 @@ -type Number = i32; - #[derive(Debug, Clone)] pub enum GeometryPoint { Point(Point), @@ -14,22 +12,22 @@ pub struct MultiPoint { #[derive(Debug, Clone)] pub struct Point { - x: Number, - y: Number, + x: i32, + y: i32, } /// Contains relative coordinates to which the cursor is moved #[derive(Debug, Clone)] pub struct MoveTo { - pub x: Number, - pub y: Number, + pub x: i32, + pub y: i32, } /// Contains relative coordinates to which a line is drawn #[derive(Debug, Clone)] pub struct LineTo { - pub x: Number, - pub y: Number, + pub x: i32, + pub y: i32, } #[derive(Debug, Clone)] @@ -58,7 +56,7 @@ pub enum Geometry { } impl Point { - pub(crate) fn new(x: Number, y: Number) -> Self { + pub(crate) fn new(x: i32, y: i32) -> Self { Self { x, y } } } diff --git a/libs/vector_tile/src/grid.rs b/libs/vector_tile/src/grid.rs index f497b99d..a7eb0e3a 100644 --- a/libs/vector_tile/src/grid.rs +++ b/libs/vector_tile/src/grid.rs @@ -5,15 +5,15 @@ pub fn google_mercator() -> Grid { 256, 256, Extent { - minx: -20037508.3427892480, - miny: -20037508.3427892480, - maxx: 20037508.3427892480, - maxy: 20037508.3427892480, + minx: -20037508.342789248, + miny: -20037508.342789248, + maxx: 20037508.342789248, + maxy: 20037508.342789248, }, 3857, Unit::Meters, vec![ - 156543.0339280410, + 156543.033928041, 78271.5169640205, 39135.75848201025, 19567.879241005125, diff --git a/libs/vector_tile/src/tile.rs b/libs/vector_tile/src/tile.rs index ea573a7f..f1dcbee1 100644 --- a/libs/vector_tile/src/tile.rs +++ b/libs/vector_tile/src/tile.rs @@ -1,7 +1,5 @@ -use std::collections::HashMap; - use crate::geometry::Geometry; -use crate::protos::vector_tile::{Tile as ProtoTile, Tile_Layer as ProtoLayer}; +use std::collections::HashMap; #[derive(Debug, Clone)] pub struct Tile { diff --git a/libs/wgsl_validate/src/lib.rs b/libs/wgsl_validate/src/lib.rs index 997dfffe..eb5a1156 100644 --- a/libs/wgsl_validate/src/lib.rs +++ b/libs/wgsl_validate/src/lib.rs @@ -63,7 +63,7 @@ pub fn validate_project_wgsl() { Ok(entry) => { let path = entry.path(); if !path.is_dir() { - match validate_wgsl(&mut validator, &path) { + match validate_wgsl(&mut validator, path) { Ok(_) => {} Err(err) => { let path = path.strip_prefix(&root_dir).unwrap_or(path); @@ -83,7 +83,7 @@ pub fn validate_project_wgsl() { } } Err(error) => { - println!("cargo:warning={}", format!("{:?}", error)); + println!("cargo:warning={:?}", error); exit(1); } } diff --git a/src/coords.rs b/src/coords.rs index 35e1ba9d..004d56c3 100644 --- a/src/coords.rs +++ b/src/coords.rs @@ -140,7 +140,7 @@ impl WorldTileCoords { }) } - pub fn to_quad_key(&self) -> Quadkey { + pub fn build_quad_key(&self) -> Quadkey { let mut key = [0u8; 32]; key[0] = self.z; @@ -428,28 +428,28 @@ mod tests { TileCoords { x: 0, y: 0, z: 1 } .into_world_tile(TileAddressingScheme::TMS) .unwrap() - .to_quad_key(), + .build_quad_key(), new_quad_key_z1(2) ); assert_eq!( TileCoords { x: 0, y: 1, z: 1 } .into_world_tile(TileAddressingScheme::TMS) .unwrap() - .to_quad_key(), + .build_quad_key(), new_quad_key_z1(0) ); assert_eq!( TileCoords { x: 1, y: 1, z: 1 } .into_world_tile(TileAddressingScheme::TMS) .unwrap() - .to_quad_key(), + .build_quad_key(), new_quad_key_z1(1) ); assert_eq!( TileCoords { x: 1, y: 0, z: 1 } .into_world_tile(TileAddressingScheme::TMS) .unwrap() - .to_quad_key(), + .build_quad_key(), new_quad_key_z1(3) ); } diff --git a/src/input/mod.rs b/src/input/mod.rs index a6688b07..8ae5de4d 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -41,7 +41,7 @@ impl InputController { Self { pinch_handler: PinchHandler::new(), pan_handler: PanHandler::new(), - zoom_handler: ZoomHandler::new(speed, zoom_sensitivity), + zoom_handler: ZoomHandler::new(zoom_sensitivity), tilt_handler: TiltHandler::new(speed, sensitivity), shift_handler: ShiftHandler::new(speed, sensitivity), } diff --git a/src/input/zoom_handler.rs b/src/input/zoom_handler.rs index 656b45a0..f7a1a52d 100644 --- a/src/input/zoom_handler.rs +++ b/src/input/zoom_handler.rs @@ -2,16 +2,12 @@ use super::UpdateState; use crate::render::render_state::RenderState; use cgmath::num_traits::Pow; -use cgmath::{Vector2, Vector3, Zero}; +use cgmath::{Vector2, Vector3}; use std::time::Duration; pub struct ZoomHandler { window_position: Option>, - translate_delta: Vector3, - zooming: bool, zoom_delta: f64, - - speed: f64, sensitivity: f64, } @@ -50,13 +46,10 @@ impl UpdateState for ZoomHandler { } impl ZoomHandler { - pub fn new(speed: f64, sensitivity: f64) -> Self { + pub fn new(sensitivity: f64) -> Self { Self { window_position: None, - translate_delta: Vector3::zero(), - zooming: false, zoom_delta: 0.0, - speed, sensitivity, } } diff --git a/src/io/scheduler.rs b/src/io/scheduler.rs index c1e6a963..62d9d0e2 100644 --- a/src/io/scheduler.rs +++ b/src/io/scheduler.rs @@ -251,6 +251,7 @@ impl IOScheduler { } } +#[derive(Default)] pub struct TileRequestState { current_id: TileRequestID, pending_tile_requests: HashMap, diff --git a/src/io/static_tile_fetcher.rs b/src/io/static_tile_fetcher.rs index 14971d1d..95297de9 100644 --- a/src/io/static_tile_fetcher.rs +++ b/src/io/static_tile_fetcher.rs @@ -14,6 +14,7 @@ static TILES: Dir = include_dir!("$OUT_DIR/extracted-tiles"); #[cfg(not(static_tiles))] static TILES: Dir = Dir::new("/path", &[]); +#[derive(Default)] pub struct StaticTileFetcher; impl StaticTileFetcher { diff --git a/src/io/tile_cache.rs b/src/io/tile_cache.rs index 5fd5de4e..e086f1c0 100644 --- a/src/io/tile_cache.rs +++ b/src/io/tile_cache.rs @@ -1,9 +1,10 @@ -use crate::coords::WorldTileCoords; +use crate::coords::{Quadkey, WorldTileCoords}; use crate::io::LayerResult; use std::collections::{btree_map, BTreeMap, HashSet}; +#[derive(Default)] pub struct TileCache { - index: BTreeMap>, + index: BTreeMap>, } impl TileCache { @@ -14,7 +15,7 @@ impl TileCache { } pub fn push(&mut self, result: LayerResult) { - match self.index.entry(result.get_coords()) { + match self.index.entry(result.get_coords().build_quad_key()) { btree_map::Entry::Vacant(entry) => { entry.insert(vec![result]); } @@ -31,7 +32,7 @@ impl TileCache { ) -> Vec { let mut ret = Vec::new(); - if let Some(results) = self.index.get(coords) { + if let Some(results) = self.index.get(&coords.build_quad_key()) { for result in results { if !skip_layers.contains(&result.layer_name().to_string()) { ret.push(result.clone()); @@ -47,7 +48,7 @@ impl TileCache { coords: &WorldTileCoords, layers: &mut HashSet, ) { - if let Some(results) = self.index.get(coords) { + if let Some(results) = self.index.get(&coords.build_quad_key()) { let tessellated_set: HashSet = results .iter() .map(|tessellated_layer| tessellated_layer.layer_name().to_string()) @@ -58,7 +59,7 @@ impl TileCache { } pub fn is_layers_missing(&self, coords: &WorldTileCoords, layers: &HashSet) -> bool { - if let Some(results) = self.index.get(coords) { + if let Some(results) = self.index.get(&coords.build_quad_key()) { let tessellated_set: HashSet<&str> = results .iter() .map(|tessellated_layer| tessellated_layer.layer_name()) diff --git a/src/render/buffer_pool.rs b/src/render/buffer_pool.rs index 2c947389..d5749349 100644 --- a/src/render/buffer_pool.rs +++ b/src/render/buffer_pool.rs @@ -1,4 +1,3 @@ -use std::collections::vec_deque::Iter; use std::collections::{btree_map, BTreeMap, HashSet, VecDeque}; use std::fmt::Debug; use std::marker::PhantomData; @@ -156,7 +155,7 @@ impl, B, V: bytemuck::Pod, I: bytemuck::Pod, TM: bytemuck::Pod, FM: style_layer: StyleLayer, geometry: &OverAlignedVertexBuffer, tile_metadata: TM, - feature_metadata: &Vec, + feature_metadata: &[FM], ) { let vertices_stride = size_of::() as wgpu::BufferAddress; let indices_stride = size_of::() as wgpu::BufferAddress; @@ -222,8 +221,7 @@ impl, B, V: bytemuck::Pod, I: bytemuck::Pod, TM: bytemuck::Pod, FM: queue.write_buffer( &self.feature_metadata.inner, maybe_entry.buffer_feature_metadata.start, - &bytemuck::cast_slice(feature_metadata.as_slice()) - [0..aligned_feature_metadata_bytes as usize], + &bytemuck::cast_slice(feature_metadata)[0..aligned_feature_metadata_bytes as usize], ); self.index.push_back(maybe_entry); } @@ -412,7 +410,7 @@ impl RingIndex { } pub fn get_layers(&self, coords: &WorldTileCoords) -> Option<&VecDeque> { - self.tree_index.get(coords.to_quad_key().as_slice()) + self.tree_index.get(coords.build_quad_key().as_slice()) } pub fn get_layers_fallback(&self, coords: &WorldTileCoords) -> Option<&VecDeque> { @@ -428,12 +426,10 @@ impl RingIndex { loop { if let Some(entries) = self.get_layers(¤t) { return Some(entries); + } else if let Some(parent) = current.get_parent() { + current = parent } else { - if let Some(parent) = current.get_parent() { - current = parent - } else { - return None; - } + return None; } } } @@ -451,8 +447,8 @@ impl RingIndex { } pub fn push_back(&mut self, entry: IndexEntry) { - let key = entry.coords.to_quad_key(); - match self.tree_index.entry(key.clone()) { + let key = entry.coords.build_quad_key(); + match self.tree_index.entry(key) { btree_map::Entry::Vacant(index_entry) => { index_entry.insert(VecDeque::from([entry])); } @@ -539,7 +535,7 @@ mod tests { style_layer.clone(), &data48bytes_aligned, 2, - &vec![], + &[], ); } assert_eq!( @@ -553,7 +549,7 @@ mod tests { style_layer.clone(), &data24bytes_aligned, 2, - &vec![], + &[], ); assert_eq!( 128 - 2 * 48 - 24, @@ -567,7 +563,7 @@ mod tests { style_layer.clone(), &data24bytes_aligned, 2, - &vec![], + &[], ); // appended now at the beginning println!("{:?}", &pool.index); @@ -579,7 +575,7 @@ mod tests { style_layer.clone(), &data24bytes_aligned, 2, - &vec![], + &[], ); println!("{:?}", &pool.index); assert_eq!(0, pool.available_space(BackingBufferType::Vertices)); @@ -590,7 +586,7 @@ mod tests { style_layer.clone(), &data24bytes_aligned, 2, - &vec![], + &[], ); println!("{:?}", &pool.index); assert_eq!(24, pool.available_space(BackingBufferType::Vertices)); @@ -601,7 +597,7 @@ mod tests { style_layer, &data24bytes_aligned, 2, - &vec![], + &[], ); println!("{:?}", &pool.index); assert_eq!(0, pool.available_space(BackingBufferType::Vertices)); diff --git a/src/render/camera.rs b/src/render/camera.rs index ea6de1a2..243d19b5 100644 --- a/src/render/camera.rs +++ b/src/render/camera.rs @@ -1,4 +1,3 @@ -use cgmath::num_traits::Inv; use cgmath::prelude::*; use cgmath::{Matrix4, Point2, Point3, Vector2, Vector3, Vector4}; @@ -40,7 +39,6 @@ impl ViewProjection { self.0 .cast::() .expect("Unable to cast view projection to f32") - .into() } } @@ -59,7 +57,6 @@ impl ModelViewProjection { self.0 .cast::() .expect("Unable to cast view projection to f32") - .into() } } @@ -276,34 +273,32 @@ impl Camera { Vector2::new(self.width, self.height), Vector2::new(0.0, self.height), ] - .map(|point| self.window_to_world_at_ground(&point, &inverted_view_proj)); + .map(|point| self.window_to_world_at_ground(&point, inverted_view_proj)); let mut min: Option> = None; let mut max: Option> = None; - for vector in screen_bounding_box { - if let Some(vector) = vector { - if let Some(current_min) = &mut min { - if vector.x < current_min.x { - current_min.x = vector.x; - } - if vector.y < current_min.y { - current_min.y = vector.y; - } - } else { - min = Some(Point2::new(vector.x, vector.y)) + for vector in screen_bounding_box.into_iter().flatten() { + if let Some(current_min) = &mut min { + if vector.x < current_min.x { + current_min.x = vector.x; } + if vector.y < current_min.y { + current_min.y = vector.y; + } + } else { + min = Some(Point2::new(vector.x, vector.y)) + } - if let Some(current_max) = &mut max { - if vector.x > current_max.x { - current_max.x = vector.x; - } - if vector.y > current_max.y { - current_max.y = vector.y; - } - } else { - max = Some(Point2::new(vector.x, vector.y)) + if let Some(current_max) = &mut max { + if vector.x > current_max.x { + current_max.x = vector.x; } + if vector.y > current_max.y { + current_max.y = vector.y; + } + } else { + max = Some(Point2::new(vector.x, vector.y)) } } @@ -403,7 +398,7 @@ impl Perspective { #[cfg(test)] mod tests { use crate::render::camera::{InvertedViewProjection, ViewProjection}; - use cgmath::{AbsDiffEq, Matrix4, SquareMatrix, Vector2, Vector3, Vector4}; + use cgmath::{AbsDiffEq, Vector2, Vector3, Vector4}; use super::{Camera, Perspective}; @@ -430,14 +425,14 @@ mod tests { let inverted_view_proj: InvertedViewProjection = view_proj.invert(); let world_pos: Vector4 = Vector4::new(0.0, 0.0, 0.0, 1.0); - let clip = view_proj * world_pos; + let clip = view_proj.project(world_pos); let origin_clip_space = view_proj.project(Vector4::new(0.0, 0.0, 0.0, 1.0)); println!("origin w in clip space: {:?}", origin_clip_space.w); println!("world_pos: {:?}", world_pos); println!("clip: {:?}", clip); - println!("world_pos: {:?}", view_proj.invert().unwrap() * clip); + println!("world_pos: {:?}", view_proj.invert().project(clip)); println!("window: {:?}", camera.clip_to_window_vulkan(&clip)); let window = camera.clip_to_window(&clip); diff --git a/src/render/render_state.rs b/src/render/render_state.rs index fee31f09..8ff77fce 100644 --- a/src/render/render_state.rs +++ b/src/render/render_state.rs @@ -1,4 +1,4 @@ -use cgmath::num_traits::Pow; + use cgmath::Matrix4; use std::collections::HashSet; use std::default::Default; diff --git a/src/render/shaders/mod.rs b/src/render/shaders/mod.rs index 5f0fa70a..5061dd6b 100644 --- a/src/render/shaders/mod.rs +++ b/src/render/shaders/mod.rs @@ -1,3 +1,4 @@ +#![allow(clippy::identity_op)] use wgpu::{ ColorTargetState, Device, FragmentState, ShaderModule, VertexBufferLayout, VertexState, }; diff --git a/src/tessellation/layer.rs b/src/tessellation/layer.rs index 229839d8..ef8d93c9 100644 --- a/src/tessellation/layer.rs +++ b/src/tessellation/layer.rs @@ -8,7 +8,6 @@ use lyon::tessellation::geometry_builder::MaxIndex; use lyon::tessellation::{ BuffersBuilder, FillOptions, FillTessellator, StrokeOptions, StrokeTessellator, }; -use lyon_path::traits::SvgPathBuilder; use lyon_path::{FillRule, Path}; use crate::error::Error;