mirror of
https://github.com/maplibre/maplibre-rs.git
synced 2025-12-08 19:05:57 +00:00
Run clippy
This commit is contained in:
parent
e462784785
commit
6b81f097b7
@ -77,7 +77,7 @@ pub fn extract<P: AsRef<Path>, R: AsRef<Path>>(
|
|||||||
])?;
|
])?;
|
||||||
|
|
||||||
while let Ok(Some(tile)) = tiles_rows.next() {
|
while let Ok(Some(tile)) = tiles_rows.next() {
|
||||||
extract_tile(&tile, &output_path)?;
|
extract_tile(tile, &output_path)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@ -5,8 +5,8 @@ use crate::geometry::{
|
|||||||
MultiPoint, Point,
|
MultiPoint, Point,
|
||||||
};
|
};
|
||||||
use crate::protos::vector_tile::{
|
use crate::protos::vector_tile::{
|
||||||
Tile as ProtoTile, Tile_Feature as ProtoFeature, Tile_GeomType as ProtoGeomType, Tile_GeomType,
|
Tile as ProtoTile, Tile_Feature as ProtoFeature, Tile_GeomType, Tile_Layer as ProtoLayer,
|
||||||
Tile_Layer as ProtoLayer, Tile_Value as ProtoValue,
|
Tile_Value as ProtoValue,
|
||||||
};
|
};
|
||||||
use crate::tile::{Feature, Layer, PropertyValue, Tile};
|
use crate::tile::{Feature, Layer, PropertyValue, Tile};
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
type Number = i32;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum GeometryPoint {
|
pub enum GeometryPoint {
|
||||||
Point(Point),
|
Point(Point),
|
||||||
@ -14,22 +12,22 @@ pub struct MultiPoint {
|
|||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Point {
|
pub struct Point {
|
||||||
x: Number,
|
x: i32,
|
||||||
y: Number,
|
y: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Contains relative coordinates to which the cursor is moved
|
/// Contains relative coordinates to which the cursor is moved
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct MoveTo {
|
pub struct MoveTo {
|
||||||
pub x: Number,
|
pub x: i32,
|
||||||
pub y: Number,
|
pub y: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Contains relative coordinates to which a line is drawn
|
/// Contains relative coordinates to which a line is drawn
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct LineTo {
|
pub struct LineTo {
|
||||||
pub x: Number,
|
pub x: i32,
|
||||||
pub y: Number,
|
pub y: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
@ -58,7 +56,7 @@ pub enum Geometry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Point {
|
impl Point {
|
||||||
pub(crate) fn new(x: Number, y: Number) -> Self {
|
pub(crate) fn new(x: i32, y: i32) -> Self {
|
||||||
Self { x, y }
|
Self { x, y }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,15 +5,15 @@ pub fn google_mercator() -> Grid {
|
|||||||
256,
|
256,
|
||||||
256,
|
256,
|
||||||
Extent {
|
Extent {
|
||||||
minx: -20037508.3427892480,
|
minx: -20037508.342789248,
|
||||||
miny: -20037508.3427892480,
|
miny: -20037508.342789248,
|
||||||
maxx: 20037508.3427892480,
|
maxx: 20037508.342789248,
|
||||||
maxy: 20037508.3427892480,
|
maxy: 20037508.342789248,
|
||||||
},
|
},
|
||||||
3857,
|
3857,
|
||||||
Unit::Meters,
|
Unit::Meters,
|
||||||
vec![
|
vec![
|
||||||
156543.0339280410,
|
156543.033928041,
|
||||||
78271.5169640205,
|
78271.5169640205,
|
||||||
39135.75848201025,
|
39135.75848201025,
|
||||||
19567.879241005125,
|
19567.879241005125,
|
||||||
|
|||||||
@ -1,7 +1,5 @@
|
|||||||
use std::collections::HashMap;
|
|
||||||
|
|
||||||
use crate::geometry::Geometry;
|
use crate::geometry::Geometry;
|
||||||
use crate::protos::vector_tile::{Tile as ProtoTile, Tile_Layer as ProtoLayer};
|
use std::collections::HashMap;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Tile {
|
pub struct Tile {
|
||||||
|
|||||||
@ -63,7 +63,7 @@ pub fn validate_project_wgsl() {
|
|||||||
Ok(entry) => {
|
Ok(entry) => {
|
||||||
let path = entry.path();
|
let path = entry.path();
|
||||||
if !path.is_dir() {
|
if !path.is_dir() {
|
||||||
match validate_wgsl(&mut validator, &path) {
|
match validate_wgsl(&mut validator, path) {
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
let path = path.strip_prefix(&root_dir).unwrap_or(path);
|
let path = path.strip_prefix(&root_dir).unwrap_or(path);
|
||||||
@ -83,7 +83,7 @@ pub fn validate_project_wgsl() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
println!("cargo:warning={}", format!("{:?}", error));
|
println!("cargo:warning={:?}", error);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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];
|
let mut key = [0u8; 32];
|
||||||
|
|
||||||
key[0] = self.z;
|
key[0] = self.z;
|
||||||
@ -428,28 +428,28 @@ mod tests {
|
|||||||
TileCoords { x: 0, y: 0, z: 1 }
|
TileCoords { x: 0, y: 0, z: 1 }
|
||||||
.into_world_tile(TileAddressingScheme::TMS)
|
.into_world_tile(TileAddressingScheme::TMS)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_quad_key(),
|
.build_quad_key(),
|
||||||
new_quad_key_z1(2)
|
new_quad_key_z1(2)
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
TileCoords { x: 0, y: 1, z: 1 }
|
TileCoords { x: 0, y: 1, z: 1 }
|
||||||
.into_world_tile(TileAddressingScheme::TMS)
|
.into_world_tile(TileAddressingScheme::TMS)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_quad_key(),
|
.build_quad_key(),
|
||||||
new_quad_key_z1(0)
|
new_quad_key_z1(0)
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
TileCoords { x: 1, y: 1, z: 1 }
|
TileCoords { x: 1, y: 1, z: 1 }
|
||||||
.into_world_tile(TileAddressingScheme::TMS)
|
.into_world_tile(TileAddressingScheme::TMS)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_quad_key(),
|
.build_quad_key(),
|
||||||
new_quad_key_z1(1)
|
new_quad_key_z1(1)
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
TileCoords { x: 1, y: 0, z: 1 }
|
TileCoords { x: 1, y: 0, z: 1 }
|
||||||
.into_world_tile(TileAddressingScheme::TMS)
|
.into_world_tile(TileAddressingScheme::TMS)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_quad_key(),
|
.build_quad_key(),
|
||||||
new_quad_key_z1(3)
|
new_quad_key_z1(3)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -41,7 +41,7 @@ impl InputController {
|
|||||||
Self {
|
Self {
|
||||||
pinch_handler: PinchHandler::new(),
|
pinch_handler: PinchHandler::new(),
|
||||||
pan_handler: PanHandler::new(),
|
pan_handler: PanHandler::new(),
|
||||||
zoom_handler: ZoomHandler::new(speed, zoom_sensitivity),
|
zoom_handler: ZoomHandler::new(zoom_sensitivity),
|
||||||
tilt_handler: TiltHandler::new(speed, sensitivity),
|
tilt_handler: TiltHandler::new(speed, sensitivity),
|
||||||
shift_handler: ShiftHandler::new(speed, sensitivity),
|
shift_handler: ShiftHandler::new(speed, sensitivity),
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,16 +2,12 @@ use super::UpdateState;
|
|||||||
|
|
||||||
use crate::render::render_state::RenderState;
|
use crate::render::render_state::RenderState;
|
||||||
use cgmath::num_traits::Pow;
|
use cgmath::num_traits::Pow;
|
||||||
use cgmath::{Vector2, Vector3, Zero};
|
use cgmath::{Vector2, Vector3};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
pub struct ZoomHandler {
|
pub struct ZoomHandler {
|
||||||
window_position: Option<Vector2<f64>>,
|
window_position: Option<Vector2<f64>>,
|
||||||
translate_delta: Vector3<f64>,
|
|
||||||
zooming: bool,
|
|
||||||
zoom_delta: f64,
|
zoom_delta: f64,
|
||||||
|
|
||||||
speed: f64,
|
|
||||||
sensitivity: f64,
|
sensitivity: f64,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,13 +46,10 @@ impl UpdateState for ZoomHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ZoomHandler {
|
impl ZoomHandler {
|
||||||
pub fn new(speed: f64, sensitivity: f64) -> Self {
|
pub fn new(sensitivity: f64) -> Self {
|
||||||
Self {
|
Self {
|
||||||
window_position: None,
|
window_position: None,
|
||||||
translate_delta: Vector3::zero(),
|
|
||||||
zooming: false,
|
|
||||||
zoom_delta: 0.0,
|
zoom_delta: 0.0,
|
||||||
speed,
|
|
||||||
sensitivity,
|
sensitivity,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -251,6 +251,7 @@ impl IOScheduler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
pub struct TileRequestState {
|
pub struct TileRequestState {
|
||||||
current_id: TileRequestID,
|
current_id: TileRequestID,
|
||||||
pending_tile_requests: HashMap<TileRequestID, TileRequest>,
|
pending_tile_requests: HashMap<TileRequestID, TileRequest>,
|
||||||
|
|||||||
@ -14,6 +14,7 @@ static TILES: Dir = include_dir!("$OUT_DIR/extracted-tiles");
|
|||||||
#[cfg(not(static_tiles))]
|
#[cfg(not(static_tiles))]
|
||||||
static TILES: Dir = Dir::new("/path", &[]);
|
static TILES: Dir = Dir::new("/path", &[]);
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
pub struct StaticTileFetcher;
|
pub struct StaticTileFetcher;
|
||||||
|
|
||||||
impl StaticTileFetcher {
|
impl StaticTileFetcher {
|
||||||
|
|||||||
@ -1,9 +1,10 @@
|
|||||||
use crate::coords::WorldTileCoords;
|
use crate::coords::{Quadkey, WorldTileCoords};
|
||||||
use crate::io::LayerResult;
|
use crate::io::LayerResult;
|
||||||
use std::collections::{btree_map, BTreeMap, HashSet};
|
use std::collections::{btree_map, BTreeMap, HashSet};
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
pub struct TileCache {
|
pub struct TileCache {
|
||||||
index: BTreeMap<WorldTileCoords, Vec<LayerResult>>,
|
index: BTreeMap<Quadkey, Vec<LayerResult>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TileCache {
|
impl TileCache {
|
||||||
@ -14,7 +15,7 @@ impl TileCache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn push(&mut self, result: LayerResult) {
|
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) => {
|
btree_map::Entry::Vacant(entry) => {
|
||||||
entry.insert(vec![result]);
|
entry.insert(vec![result]);
|
||||||
}
|
}
|
||||||
@ -31,7 +32,7 @@ impl TileCache {
|
|||||||
) -> Vec<LayerResult> {
|
) -> Vec<LayerResult> {
|
||||||
let mut ret = Vec::new();
|
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 {
|
for result in results {
|
||||||
if !skip_layers.contains(&result.layer_name().to_string()) {
|
if !skip_layers.contains(&result.layer_name().to_string()) {
|
||||||
ret.push(result.clone());
|
ret.push(result.clone());
|
||||||
@ -47,7 +48,7 @@ impl TileCache {
|
|||||||
coords: &WorldTileCoords,
|
coords: &WorldTileCoords,
|
||||||
layers: &mut HashSet<String>,
|
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
|
let tessellated_set: HashSet<String> = results
|
||||||
.iter()
|
.iter()
|
||||||
.map(|tessellated_layer| tessellated_layer.layer_name().to_string())
|
.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 {
|
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
|
let tessellated_set: HashSet<&str> = results
|
||||||
.iter()
|
.iter()
|
||||||
.map(|tessellated_layer| tessellated_layer.layer_name())
|
.map(|tessellated_layer| tessellated_layer.layer_name())
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
use std::collections::vec_deque::Iter;
|
|
||||||
use std::collections::{btree_map, BTreeMap, HashSet, VecDeque};
|
use std::collections::{btree_map, BTreeMap, HashSet, VecDeque};
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use std::marker::PhantomData;
|
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,
|
style_layer: StyleLayer,
|
||||||
geometry: &OverAlignedVertexBuffer<V, I>,
|
geometry: &OverAlignedVertexBuffer<V, I>,
|
||||||
tile_metadata: TM,
|
tile_metadata: TM,
|
||||||
feature_metadata: &Vec<FM>,
|
feature_metadata: &[FM],
|
||||||
) {
|
) {
|
||||||
let vertices_stride = size_of::<V>() as wgpu::BufferAddress;
|
let vertices_stride = size_of::<V>() as wgpu::BufferAddress;
|
||||||
let indices_stride = size_of::<I>() 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(
|
queue.write_buffer(
|
||||||
&self.feature_metadata.inner,
|
&self.feature_metadata.inner,
|
||||||
maybe_entry.buffer_feature_metadata.start,
|
maybe_entry.buffer_feature_metadata.start,
|
||||||
&bytemuck::cast_slice(feature_metadata.as_slice())
|
&bytemuck::cast_slice(feature_metadata)[0..aligned_feature_metadata_bytes as usize],
|
||||||
[0..aligned_feature_metadata_bytes as usize],
|
|
||||||
);
|
);
|
||||||
self.index.push_back(maybe_entry);
|
self.index.push_back(maybe_entry);
|
||||||
}
|
}
|
||||||
@ -412,7 +410,7 @@ impl RingIndex {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_layers(&self, coords: &WorldTileCoords) -> Option<&VecDeque<IndexEntry>> {
|
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>> {
|
pub fn get_layers_fallback(&self, coords: &WorldTileCoords) -> Option<&VecDeque<IndexEntry>> {
|
||||||
@ -428,12 +426,10 @@ impl RingIndex {
|
|||||||
loop {
|
loop {
|
||||||
if let Some(entries) = self.get_layers(¤t) {
|
if let Some(entries) = self.get_layers(¤t) {
|
||||||
return Some(entries);
|
return Some(entries);
|
||||||
|
} else if let Some(parent) = current.get_parent() {
|
||||||
|
current = parent
|
||||||
} else {
|
} else {
|
||||||
if let Some(parent) = current.get_parent() {
|
return None;
|
||||||
current = parent
|
|
||||||
} else {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -451,8 +447,8 @@ impl RingIndex {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn push_back(&mut self, entry: IndexEntry) {
|
pub fn push_back(&mut self, entry: IndexEntry) {
|
||||||
let key = entry.coords.to_quad_key();
|
let key = entry.coords.build_quad_key();
|
||||||
match self.tree_index.entry(key.clone()) {
|
match self.tree_index.entry(key) {
|
||||||
btree_map::Entry::Vacant(index_entry) => {
|
btree_map::Entry::Vacant(index_entry) => {
|
||||||
index_entry.insert(VecDeque::from([entry]));
|
index_entry.insert(VecDeque::from([entry]));
|
||||||
}
|
}
|
||||||
@ -539,7 +535,7 @@ mod tests {
|
|||||||
style_layer.clone(),
|
style_layer.clone(),
|
||||||
&data48bytes_aligned,
|
&data48bytes_aligned,
|
||||||
2,
|
2,
|
||||||
&vec![],
|
&[],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
@ -553,7 +549,7 @@ mod tests {
|
|||||||
style_layer.clone(),
|
style_layer.clone(),
|
||||||
&data24bytes_aligned,
|
&data24bytes_aligned,
|
||||||
2,
|
2,
|
||||||
&vec![],
|
&[],
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
128 - 2 * 48 - 24,
|
128 - 2 * 48 - 24,
|
||||||
@ -567,7 +563,7 @@ mod tests {
|
|||||||
style_layer.clone(),
|
style_layer.clone(),
|
||||||
&data24bytes_aligned,
|
&data24bytes_aligned,
|
||||||
2,
|
2,
|
||||||
&vec![],
|
&[],
|
||||||
);
|
);
|
||||||
// appended now at the beginning
|
// appended now at the beginning
|
||||||
println!("{:?}", &pool.index);
|
println!("{:?}", &pool.index);
|
||||||
@ -579,7 +575,7 @@ mod tests {
|
|||||||
style_layer.clone(),
|
style_layer.clone(),
|
||||||
&data24bytes_aligned,
|
&data24bytes_aligned,
|
||||||
2,
|
2,
|
||||||
&vec![],
|
&[],
|
||||||
);
|
);
|
||||||
println!("{:?}", &pool.index);
|
println!("{:?}", &pool.index);
|
||||||
assert_eq!(0, pool.available_space(BackingBufferType::Vertices));
|
assert_eq!(0, pool.available_space(BackingBufferType::Vertices));
|
||||||
@ -590,7 +586,7 @@ mod tests {
|
|||||||
style_layer.clone(),
|
style_layer.clone(),
|
||||||
&data24bytes_aligned,
|
&data24bytes_aligned,
|
||||||
2,
|
2,
|
||||||
&vec![],
|
&[],
|
||||||
);
|
);
|
||||||
println!("{:?}", &pool.index);
|
println!("{:?}", &pool.index);
|
||||||
assert_eq!(24, pool.available_space(BackingBufferType::Vertices));
|
assert_eq!(24, pool.available_space(BackingBufferType::Vertices));
|
||||||
@ -601,7 +597,7 @@ mod tests {
|
|||||||
style_layer,
|
style_layer,
|
||||||
&data24bytes_aligned,
|
&data24bytes_aligned,
|
||||||
2,
|
2,
|
||||||
&vec![],
|
&[],
|
||||||
);
|
);
|
||||||
println!("{:?}", &pool.index);
|
println!("{:?}", &pool.index);
|
||||||
assert_eq!(0, pool.available_space(BackingBufferType::Vertices));
|
assert_eq!(0, pool.available_space(BackingBufferType::Vertices));
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
use cgmath::num_traits::Inv;
|
|
||||||
use cgmath::prelude::*;
|
use cgmath::prelude::*;
|
||||||
use cgmath::{Matrix4, Point2, Point3, Vector2, Vector3, Vector4};
|
use cgmath::{Matrix4, Point2, Point3, Vector2, Vector3, Vector4};
|
||||||
|
|
||||||
@ -40,7 +39,6 @@ impl ViewProjection {
|
|||||||
self.0
|
self.0
|
||||||
.cast::<f32>()
|
.cast::<f32>()
|
||||||
.expect("Unable to cast view projection to f32")
|
.expect("Unable to cast view projection to f32")
|
||||||
.into()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,7 +57,6 @@ impl ModelViewProjection {
|
|||||||
self.0
|
self.0
|
||||||
.cast::<f32>()
|
.cast::<f32>()
|
||||||
.expect("Unable to cast view projection to f32")
|
.expect("Unable to cast view projection to f32")
|
||||||
.into()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -276,34 +273,32 @@ impl Camera {
|
|||||||
Vector2::new(self.width, self.height),
|
Vector2::new(self.width, self.height),
|
||||||
Vector2::new(0.0, 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 min: Option<Point2<f64>> = None;
|
||||||
let mut max: Option<Point2<f64>> = None;
|
let mut max: Option<Point2<f64>> = None;
|
||||||
|
|
||||||
for vector in screen_bounding_box {
|
for vector in screen_bounding_box.into_iter().flatten() {
|
||||||
if let Some(vector) = vector {
|
if let Some(current_min) = &mut min {
|
||||||
if let Some(current_min) = &mut min {
|
if vector.x < current_min.x {
|
||||||
if vector.x < current_min.x {
|
current_min.x = vector.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 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 let Some(current_max) = &mut max {
|
||||||
if vector.x > current_max.x {
|
if vector.x > current_max.x {
|
||||||
current_max.x = vector.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 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)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::render::camera::{InvertedViewProjection, ViewProjection};
|
use crate::render::camera::{InvertedViewProjection, ViewProjection};
|
||||||
use cgmath::{AbsDiffEq, Matrix4, SquareMatrix, Vector2, Vector3, Vector4};
|
use cgmath::{AbsDiffEq, Vector2, Vector3, Vector4};
|
||||||
|
|
||||||
use super::{Camera, Perspective};
|
use super::{Camera, Perspective};
|
||||||
|
|
||||||
@ -430,14 +425,14 @@ mod tests {
|
|||||||
let inverted_view_proj: InvertedViewProjection = view_proj.invert();
|
let inverted_view_proj: InvertedViewProjection = view_proj.invert();
|
||||||
|
|
||||||
let world_pos: Vector4<f64> = Vector4::new(0.0, 0.0, 0.0, 1.0);
|
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));
|
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!("origin w in clip space: {:?}", origin_clip_space.w);
|
||||||
|
|
||||||
println!("world_pos: {:?}", world_pos);
|
println!("world_pos: {:?}", world_pos);
|
||||||
println!("clip: {:?}", clip);
|
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));
|
println!("window: {:?}", camera.clip_to_window_vulkan(&clip));
|
||||||
let window = camera.clip_to_window(&clip);
|
let window = camera.clip_to_window(&clip);
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
use cgmath::num_traits::Pow;
|
|
||||||
use cgmath::Matrix4;
|
use cgmath::Matrix4;
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
#![allow(clippy::identity_op)]
|
||||||
use wgpu::{
|
use wgpu::{
|
||||||
ColorTargetState, Device, FragmentState, ShaderModule, VertexBufferLayout, VertexState,
|
ColorTargetState, Device, FragmentState, ShaderModule, VertexBufferLayout, VertexState,
|
||||||
};
|
};
|
||||||
|
|||||||
@ -8,7 +8,6 @@ use lyon::tessellation::geometry_builder::MaxIndex;
|
|||||||
use lyon::tessellation::{
|
use lyon::tessellation::{
|
||||||
BuffersBuilder, FillOptions, FillTessellator, StrokeOptions, StrokeTessellator,
|
BuffersBuilder, FillOptions, FillTessellator, StrokeOptions, StrokeTessellator,
|
||||||
};
|
};
|
||||||
use lyon_path::traits::SvgPathBuilder;
|
|
||||||
use lyon_path::{FillRule, Path};
|
use lyon_path::{FillRule, Path};
|
||||||
|
|
||||||
use crate::error::Error;
|
use crate::error::Error;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user