1use thiserror::Error;
2
3#[derive(Error, Debug)]
5pub enum ProjectionError {
6 #[error("Projection parameter {0} is not finite")]
8 ParamNotFinite(&'static str),
9
10 #[error("Parameter {0} must be definied")]
12 ParamRequired(&'static str),
13
14 #[error("Parameter {0} is out of required range {1}..{2}")]
16 ParamOutOfRange(&'static str, f64, f64),
17
18 #[error("Incorrect projection parameters: {0}")]
20 IncorrectParams(&'static str),
21
22 #[error("Attempt to project lon: {0} lat: {1} results in not finite result")]
24 ProjectionImpossible(f64, f64),
25
26 #[error("Attempt to inverse project x: {0} y: {1} results in not finite result")]
28 InverseProjectionImpossible(f64, f64),
29}
30
31macro_rules! unpack_required_parameter {
32 ($self:ident, $param: ident) => {
33 $self
34 .$param
35 .ok_or(ProjectionError::ParamRequired(stringify!($param)))?
36 };
37}
38pub(crate) use unpack_required_parameter;
39
40macro_rules! ensure_finite {
41 ($param:ident) => {
42 if !$param.is_finite() {
43 return Err(ProjectionError::ParamNotFinite(stringify!($param)));
44 }
45 };
46
47 ($first:ident, $($rest:ident),+$(,)?) => {
48 ensure_finite!($first);
49 ensure_finite!($($rest),+);
50 };
51}
52pub(crate) use ensure_finite;
53
54macro_rules! ensure_within_range {
55 ($param:ident, $range:expr) => {
56 if !($range).contains(&$param) {
57 return Err(ProjectionError::ParamOutOfRange(
58 stringify!($param),
59 $range.start,
60 $range.end,
61 ));
62 }
63 };
64}
65pub(crate) use ensure_within_range;