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
58
//! Validation errors produced by conic constructors and conversions.
use std::fmt;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
/// Validation errors for conic geometry models.
#[derive(Clone, Copy, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum ConicValidationError {
/// Eccentricity must be finite and non-negative.
InvalidEccentricity,
/// Semi-major axis must be finite and strictly positive.
InvalidSemiMajorAxis,
/// Periapsis distance must be finite and strictly positive.
InvalidPeriapsisDistance,
/// Semi-major axis is undefined for parabolic conics (`e == 1`).
ParabolicSemiMajorAxis,
/// Orientation angles must be finite.
InvalidOrientation,
/// A strict orientation constructor received an angle outside its canonical range.
///
/// `field` identifies the offending angle (`"inclination"`,
/// `"longitude_of_ascending_node"`, or `"argument_of_periapsis"`).
/// `value` is the rejected value, in degrees.
OutOfRange {
/// Name of the angle field that was out of range.
field: &'static str,
/// The rejected value, expressed in degrees.
value: f64,
},
}
impl fmt::Display for ConicValidationError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::InvalidEccentricity => write!(f, "invalid eccentricity"),
Self::InvalidSemiMajorAxis => write!(f, "invalid semi-major axis"),
Self::InvalidPeriapsisDistance => write!(f, "invalid periapsis distance"),
Self::ParabolicSemiMajorAxis => {
write!(
f,
"semi-major axis is undefined for parabolic conics (e == 1)"
)
}
Self::InvalidOrientation => write!(f, "orientation angles must be finite"),
Self::OutOfRange { field, value } => {
write!(
f,
"orientation angle `{field}` is out of canonical range: {value}°"
)
}
}
}
}
impl std::error::Error for ConicValidationError {}