Skip to main content

hydr_structures/structures/gate/trajectory/
definition.rs

1//! Original immutable trajectory inputs and static admission.
2
3use super::accuracy::{GateMotionLimits, GateTrajectoryAccuracy};
4use crate::structures::{StructureError, StructureInputErrorKind};
5
6/// One original SI gate-opening coordinate.
7#[derive(Clone, Copy, Debug, PartialEq)]
8pub struct GateOpeningKnot {
9    /// Nonnegative elapsed time in seconds.
10    pub time_s: f64,
11    /// Nonnegative opening in metres.
12    pub opening_m: f64,
13}
14
15/// Immutable continuous piecewise-linear opening with explicit motion and accuracy policies.
16#[derive(Clone, Debug, PartialEq)]
17pub struct GateOpeningTrajectory {
18    knots: Vec<GateOpeningKnot>,
19    motion_limits: GateMotionLimits,
20    accuracy: GateTrajectoryAccuracy,
21    provenance: String,
22}
23impl GateOpeningTrajectory {
24    /// Check original inputs. Binding checks motion arithmetic and the actual gate range.
25    pub fn new(
26        knots: Vec<GateOpeningKnot>,
27        motion_limits: GateMotionLimits,
28        accuracy: GateTrajectoryAccuracy,
29        provenance: String,
30    ) -> Result<Self, StructureError> {
31        crate::structures::definition::text(&provenance, "gate trajectory provenance")?;
32        motion_limits.check()?;
33        accuracy.check()?;
34        if knots.len() < 2 {
35            return Err(StructureError::input(
36                StructureInputErrorKind::Definition,
37                "gate trajectory needs at least two knots: supply explicit closed support",
38            ));
39        }
40        for (index, knot) in knots.iter().enumerate() {
41            if !knot.time_s.is_finite()
42                || knot.time_s < 0.0
43                || !knot.opening_m.is_finite()
44                || knot.opening_m < 0.0
45            {
46                return Err(StructureError::input(
47                    StructureInputErrorKind::Definition,
48                    format!(
49                        "gate knot={index},value={knot:?}: supply finite nonnegative time and opening"
50                    ),
51                ));
52            }
53        }
54        for (index, pair) in knots.windows(2).enumerate() {
55            if pair[1].time_s <= pair[0].time_s {
56                return Err(StructureError::input(
57                    StructureInputErrorKind::Definition,
58                    format!(
59                        "gate segment={index},times={:?}/{:?}: supply strictly increasing original times",
60                        pair[0].time_s, pair[1].time_s
61                    ),
62                ));
63            }
64        }
65        Ok(Self {
66            knots,
67            motion_limits,
68            accuracy,
69            provenance,
70        })
71    }
72    /// Complete original coordinates without extrapolation.
73    pub fn knots(&self) -> &[GateOpeningKnot] {
74        &self.knots
75    }
76    /// Original directional speed limits.
77    pub fn motion_limits(&self) -> GateMotionLimits {
78        self.motion_limits
79    }
80    /// Original numerical opening-error policy.
81    pub fn accuracy(&self) -> GateTrajectoryAccuracy {
82        self.accuracy
83    }
84    /// Original source and operating-envelope evidence.
85    pub fn provenance(&self) -> &str {
86        &self.provenance
87    }
88}