Skip to main content

hydr_structures/structures/gate/trajectory/
accuracy.rs

1//! Explicit directional limits and numerical opening budgets.
2
3use crate::structures::{StructureError, StructureInputErrorKind};
4
5/// Finite nonnegative directional speed limits. Zero prohibits motion in that direction.
6#[derive(Clone, Copy, Debug, PartialEq)]
7pub struct GateMotionLimits {
8    /// Maximum increasing-opening speed in metres per second.
9    pub maximum_opening_speed_m_per_s: f64,
10    /// Maximum decreasing-opening speed in metres per second.
11    pub maximum_closing_speed_m_per_s: f64,
12}
13impl GateMotionLimits {
14    pub(super) fn check(self) -> Result<(), StructureError> {
15        check(
16            self.maximum_opening_speed_m_per_s,
17            "maximum_opening_speed_m_per_s",
18        )?;
19        check(
20            self.maximum_closing_speed_m_per_s,
21            "maximum_closing_speed_m_per_s",
22        )
23    }
24}
25/// Explicit absolute-or-relative receipt admission. Neither field has an implicit minimum.
26#[derive(Clone, Copy, Debug, PartialEq)]
27pub struct GateTrajectoryAccuracy {
28    /// Maximum absolute opening-error receipt in metres.
29    pub maximum_absolute_opening_error_m: f64,
30    /// Maximum outward relative opening-error receipt.
31    pub maximum_relative_opening_error: f64,
32}
33impl GateTrajectoryAccuracy {
34    pub(super) fn check(self) -> Result<(), StructureError> {
35        check(
36            self.maximum_absolute_opening_error_m,
37            "maximum_absolute_opening_error_m",
38        )?;
39        check(
40            self.maximum_relative_opening_error,
41            "maximum_relative_opening_error",
42        )
43    }
44}
45fn check(value: f64, name: &str) -> Result<(), StructureError> {
46    if !value.is_finite() || value < 0.0 {
47        return Err(StructureError::input(
48            StructureInputErrorKind::Definition,
49            format!("{name}={value}: supply an explicit finite nonnegative limit"),
50        ));
51    }
52    Ok(())
53}