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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use crate::Sac;
macro_rules! xeq {
($a:ident,$b:ident,$t:ty,$($x:ident),*) => {
$( if $a.$x != $b.$x {
println!("field {}: {} != {}", stringify!($x),$a.$x, $b.$x);
return false;
} )*
};
}
macro_rules! xeqf {
($a:ident,$b:ident,$t:ty,$($x:ident),*) => {
$( if ($a.$x - $b.$x).abs() > 1e-5 {
let dx = ($a.$x - $b.$x).abs();
println!("field {}: {} != {} [{}]", stringify!($x),$a.$x, $b.$x, dx);
return false;
} )*
};
}
fn veq(a: &[f32], b: &[f32], tol: f32) -> bool {
if a.len() != b.len() {
println!("Data Lenghts unequal: {} vs {}", a.len(), b.len());
return false;
}
if a != b {
for i in 0 .. a.len() {
println!("{:6} {:21.15e} {:21.15e} {:21.15e}", i, a[i], b[i], (a[i]-b[i]).abs());
if (a[i] - b[i]).abs() > tol {
println!("{}: {} {} tol: {}", i, a[i], b[i], tol);
return false;
}
}
return true;
}
true
}
impl PartialEq for Sac {
fn eq(&self, other: &Sac) -> bool {
sac_ints!(self, other, xeq);
sac_strings!(self, other, xeq);
sac_reals!(self, other, xeqf);
if self.npts != other.npts {
return false;
}
if self.y.len() != other.y.len() {
return false;
}
veq(&self.y, &other.y, 1e-5) &&
veq(&self.x, &other.x, 1e-5)
}
}