use super::index::{NearestBoundaryIndex, PipIndex};
use super::input::{HostPolygon, SegmentIndex};
use super::MicError;
#[derive(Debug, Clone)]
pub struct MicWorkspace {
pub host: HostPolygon,
pub pip_index: PipIndex,
pub nb_index: NearestBoundaryIndex,
}
impl MicWorkspace {
pub fn new(host: HostPolygon) -> Result<Self, MicError> {
let seg_index = SegmentIndex::from_host(&host);
Self::with_segments(host, seg_index)
}
pub fn with_segments(host: HostPolygon, seg_index: SegmentIndex) -> Result<Self, MicError> {
if seg_index.is_empty() {
return Err(MicError::InvalidInput(
"polygon has no non-degenerate boundary segments".to_string(),
));
}
let pip_index = PipIndex::new(&host);
let nb_index = NearestBoundaryIndex::new(seg_index);
Ok(Self {
host,
pip_index,
nb_index,
})
}
}