mod arc_set;
mod ring_hierarchy;
mod vertex_graph;
use arc_set::ArcSet;
use ring_hierarchy::RingHierarchy;
use vertex_graph::VertexGraph;
#[derive(Debug, Clone, Copy)]
pub struct Solvent {
input_mode: InputMode,
check_duplicate: bool,
}
impl Solvent {
pub fn dissolve(
&self,
cells: impl IntoIterator<Item = crate::CellIndex>,
) -> Result<geo::MultiPolygon, crate::error::DissolutionError> {
Ok(match self.input_mode {
InputMode::Homogeneous => {
ArcSet::new(cells, self.check_duplicate)?.into()
}
InputMode::Heterogeneous(resolution) => {
VertexGraph::from_heterogeneous(
cells,
resolution,
self.check_duplicate,
)?
.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: crate::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(crate::Resolution),
}