Skip to content

Commit

Permalink
Move compactor to elev mod
Browse files Browse the repository at this point in the history
  • Loading branch information
JayKickliter committed Nov 24, 2023
1 parent 9ff40c6 commit 9f78d55
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 25 deletions.
27 changes: 2 additions & 25 deletions hexit/src/combine.rs
Original file line number Diff line number Diff line change
@@ -1,38 +1,15 @@
use crate::{
elevation::{Elevation, ReducedElevation},
elevation::{Elevation, ReducedElevation, ReductionCompactor},
options::Combine,
progress,
};
use anyhow::Result;
use byteorder::{LittleEndian as LE, ReadBytesExt, WriteBytesExt};
use flate2::bufread::GzDecoder;
use hextree::{compaction::Compactor, Cell, HexTreeMap};
use hextree::HexTreeMap;
use indicatif::MultiProgress;
use std::{ffi::OsStr, fs::File, io::BufReader, path::Path};

struct ReductionCompactor {
target_resolution: u8,
source_resolution: u8,
}

impl Compactor<Elevation> for ReductionCompactor {
fn compact(&mut self, cell: Cell, children: [Option<&Elevation>; 7]) -> Option<Elevation> {
if cell.res() < self.target_resolution {
None
} else if let [Some(v0), Some(v1), Some(v2), Some(v3), Some(v4), Some(v5), Some(v6)] =
children
{
Some(Elevation::concat(
self.source_resolution,
cell.res(),
&[*v0, *v1, *v2, *v3, *v4, *v5, *v6],
))
} else {
None
}
}
}

impl Combine {
pub fn run(&self) -> Result<()> {
assert!(!self.input.is_empty());
Expand Down
24 changes: 24 additions & 0 deletions hexit/src/elevation.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use anyhow::Result;
use byteorder::{LittleEndian as LE, ReadBytesExt};
use hextree::{compaction::Compactor, Cell};
use std::io::Read;

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
Expand Down Expand Up @@ -79,3 +80,26 @@ impl Elevation {
})
}
}

pub struct ReductionCompactor {
pub target_resolution: u8,
pub source_resolution: u8,
}

impl Compactor<Elevation> for ReductionCompactor {
fn compact(&mut self, cell: Cell, children: [Option<&Elevation>; 7]) -> Option<Elevation> {
if cell.res() < self.target_resolution {
None
} else if let [Some(v0), Some(v1), Some(v2), Some(v3), Some(v4), Some(v5), Some(v6)] =
children
{
Some(Elevation::concat(
self.source_resolution,
cell.res(),
&[*v0, *v1, *v2, *v3, *v4, *v5, *v6],
))
} else {
None
}
}
}

0 comments on commit 9f78d55

Please sign in to comment.