use super::manifold::{raw_components, ManifoldType};
use crate::ToponError;
pub const MAX_DIMENSION: usize = 1144;
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct CoordinateConfig {
pub dimension: usize,
pub manifold_type: ManifoldType,
}
impl CoordinateConfig {
pub fn new(dimension: usize, manifold_type: ManifoldType) -> Result<Self, ToponError> {
let config = CoordinateConfig { dimension, manifold_type };
config.validate()?;
Ok(config)
}
pub fn validate(&self) -> Result<(), ToponError> {
if self.dimension == 0 {
return Err(ToponError::InvalidConfig);
}
if self.dimension > MAX_DIMENSION {
return Err(ToponError::InvalidConfig);
}
if raw_components(self.dimension, self.manifold_type) > MAX_DIMENSION + 1 {
return Err(ToponError::InvalidConfig);
}
Ok(())
}
}
impl Default for CoordinateConfig {
fn default() -> Self {
CoordinateConfig {
dimension: 128,
manifold_type: ManifoldType::Sphere,
}
}
}