1
1
use std:: cmp:: Ordering ;
2
2
3
- use super :: interpolation:: Linear ;
4
3
use super :: traits:: SignalPartialOrd ;
5
4
use super :: { InterpolationMethod , Signal } ;
6
5
7
- impl < T > SignalPartialOrd for Signal < T >
6
+ impl < T > SignalPartialOrd < T > for Signal < T >
8
7
where
9
8
T : PartialOrd + Clone ,
10
- Linear : InterpolationMethod < T > ,
11
9
{
12
- fn signal_cmp < F > ( & self , other : & Self , op : F ) -> Option < Signal < bool > >
10
+ fn signal_cmp < F , I > ( & self , other : & Self , op : F ) -> Option < Signal < bool > >
13
11
where
14
12
F : Fn ( Ordering ) -> bool ,
13
+ I : InterpolationMethod < T > ,
15
14
{
16
15
// This has to be manually implemented and cannot use the apply2 functions.
17
16
// This is because if we have two signals that cross each other, then there is
18
17
// an intermediate point where the two signals are equal. This point must be
19
18
// added to the signal appropriately.
20
19
// the union of the sample points in self and other
21
- let sync_points = self . sync_with_intersection :: < Linear > ( other) ?;
20
+ let sync_points = self . sync_with_intersection :: < I > ( other) ?;
22
21
let sig: Option < Signal < bool > > = sync_points
23
22
. into_iter ( )
24
23
. map ( |t| {
25
- let lhs = self . interpolate_at :: < Linear > ( t) . unwrap ( ) ;
26
- let rhs = other. interpolate_at :: < Linear > ( t) . unwrap ( ) ;
24
+ let lhs = self . interpolate_at :: < I > ( t) . unwrap ( ) ;
25
+ let rhs = other. interpolate_at :: < I > ( t) . unwrap ( ) ;
27
26
let cmp = lhs. partial_cmp ( & rhs) ;
28
27
cmp. map ( |v| ( t, op ( v) ) )
29
28
} )
@@ -35,16 +34,18 @@ where
35
34
impl < T > Signal < T >
36
35
where
37
36
T : PartialOrd + Clone ,
38
- Linear : InterpolationMethod < T > ,
39
37
{
40
38
/// Compute the time-wise min of two signals
41
- pub fn min ( & self , other : & Self ) -> Self {
42
- let time_points = self . sync_with_intersection :: < Linear > ( other) . unwrap ( ) ;
39
+ pub fn min < I > ( & self , other : & Self ) -> Self
40
+ where
41
+ I : InterpolationMethod < T > ,
42
+ {
43
+ let time_points = self . sync_with_intersection :: < I > ( other) . unwrap ( ) ;
43
44
time_points
44
45
. into_iter ( )
45
46
. map ( |t| {
46
- let lhs = self . interpolate_at :: < Linear > ( t) . unwrap ( ) ;
47
- let rhs = other. interpolate_at :: < Linear > ( t) . unwrap ( ) ;
47
+ let lhs = self . interpolate_at :: < I > ( t) . unwrap ( ) ;
48
+ let rhs = other. interpolate_at :: < I > ( t) . unwrap ( ) ;
48
49
if lhs < rhs {
49
50
( t, lhs)
50
51
} else {
@@ -55,13 +56,16 @@ where
55
56
}
56
57
57
58
/// Compute the time-wise max of two signals
58
- pub fn max ( & self , other : & Self ) -> Self {
59
- let time_points = self . sync_with_intersection :: < Linear > ( other) . unwrap ( ) ;
59
+ pub fn max < I > ( & self , other : & Self ) -> Self
60
+ where
61
+ I : InterpolationMethod < T > ,
62
+ {
63
+ let time_points = self . sync_with_intersection :: < I > ( other) . unwrap ( ) ;
60
64
time_points
61
65
. into_iter ( )
62
66
. map ( |t| {
63
- let lhs = self . interpolate_at :: < Linear > ( t) . unwrap ( ) ;
64
- let rhs = other. interpolate_at :: < Linear > ( t) . unwrap ( ) ;
67
+ let lhs = self . interpolate_at :: < I > ( t) . unwrap ( ) ;
68
+ let rhs = other. interpolate_at :: < I > ( t) . unwrap ( ) ;
65
69
if lhs > rhs {
66
70
( t, lhs)
67
71
} else {
0 commit comments