hydr_structures/structures/geometry/events.rs
1//! Event-time queries and epoch derivation for structure geometry schedules.
2
3use super::StructureGeometrySchedule;
4
5/// Earliest knot time strictly after `start_s` across `schedules`, or `None` when none remains.
6pub fn next_geometry_event_after(
7 schedules: &[StructureGeometrySchedule],
8 start_s: f64,
9) -> Option<f64> {
10 schedules
11 .iter()
12 .filter_map(|schedule| {
13 schedule
14 .track
15 .knot_times()
16 .into_iter()
17 .find(|&time| time > start_s)
18 })
19 .reduce(f64::min)
20}
21
22/// Active epoch index of every schedule at `time_s`, in schedule order.
23///
24/// The epoch is the number of knots with `knot.time_s <= time_s`. It is purely a function of
25/// `time_s`, so checkpoint import recomputes it and rejects any mismatch.
26pub fn active_geometry_epochs(schedules: &[StructureGeometrySchedule], time_s: f64) -> Vec<usize> {
27 schedules
28 .iter()
29 .map(|schedule| {
30 let times = schedule.track.knot_times();
31 times.partition_point(|&t| t <= time_s)
32 })
33 .collect()
34}