stimulus: add a structure to sum together two stimuli of different types

this may resemble the original List stuff. only it's more specialized,
for only summing two of a thing.
This commit is contained in:
2022-08-23 16:35:29 -07:00
parent 3326acd125
commit f47c713e0e

View File

@@ -482,6 +482,9 @@ pub trait StimExt<R>: Sized {
fn scaled<T: TimeVarying<R>>(self, scale: T) -> Scaled<Self, T> {
Scaled::new(self, scale)
}
fn summed<T: TimeVarying<R>>(self, with: T) -> Summed<Self, T> {
Summed::new(self, with)
}
}
impl<R, T> StimExt<R> for T {}
@@ -665,6 +668,21 @@ impl<R: Real, A: TimeVarying<R>, B: TimeVarying<R>> TimeVarying<R> for Scaled<A,
}
}
#[derive(Clone)]
pub struct Summed<A, B>(A, B);
impl<A, B> Summed<A, B> {
pub fn new(a: A, b: B) -> Self {
Self(a, b)
}
}
impl<R: Real, A: TimeVarying<R>, B: TimeVarying<R>> TimeVarying<R> for Summed<A, B> {
fn at(&self, t_sec: R) -> FieldMags<R> {
self.0.at(t_sec) + self.1.at(t_sec)
}
}
#[cfg(test)]
mod test {
use super::*;