feat(argus-semantics): complete boolean semantics
This commit is contained in:
parent
ad9afb4eba
commit
c916db3853
6 changed files with 149 additions and 48 deletions
|
|
@ -277,9 +277,13 @@ impl<T> Signal<T> {
|
|||
// We will now loop over the sync points, compare across signals and (if
|
||||
// an intersection happens) we will have to compute the intersection point
|
||||
for t in sync_points {
|
||||
let lhs = self.at(*t).expect("value must be present at given time");
|
||||
let rhs = other.at(*t).expect("values must be present at given time");
|
||||
let ord = lhs.partial_cmp(rhs).unwrap();
|
||||
let lhs = self
|
||||
.interpolate_at::<Interp>(*t)
|
||||
.unwrap_or_else(|| panic!("value must be present at given time {:?}.", t));
|
||||
let rhs = other
|
||||
.interpolate_at::<Interp>(*t)
|
||||
.unwrap_or_else(|| panic!("value must be present at given time {:?}.", t));
|
||||
let ord = lhs.partial_cmp(&rhs).unwrap();
|
||||
|
||||
// We will check for any intersections between the current sample and the
|
||||
// previous one before we push the current sample time
|
||||
|
|
@ -289,12 +293,20 @@ impl<T> Signal<T> {
|
|||
if let (Less, Greater) | (Greater, Less) = (last, ord) {
|
||||
// Find the point of intersection between the points.
|
||||
let a = utils::Neighborhood {
|
||||
first: self.at(tm1).cloned().map(|value| Sample { time: tm1, value }),
|
||||
second: self.at(*t).cloned().map(|value| Sample { time: *t, value }),
|
||||
first: self
|
||||
.interpolate_at::<Interp>(tm1)
|
||||
.map(|value| Sample { time: tm1, value }),
|
||||
second: self
|
||||
.interpolate_at::<Interp>(*t)
|
||||
.map(|value| Sample { time: *t, value }),
|
||||
};
|
||||
let b = utils::Neighborhood {
|
||||
first: other.at(tm1).cloned().map(|value| Sample { time: tm1, value }),
|
||||
second: other.at(*t).cloned().map(|value| Sample { time: *t, value }),
|
||||
first: other
|
||||
.interpolate_at::<Interp>(tm1)
|
||||
.map(|value| Sample { time: tm1, value }),
|
||||
second: other
|
||||
.interpolate_at::<Interp>(*t)
|
||||
.map(|value| Sample { time: *t, value }),
|
||||
};
|
||||
let intersect = Interp::find_intersection(&a, &b);
|
||||
return_points.push(intersect.time);
|
||||
|
|
|
|||
|
|
@ -113,8 +113,8 @@ macro_rules! interpolate_for_num {
|
|||
|
||||
// We need to do stable linear interpolation
|
||||
// https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p0811r3.html
|
||||
let a: f64 = cast(first.value).unwrap();
|
||||
let b: f64 = cast(second.value).unwrap();
|
||||
let a: f64 = cast(first.value).unwrap_or_else(|| panic!("unable to cast {:?} to f64", first.value));
|
||||
let b: f64 = cast(second.value).unwrap_or_else(|| panic!("unable to cast {:?} to f64", second.value));
|
||||
|
||||
// Set t to a value in [0, 1]
|
||||
let t = (at - t1) / (t2 - t1);
|
||||
|
|
@ -137,20 +137,20 @@ macro_rules! interpolate_for_num {
|
|||
// https://en.wikipedia.org/wiki/Line%E2%80%93line_intersection#Given_two_points_on_each_line
|
||||
use num_traits::cast;
|
||||
|
||||
let Sample { time: t1, value: y1 } = a.first.unwrap();
|
||||
let Sample { time: t2, value: y2 } = a.second.unwrap();
|
||||
let Sample { time: t3, value: y3 } = b.first.unwrap();
|
||||
let Sample { time: t4, value: y4 } = b.second.unwrap();
|
||||
let Sample { time: t1, value: y1 } = (a.first).unwrap();
|
||||
let Sample { time: t2, value: y2 } = (a.second).unwrap();
|
||||
let Sample { time: t3, value: y3 } = (b.first).unwrap();
|
||||
let Sample { time: t4, value: y4 } = (b.second).unwrap();
|
||||
|
||||
let t1 = t1.as_secs_f64();
|
||||
let t2 = t2.as_secs_f64();
|
||||
let t3 = t3.as_secs_f64();
|
||||
let t4 = t4.as_secs_f64();
|
||||
|
||||
let y1: f64 = cast(y1).unwrap();
|
||||
let y2: f64 = cast(y2).unwrap();
|
||||
let y3: f64 = cast(y3).unwrap();
|
||||
let y4: f64 = cast(y4).unwrap();
|
||||
let y1: f64 = cast(y1).unwrap_or_else(|| panic!("unable to cast {:?} to f64", y1));
|
||||
let y2: f64 = cast(y2).unwrap_or_else(|| panic!("unable to cast {:?} to f64", y2));
|
||||
let y3: f64 = cast(y3).unwrap_or_else(|| panic!("unable to cast {:?} to f64", y3));
|
||||
let y4: f64 = cast(y4).unwrap_or_else(|| panic!("unable to cast {:?} to f64", y4));
|
||||
|
||||
let denom = ((t1 - t2) * (y3 - y4)) - ((y1 - y2) * (t3 - t4));
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue