use std::{error, fmt};
#[derive(Debug, PartialEq)]
pub enum StateError {
ZeroMagnitude,
}
impl fmt::Display for StateError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::ZeroMagnitude => write!(f, "Magnitude or Norm of the state is 0."),
}
}
}
impl error::Error for StateError {}
#[derive(Debug, PartialEq)]
pub enum StateSpaceError {
DimensionMismatch { expected: usize, found: usize },
InvalidBound { lower: f64, upper: f64 },
ZeroDimensionUnbounded,
InvalidAngularDistance { lower: f64 },
}
impl fmt::Display for StateSpaceError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::DimensionMismatch { expected, found } => write!(
f,
"provided bounds length ({found}) does not match specified dimension ({expected})."
),
Self::InvalidBound { lower, upper } => {
write!(
f,
"Lower bound {lower} is greater than upper bound {upper}."
)
}
Self::ZeroDimensionUnbounded => {
write!(f, "Cannot create 0-dimensional unbounded space.")
}
Self::InvalidAngularDistance { lower } => {
write!(
f,
"Maximum angle cannot be negative or less than zero. Provided: {lower}."
)
}
}
}
}
impl error::Error for StateSpaceError {}
#[derive(Debug, PartialEq)]
pub enum StateSamplingError {
UnboundedDimension { dimension_index: usize },
ZeroVolume,
GoalRegionUnsatisfiable,
GoalSamplingTimeout { attempts: u32 },
}
impl fmt::Display for StateSamplingError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::UnboundedDimension { dimension_index } => {
write!(
f,
"Cannot sample uniformly because dimension {dimension_index} is unbounded."
)
}
Self::ZeroVolume => {
write!(f, "Cannot sample from a region with zero volume.")
}
Self::GoalRegionUnsatisfiable => {
write!(f, "Could not generate a sample from the goal region because its constraints may be unsatisfiable.")
}
Self::GoalSamplingTimeout { attempts } => {
write!(
f,
"Failed to generate a goal sample within {attempts} attempts."
)
}
}
}
}
impl error::Error for StateSamplingError {}
#[derive(Debug, PartialEq)]
pub enum PlanningError {
Timeout,
NoSolutionFound,
PlannerUninitialised,
InvalidStartState,
UnsampledStateSpace,
}
impl fmt::Display for PlanningError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Timeout => {
write!(f, "No solution found within timeout.")
}
Self::NoSolutionFound => {
write!(f, "No solution found.")
}
Self::PlannerUninitialised => {
write!(
f,
"<Planner>.setup() was not called, thus Planner is uninitialised."
)
}
Self::InvalidStartState => {
write!(f, "Start state is not valid in the current StateSpace.")
}
Self::UnsampledStateSpace => {
write!(
f,
"StateSpace is not sampled. Either Tree or Roadmap is empty."
)
}
}
}
}
impl error::Error for PlanningError {}