Run clippy

This commit is contained in:
Maximilian Ammann 2022-03-27 15:07:36 +02:00
parent e462784785
commit 6b81f097b7
17 changed files with 73 additions and 90 deletions

View File

@ -77,7 +77,7 @@ pub fn extract<P: AsRef<Path>, R: AsRef<Path>>(
])?;
while let Ok(Some(tile)) = tiles_rows.next() {
extract_tile(&tile, &output_path)?;
extract_tile(tile, &output_path)?;
}
Ok(())

View File

@ -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};

View File

@ -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 }
}
}

View File

@ -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,

View File

@ -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 {

View File

@ -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);
}
}

View File

@ -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)
);
}

View File

@ -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),
}

View File

@ -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<Vector2<f64>>,
translate_delta: Vector3<f64>,
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,
}
}

View File

@ -251,6 +251,7 @@ impl IOScheduler {
}
}
#[derive(Default)]
pub struct TileRequestState {
current_id: TileRequestID,
pending_tile_requests: HashMap<TileRequestID, TileRequest>,

View File

@ -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 {

View File

@ -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<WorldTileCoords, Vec<LayerResult>>,
index: BTreeMap<Quadkey, Vec<LayerResult>>,
}
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<LayerResult> {
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<String>,
) {
if let Some(results) = self.index.get(coords) {
if let Some(results) = self.index.get(&coords.build_quad_key()) {
let tessellated_set: HashSet<String> = 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<String>) -> 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())

View File

@ -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<Q: Queue<B>, B, V: bytemuck::Pod, I: bytemuck::Pod, TM: bytemuck::Pod, FM:
style_layer: StyleLayer,
geometry: &OverAlignedVertexBuffer<V, I>,
tile_metadata: TM,
feature_metadata: &Vec<FM>,
feature_metadata: &[FM],
) {
let vertices_stride = size_of::<V>() as wgpu::BufferAddress;
let indices_stride = size_of::<I>() as wgpu::BufferAddress;
@ -222,8 +221,7 @@ impl<Q: Queue<B>, 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<IndexEntry>> {
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<IndexEntry>> {
@ -428,12 +426,10 @@ impl RingIndex {
loop {
if let Some(entries) = self.get_layers(&current) {
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));

View File

@ -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::<f32>()
.expect("Unable to cast view projection to f32")
.into()
}
}
@ -59,7 +57,6 @@ impl ModelViewProjection {
self.0
.cast::<f32>()
.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<Point2<f64>> = None;
let mut max: Option<Point2<f64>> = 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<f64> = 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);

View File

@ -1,4 +1,4 @@
use cgmath::num_traits::Pow;
use cgmath::Matrix4;
use std::collections::HashSet;
use std::default::Default;

View File

@ -1,3 +1,4 @@
#![allow(clippy::identity_op)]
use wgpu::{
ColorTargetState, Device, FragmentState, ShaderModule, VertexBufferLayout, VertexState,
};

View File

@ -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;