use core::fmt;
use numra_core::NumraError;
#[derive(Clone, Debug, PartialEq)]
pub enum SignalError {
InvalidOrder(usize),
InvalidCutoff { cutoff: f64, nyquist: f64 },
InvalidRipple(f64),
InsufficientData { need: usize, got: usize },
InvalidParameter(String),
}
impl fmt::Display for SignalError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::InvalidOrder(n) => write!(f, "invalid filter order: {n}"),
Self::InvalidCutoff { cutoff, nyquist } => {
write!(f, "cutoff {cutoff} must be in (0, {nyquist})")
}
Self::InvalidRipple(r) => write!(f, "ripple must be positive, got {r}"),
Self::InsufficientData { need, got } => {
write!(f, "need at least {need} samples, got {got}")
}
Self::InvalidParameter(msg) => write!(f, "invalid parameter: {msg}"),
}
}
}
impl std::error::Error for SignalError {}
impl From<SignalError> for NumraError {
fn from(e: SignalError) -> Self {
NumraError::Signal(e.to_string())
}
}