aboutsummaryrefslogtreecommitdiff
path: root/src/renderer
diff options
context:
space:
mode:
Diffstat (limited to 'src/renderer')
-rw-r--r--src/renderer/mod.rs1
-rw-r--r--src/renderer/tile-marked.pngbin0 -> 116 bytes
-rw-r--r--src/renderer/tilehunt.rs52
3 files changed, 53 insertions, 0 deletions
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())
+ }
+}