terrand/error.rs
1//! Error types returned by fallible terrand operations.
2
3use thiserror::Error;
4
5/// Errors returned by terrand operations.
6#[derive(Error, Debug)]
7pub enum Error {
8 /// Cell dimensions must be positive finite values.
9 #[error("cell dimensions must be positive and finite, got x={x}, y={y}")]
10 InvalidCellSize {
11 /// Invalid x cell size.
12 x: f64,
13 /// Invalid y cell size.
14 y: f64,
15 },
16
17 /// Observer position is outside the DEM grid.
18 #[error("observer position ({row}, {col}) is outside grid of size ({height}, {width})")]
19 ObserverOutOfBounds {
20 /// Observer row index.
21 row: usize,
22 /// Observer column index.
23 col: usize,
24 /// Grid height in rows.
25 height: usize,
26 /// Grid width in columns.
27 width: usize,
28 },
29
30 /// Viewshed maximum distance must be positive and finite, or positive infinity.
31 #[error("viewshed max_distance must be positive and finite, or infinity, got {0}")]
32 InvalidViewshedMaxDistance(f64),
33
34 /// Contour interval is not a positive, finite number.
35 #[error("contour interval must be positive and finite, got {0}")]
36 InvalidContourInterval(f64),
37
38 /// Two input grids have different shapes.
39 #[error("grid shapes must match: {left} has shape {left_shape:?}, {right} has shape {right_shape:?}")]
40 ShapeMismatch {
41 /// Name of the first grid.
42 left: &'static str,
43 /// Shape of the first grid.
44 left_shape: (usize, usize),
45 /// Name of the second grid.
46 right: &'static str,
47 /// Shape of the second grid.
48 right_shape: (usize, usize),
49 },
50
51 /// Pour point position is outside the input grid.
52 #[error("pour point ({row}, {col}) is outside grid of size ({height}, {width})")]
53 PourPointOutOfBounds {
54 /// Pour point row index.
55 row: usize,
56 /// Pour point column index.
57 col: usize,
58 /// Grid height in rows.
59 height: usize,
60 /// Grid width in columns.
61 width: usize,
62 },
63}
64
65/// Convenience alias for `Result<T, terrand::Error>`.
66pub type Result<T> = std::result::Result<T, Error>;