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
use super::{interpolation::TInterpolation, temporal::Temporal, tinstant::TInstant};
pub trait TSequence: Temporal {
/// ## Arguments
/// * `values` - A slice of temporal instants (`TInstant`) that represent the values of the temporal sequence.
/// * `interpolation` - The interpolation method to use for the temporal sequence.
///
/// ## Returns
/// Returns an instance of a type implementing the `TSequence` trait.
///
/// ## Note
/// We assume that the lower bound will be inclusive and
/// the upper one exclusive (except for Discrete interpolations and instantaneous sequences, where it's inclusive), if you find yourself needing another variant, report it.
fn new<Inst: AsRef<Self::TI>>(values: &[Inst], interpolation: TInterpolation) -> Self {
let mut t_list: Vec<_> = values
.iter()
.map(|i| i.as_ref().inner_as_tinstant().cast_mut())
.collect();
// The default for discrete instances or instantaneous sequences is an inclusive upper bound
let upper_inclusive = matches!(
interpolation,
TInterpolation::Discrete | TInterpolation::Stepwise
) || values.len() == 1;
TSequence::from_inner(unsafe {
meos_sys::tsequence_make(
t_list.as_mut_ptr(),
t_list.len() as i32,
true,
upper_inclusive,
interpolation as u32,
true,
)
})
}
fn from_inner(inner: *mut meos_sys::TSequence) -> Self;
fn inner_mut_as_tsequence(&self) -> *mut meos_sys::TSequence;
fn inner_as_tsequence(&self) -> *const meos_sys::TSequence {
self.inner_mut_as_tsequence().cast()
}
fn is_lower_inclusive(&self) -> bool {
unsafe { meos_sys::temporal_lower_inc(self.inner()) }
}
fn is_upper_inclusive(&self) -> bool {
unsafe { meos_sys::temporal_upper_inc(self.inner()) }
}
}