use thiserror::Error;
pub type Result<T> = std::result::Result<T, Error>;
pub(crate) fn check_range(name: &str, value: f64, min: f64, max: f64) -> Result<()> {
if value >= min && value <= max {
Ok(())
} else {
Err(Error::ConfigError(format!(
"{name} must be in [{min}, {max}], got {value}"
)))
}
}
pub(crate) fn check_at_least(name: &str, value: f64, min: f64) -> Result<()> {
if value.is_finite() && value >= min {
Ok(())
} else {
Err(Error::ConfigError(format!(
"{name} must be a finite number >= {min}, got {value}"
)))
}
}
#[derive(Debug, Error)]
pub enum Error {
#[error("Invalid geometry: {0}")]
InvalidGeometry(String),
#[error("Invalid boundary: {0}")]
InvalidBoundary(String),
#[error("Configuration error: {0}")]
ConfigError(String),
#[error("NFP computation failed: {0}")]
NfpError(String),
#[error("No valid placement found for geometry: {0}")]
NoPlacement(String),
#[error("Computation cancelled")]
Cancelled,
#[error("Timeout exceeded after {0}ms")]
Timeout(u64),
#[cfg(feature = "serde")]
#[error("Serialization error: {0}")]
SerializationError(String),
#[error("Internal error: {0}")]
Internal(String),
}