use core::fmt;
use mynd_math::MathError;
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
#[non_exhaustive]
pub enum GeometryError {
ZeroWidth,
ZeroHeight,
ZeroRectangleWidth,
ZeroRectangleHeight,
RectangleOutOfBounds,
ZeroRows,
ZeroRowBytes,
ZeroAlignment,
StrideTooSmall,
OffsetMisaligned,
StrideMisaligned,
NoPlanes,
PlanesOutOfOrder,
PlaneOverlap,
Arithmetic(MathError),
}
impl fmt::Display for GeometryError {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::ZeroWidth => formatter.write_str("image width must be nonzero"),
Self::ZeroHeight => formatter.write_str("image height must be nonzero"),
Self::ZeroRectangleWidth => formatter.write_str("rectangle width must be nonzero"),
Self::ZeroRectangleHeight => formatter.write_str("rectangle height must be nonzero"),
Self::RectangleOutOfBounds => {
formatter.write_str("rectangle exceeds its image dimensions")
}
Self::ZeroRows => formatter.write_str("plane row count must be nonzero"),
Self::ZeroRowBytes => formatter.write_str("plane row bytes must be nonzero"),
Self::ZeroAlignment => formatter.write_str("plane alignment must be nonzero"),
Self::StrideTooSmall => formatter.write_str("row stride is smaller than row bytes"),
Self::OffsetMisaligned => formatter.write_str("plane offset is not aligned"),
Self::StrideMisaligned => formatter.write_str("row stride is not aligned"),
Self::NoPlanes => formatter.write_str("plane set must be nonempty"),
Self::PlanesOutOfOrder => formatter.write_str("plane offsets are out of order"),
Self::PlaneOverlap => formatter.write_str("plane extents overlap"),
Self::Arithmetic(error) => write!(formatter, "geometry arithmetic failed: {error}"),
}
}
}
impl core::error::Error for GeometryError {
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
match self {
Self::Arithmetic(error) => Some(error),
_ => None,
}
}
}
pub type GeometryResult<T> = Result<T, GeometryError>;