1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//! Error types for the geoproject library.
use thiserror::Error;
/// A specialized [`Result`] type for projection operations.
pub type Result<T> = std::result::Result<T, ProjectionError>;
/// Errors that can occur during projection operations.
#[derive(Debug, Error, Clone, PartialEq)]
pub enum ProjectionError {
/// The input coordinate is outside the valid domain of the projection.
#[error("coordinate out of bounds: {0}")]
OutOfBounds(String),
/// A required parameter is missing or invalid.
#[error("invalid parameter '{param}': {reason}")]
InvalidParameter {
/// Name of the invalid parameter.
param: String,
/// Reason why the parameter is invalid.
reason: String,
},
/// The inverse projection did not converge.
#[error("inverse projection failed to converge after {iterations} iterations")]
ConvergenceFailure {
/// Number of iterations attempted before aborting.
iterations: usize,
},
/// The coordinate is at a singular point of the projection (e.g. a pole).
#[error("singular point: {0}")]
SingularPoint(String),
/// The datum transformation failed.
#[error("datum transformation error: {0}")]
DatumError(String),
/// An unsupported projection was requested.
#[error("unsupported projection: {0}")]
UnsupportedProjection(String),
}
impl ProjectionError {
/// Convenience constructor for out-of-bounds errors.
pub fn out_of_bounds(msg: impl Into<String>) -> Self {
ProjectionError::OutOfBounds(msg.into())
}
/// Convenience constructor for invalid parameter errors.
pub fn invalid_param(param: impl Into<String>, reason: impl Into<String>) -> Self {
ProjectionError::InvalidParameter {
param: param.into(),
reason: reason.into(),
}
}
}