use crate::geom::Point;
use core::fmt;
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum Error {
CoordinateOutOfRange(Point),
InvalidParameter(&'static str),
TooLarge,
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::CoordinateOutOfRange(p) => {
write!(
f,
"coordinate ({}, {}) outside the supported range ±2^40",
p.x, p.y
)
}
Error::InvalidParameter(s) => write!(f, "invalid parameter: {s}"),
Error::TooLarge => write!(f, "input too large"),
}
}
}
impl std::error::Error for Error {}
pub type Result<T> = core::result::Result<T, Error>;
#[inline]
pub(crate) fn check_point(p: Point) -> Result<()> {
if p.in_range() {
Ok(())
} else {
Err(Error::CoordinateOutOfRange(p))
}
}