Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Max Ammann <max@maxammann.org>
  • Loading branch information
Drabble and maxammann committed May 11, 2022
1 parent aa3b43b commit 7458dd1
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 37 deletions.
5 changes: 3 additions & 2 deletions maplibre/src/coords.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ impl fmt::Debug for Quadkey {
}
}

/// Zoom is an exponential scale that defines the zoom level for camera and tiles.
/// `Zoom` is an exponential scale that defines of the camera and tiles.
/// We can derive the `ZoomLevel` from `Zoom` by using the `[crate::coords::ZOOM_BOUNDS]`.
#[derive(Copy, Clone, Debug)]
pub struct Zoom(f64);

Expand Down Expand Up @@ -444,7 +445,7 @@ impl From<Point3<f64>> for WorldCoords {
}
}

/// Defines a bounding box on a tiled map with a zoom level and a padding.
/// Defines a bounding box on a tiled map with a [`ZoomLevel`] and a padding.
#[derive(Debug)]
pub struct ViewRegion {
min_tile: WorldTileCoords,
Expand Down
2 changes: 1 addition & 1 deletion maplibre/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use lyon::tessellation::TessellationError;
use std::sync::mpsc::SendError;

/// Multiple types of map rendering errors
/// Enumeration of errors which can happen during the operation of the library.
#[derive(Debug)]
pub enum Error {
Schedule,
Expand Down
5 changes: 0 additions & 5 deletions maplibre/src/input/pan_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,6 @@ impl PanHandler {
return false;
}

if !self.is_panning {
// starting to pan
// FIXME: This `if` statement is not used
}

if *state == ElementState::Pressed {
// currently panning or starting to pan
self.is_panning = true;
Expand Down
4 changes: 2 additions & 2 deletions maplibre/src/io/geometry_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use rstar::{Envelope, PointDistance, RTree, RTreeObject, AABB};
use crate::coords::{InnerCoords, Quadkey, WorldCoords, WorldTileCoords, Zoom, EXTENT, TILE_SIZE};
use crate::util::math::bounds_from_points;

/// A quad tree storing the current tiles being rendered.
/// A quad tree storing the currently loaded tiles.
pub struct GeometryIndex {
index: BTreeMap<Quadkey, TileIndex>,
}
Expand Down Expand Up @@ -62,7 +62,7 @@ impl GeometryIndex {
/// Spatial tiles are stored in a multi-dimentional tree which represents their position in the tile.
/// Linear tiles are simply stored in a vector.
///
/// A spatial tile index can improve query performance on tiles.
/// A spatial tile index can theoretically improve query performance on tiles. Practically it could be slower though. The `Spatial` index is experimental and currently unused.
pub enum TileIndex {
Spatial { tree: RTree<IndexedGeometry<f64>> },
Linear { list: Vec<IndexedGeometry<f64>> },
Expand Down
2 changes: 1 addition & 1 deletion maplibre/src/io/static_tile_fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ static TILES: Dir = include_dir!("$OUT_DIR/extracted-tiles");
#[cfg(not(static_tiles))]
static TILES: Dir = Dir::new("/path", &[]);

/// Load PBF files from the local direction `extracted-tiles`.
/// Load PBF files which were statically embedded in the `build.rs`
#[derive(Default)]
pub struct StaticTileFetcher;

Expand Down
31 changes: 14 additions & 17 deletions maplibre/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
//! # Maplibre-rs
//!
//! A multi-platform library for rendering vector tile maps with WebGPU.
//!
//! Maplibre-rs is a map renderer that can run natively on MacOS, Linux, Windows, Android, iOS and the web.
//! It takes advantage of Lyon to tessellate vector tiles and WebGPU to display them efficiently.
//! Maplibre-rs also has an headless mode (*work in progress*) that can generate rasters.
//!
//! The official guide book can be found here #![doc = include_str!("description.md")]
//!
//! ### Example
//!
//! To import maplibre-rs in your `Cargo.toml`:
//!
//! ```toml
//! maplibre = "0.0.2"
//! ```

use crate::io::scheduler::{ScheduleMethod, Scheduler};
use crate::io::source_client::HTTPClient;
Expand Down Expand Up @@ -95,10 +109,6 @@ where
{
/// Initializes the whole rendering pipeline for the given configuration.
/// Returns the initialized map, ready to be run.
///
/// # Panics
///
/// * Panics if Winit is unable to retrieve the target window size.
pub async fn initialize(self) -> Map<W, E, SM, HC> {
#[cfg(target_os = "android")]
// On android we can not get the dimensions of the window initially. Therefore, we use a
Expand Down Expand Up @@ -135,10 +145,6 @@ where
HC: HTTPClient,
{
/// Runs the map application without a maximum number of frames per second defined.
///
/// # Panics
///
/// * Panics if the operating system is unable to starts the worker threads.
pub fn run_sync(self) {
self.run_sync_with_optionally_max_frames(None);
}
Expand All @@ -148,10 +154,6 @@ where
/// # Arguments
///
/// * `max_frames` - The maxiumum number of frame per seconds.
///
/// # Panics
///
/// * Panics if the operating system is unable to starts the worker threads.
pub fn run_sync_with_max_frames(self, max_frames: u64) {
self.run_sync_with_optionally_max_frames(Some(max_frames))
}
Expand Down Expand Up @@ -225,11 +227,6 @@ where
}

/// Builds the UninitializedMap with the given configuration.
///
/// # Panics
///
/// * Panics if no schedule method has been configured.
/// * Panics if no http client has been configured.
pub fn build(self) -> UninitializedMap<W, E, SM, HC> {
let (window, event_loop) = (self.window_factory)();

Expand Down
2 changes: 1 addition & 1 deletion maplibre/src/map_state.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Stores the state of the map such as zoom level, camera, styles, etc.
//! Stores the state of the map such as `[crate::coords::Zoom]`, `[crate::camera::Camera]`, `[crate::style::Style]`, `[crate::io::tile_cache::TileCache]` and more.

use crate::coords::{ViewRegion, WorldTileCoords, Zoom, TILE_SIZE};
use crate::error::Error;
Expand Down
1 change: 0 additions & 1 deletion maplibre/src/platform/noweb/http_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use reqwest_middleware::ClientWithMiddleware;
use reqwest_middleware_cache::managers::CACacheManager;
use reqwest_middleware_cache::{Cache, CacheMode};

/// Reqwest http client
#[derive(Clone)]
pub struct ReqwestHttpClient {
client: ClientWithMiddleware,
Expand Down
3 changes: 0 additions & 3 deletions maplibre/src/style/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use csscolorparser::Color;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

/// Background styling.
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct BackgroundPaint {
#[serde(rename = "background-color")]
Expand All @@ -14,7 +13,6 @@ pub struct BackgroundPaint {
// TODO a lot
}

/// Fill styling.
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct FillPaint {
#[serde(rename = "fill-color")]
Expand All @@ -23,7 +21,6 @@ pub struct FillPaint {
// TODO a lot
}

/// Line styling.
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct LinePaint {
#[serde(rename = "line-color")]
Expand Down
4 changes: 0 additions & 4 deletions maplibre/src/winit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,6 @@ where
let dt = now - last_render_time;
last_render_time = now;

// FIXME: Inputs are updated in RedrawRequested which
// 1. Adds a strain on the main thread, maybe we need another thread for that.
// 2. Delta time is correlated to the frame rate, and a low frame rate will cause
// a lag with inputs. e.g. a button is held for a certain amount of time.
input_controller.update_state(self.view_state_mut(), dt);

match self.update_and_redraw() {
Expand Down

0 comments on commit 7458dd1

Please sign in to comment.