use super::VertexGraph;
use crate::{CellIndex, Resolution, error::DissolutionError};
use geo::MultiPolygon;
#[derive(Debug, Clone, Copy)]
pub struct Solvent {
input_mode: InputMode,
check_duplicate: bool,
}
impl Solvent {
pub fn dissolve(
&self,
cells: impl IntoIterator<Item = CellIndex>,
) -> Result<MultiPolygon, DissolutionError> {
let graph = match self.input_mode {
InputMode::Homogeneous => {
VertexGraph::from_homogeneous(cells, self.check_duplicate)
}
InputMode::Heterogeneous(resolution) => {
VertexGraph::from_heterogeneous(
cells,
resolution,
self.check_duplicate,
)
}
}?;
Ok(graph.into())
}
}
#[derive(Debug, Clone, Copy)]
pub struct SolventBuilder {
input_mode: InputMode,
check_duplicate: bool,
}
impl Default for SolventBuilder {
fn default() -> Self {
Self::new()
}
}
impl SolventBuilder {
#[must_use]
pub const fn new() -> Self {
Self {
input_mode: InputMode::Homogeneous,
check_duplicate: true,
}
}
#[must_use]
pub const fn disable_duplicate_detection(mut self) -> Self {
self.check_duplicate = false;
self
}
#[must_use]
pub const fn enable_heterogeneous_support(
mut self,
resolution: Resolution,
) -> Self {
self.input_mode = InputMode::Heterogeneous(resolution);
self
}
#[must_use]
pub const fn build(self) -> Solvent {
Solvent {
input_mode: self.input_mode,
check_duplicate: self.check_duplicate,
}
}
}
#[derive(Debug, Clone, Copy)]
enum InputMode {
Homogeneous,
Heterogeneous(Resolution),
}