diff --git a/hexit/src/combine.rs b/hexit/src/combine.rs index 4bee834..3e2d2ea 100644 --- a/hexit/src/combine.rs +++ b/hexit/src/combine.rs @@ -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 for ReductionCompactor { - fn compact(&mut self, cell: Cell, children: [Option<&Elevation>; 7]) -> Option { - 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()); diff --git a/hexit/src/elevation.rs b/hexit/src/elevation.rs index 3cbd2bc..11a86d8 100644 --- a/hexit/src/elevation.rs +++ b/hexit/src/elevation.rs @@ -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)] @@ -79,3 +80,26 @@ impl Elevation { }) } } + +pub struct ReductionCompactor { + pub target_resolution: u8, + pub source_resolution: u8, +} + +impl Compactor for ReductionCompactor { + fn compact(&mut self, cell: Cell, children: [Option<&Elevation>; 7]) -> Option { + 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 + } + } +}