aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Schadt <kingdread@gmx.de>2023-03-11 19:57:18 +0100
committerDaniel Schadt <kingdread@gmx.de>2023-03-11 19:57:18 +0100
commitfd4f3318db8df3e9f0542535fb7df6d621d07768 (patch)
treea7266db8f159d3cd7a487bc7eb80f3fcb2dd807d
parent4e8ce5bbaf5aa71f7e00e7a131fc6b25e623c992 (diff)
downloadhittekaart-fd4f3318db8df3e9f0542535fb7df6d621d07768.tar.gz
hittekaart-fd4f3318db8df3e9f0542535fb7df6d621d07768.tar.bz2
hittekaart-fd4f3318db8df3e9f0542535fb7df6d621d07768.zip
first implementation of tile hunter mode
This is a very basic idea, the downside is that you basically cannot "fix" the tilehunt overlay to a specific zoom level. It might be nice to get a second renderer that renders the tile hunt for a fixed zoom, and then adjusts the output tiles accordingly (then it also takes more space again though).
-rw-r--r--src/main.rs7
-rw-r--r--src/renderer/mod.rs1
-rw-r--r--src/renderer/tile-marked.pngbin0 -> 116 bytes
-rw-r--r--src/renderer/tilehunt.rs52
4 files changed, 58 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs
index 6c110e2..7f7c532 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -7,7 +7,7 @@ use color_eyre::{
};
use hittekaart::{
gpx::{self, Compression},
- renderer::{self, heatmap, Renderer},
+ renderer::{self, heatmap, tilehunt, Renderer},
storage::{Folder, Sqlite, Storage},
};
use indicatif::{MultiProgress, ProgressBar, ProgressDrawTarget, ProgressStyle};
@@ -71,7 +71,10 @@ fn main() -> Result<()> {
.num_threads(args.threads)
.build_global()?;
- run::<heatmap::Renderer>(args)
+ match args.mode {
+ Mode::Heatmap => run::<heatmap::Renderer>(args),
+ Mode::Tilehunt => run::<tilehunt::Renderer>(args),
+ }
}
fn run<R: Renderer>(args: Args) -> Result<()> {
diff --git a/src/renderer/mod.rs b/src/renderer/mod.rs
index 927c6ed..f109872 100644
--- a/src/renderer/mod.rs
+++ b/src/renderer/mod.rs
@@ -7,6 +7,7 @@ use crossbeam_channel::Sender;
use super::gpx::Coordinates;
pub mod heatmap;
+pub mod tilehunt;
const CHANNEL_SIZE: usize = 30;
diff --git a/src/renderer/tile-marked.png b/src/renderer/tile-marked.png
new file mode 100644
index 0000000..0b05ce2
--- /dev/null
+++ b/src/renderer/tile-marked.png
Binary files differ
diff --git a/src/renderer/tilehunt.rs b/src/renderer/tilehunt.rs
new file mode 100644
index 0000000..f44644b
--- /dev/null
+++ b/src/renderer/tilehunt.rs
@@ -0,0 +1,52 @@
+//! Actual rendering functions for tile hunts.
+use color_eyre::eyre::Result;
+use crossbeam_channel::Sender;
+use fnv::FnvHashSet;
+
+use super::{
+ super::{
+ gpx::Coordinates,
+ layer::{TILE_HEIGHT, TILE_WIDTH},
+ },
+ RenderedTile,
+};
+
+#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
+pub struct Renderer;
+
+impl super::Renderer for Renderer {
+ type Prepared = FnvHashSet<(u64, u64)>;
+
+ fn prepare(zoom: u32, tracks: &[Vec<Coordinates>], tick: Sender<()>) -> Result<Self::Prepared> {
+ let mut marked = FnvHashSet::default();
+
+ for track in tracks {
+ for point in track {
+ let merc = point.web_mercator(zoom);
+ let tile_x = merc.0 / TILE_WIDTH;
+ let tile_y = merc.1 / TILE_HEIGHT;
+ marked.insert((tile_x, tile_y));
+ }
+
+ tick.send(()).unwrap();
+ }
+
+ Ok(marked)
+ }
+
+ fn colorize(layer: Self::Prepared, tx: Sender<RenderedTile>) -> Result<()> {
+ static IMAGE_DATA: &[u8] = include_bytes!("tile-marked.png");
+ for (tile_x, tile_y) in layer {
+ tx.send(RenderedTile {
+ x: tile_x,
+ y: tile_y,
+ data: IMAGE_DATA.to_vec(),
+ })?;
+ }
+ Ok(())
+ }
+
+ fn tile_count(layer: &Self::Prepared) -> Result<u64> {
+ Ok(layer.len().try_into().unwrap())
+ }
+}