aboutsummaryrefslogtreecommitdiff
path: root/src/renderer.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/renderer.rs')
-rw-r--r--src/renderer.rs40
1 files changed, 11 insertions, 29 deletions
diff --git a/src/renderer.rs b/src/renderer.rs
index 6e17304..cece8f3 100644
--- a/src/renderer.rs
+++ b/src/renderer.rs
@@ -1,9 +1,8 @@
-use std::{fs, mem, path::Path};
+use std::{fs, path::Path};
use color_eyre::eyre::{bail, Result};
-use image::{ImageBuffer, Luma, Pixel, Rgba, RgbaImage};
+use image::{ImageBuffer, Luma, Pixel, RgbaImage};
use nalgebra::{vector, Vector2};
-use num_traits::identities::Zero;
use super::{
gpx::Coordinates,
@@ -12,8 +11,6 @@ use super::{
pub type HeatCounter = TileLayer<Luma<u8>>;
-pub type HeatMap = TileLayer<Rgba<u8>>;
-
fn render_circle<P: Pixel>(layer: &mut TileLayer<P>, center: (u64, u64), radius: u64, pixel: P) {
let topleft = (center.0 - radius, center.1 - radius);
let rad_32: u32 = radius.try_into().unwrap();
@@ -59,14 +56,14 @@ fn render_line<P: Pixel>(
fn unsigned_add(a: Vector2<u64>, b: Vector2<i32>) -> Vector2<u64> {
let x = if b[0] < 0 {
- a[0] - b[0].abs() as u64
+ a[0] - u64::from(b[0].unsigned_abs())
} else {
- a[0] + b[0] as u64
+ a[0] + u64::try_from(b[0]).unwrap()
};
let y = if b[1] < 0 {
- a[1] - b[1].abs() as u64
+ a[1] - u64::from(b[1].unsigned_abs())
} else {
- a[1] + b[1] as u64
+ a[1] + u64::try_from(b[1]).unwrap()
};
vector![x, y]
}
@@ -130,19 +127,6 @@ fn colorize_tile(tile: &ImageBuffer<Luma<u8>, Vec<u8>>, max: u32) -> RgbaImage {
result
}
-pub fn colorize_heatcounter(layer: &HeatCounter) -> HeatMap {
- let max = layer.pixels().map(|l| l.0[0]).max().unwrap_or_default();
- let mut result = TileLayer::from_pixel(layer.width(), layer.height(), [0, 0, 0, 0].into());
- if max == 0 {
- return result;
- }
- for (tile_x, tile_y, tile) in layer.enumerate_tiles() {
- let colorized = colorize_tile(&tile, max.into());
- *result.tile_mut(tile_x, tile_y) = colorized;
- }
- result
-}
-
/// Lazily colorizes a [`HeatCounter`] by colorizing it tile-by-tile and saving a tile before
/// rendering the next one.
///
@@ -159,15 +143,15 @@ pub fn lazy_colorization<P: AsRef<Path>, F: FnMut(usize)>(
}
for (tile_x, tile_y, tile) in layer.enumerate_tiles() {
- let colorized = colorize_tile(&tile, max.into());
- let folder = base_dir.join(&tile_x.to_string());
+ let colorized = colorize_tile(tile, max.into());
+ let folder = base_dir.join(tile_x.to_string());
let metadata = folder.metadata();
match metadata {
Err(_) => fs::create_dir(&folder)?,
Ok(m) if !m.is_dir() => bail!("Output path is not a directory"),
_ => {}
}
- let file = folder.join(&format!("{tile_y}.png"));
+ let file = folder.join(format!("{tile_y}.png"));
layer::compress_png(&colorized, file)?;
progress_callback(1);
}
@@ -180,12 +164,10 @@ pub fn render_heatcounter<F: FnMut(usize)>(
tracks: &[Vec<Coordinates>],
mut progress_callback: F,
) -> HeatCounter {
- let size = 256 * 2u64.pow(zoom);
-
- let mut heatcounter = TileLayer::from_pixel(size, size, [0].into());
+ let mut heatcounter = TileLayer::from_pixel([0].into());
for track in tracks {
- let mut layer = TileLayer::from_pixel(size, size, [0].into());
+ let mut layer = TileLayer::from_pixel([0].into());
let points = track
.iter()