-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathstructs.rs
87 lines (78 loc) · 1.99 KB
/
structs.rs
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/// 3D vector.
#[derive(Clone, Copy)]
pub struct Vector {
pub x: f64,
pub y: f64,
pub z: f64,
}
impl Vector {
pub fn new(x: f64, y: f64, z: f64) -> Vector {
Vector {
x,
y,
z
}
}
/// Calculates vector magnitude.
pub fn magnitude(&self) -> f64 {
(self.x*self.x + self.y*self.y + self.z*self.z).sqrt()
}
/// Assigns vector values from another vector.
pub fn assign(&mut self, other: &Vector) {
self.x = other.x;
self.y = other.y;
self.z = other.z;
}
/// Normalizes vector components to magnitude 1.
pub fn normalize(&mut self) {
let magnitude = self.magnitude();
self.x /= magnitude;
self.y /= magnitude;
self.z /= magnitude;
}
/// Add this vector and another and return a new vector.
pub fn add(&self, other: &Vector) -> Vector {
Vector::new(self.x + other.x, self.y + other.y, self.z + other.z)
}
pub fn dot(&self, other: &Vector) -> f64 {
self.x*other.x + self.y*other.y + self.z*other.z
}
}
/// TrajectoryElement is a trajectory-tracking object that includes x, y, z, and the current energy.
#[derive(Clone)]
pub struct TrajectoryElement {
pub E: f64,
pub x: f64,
pub y: f64,
pub z: f64,
}
impl TrajectoryElement {
pub fn new(E: f64, x: f64, y: f64, z: f64) -> TrajectoryElement {
TrajectoryElement {
E,
x,
y,
z
}
}
}
/// Energy loss is an output tracker that tracks the separate nuclear and electronic energy losses.
#[derive(Clone)]
pub struct EnergyLoss {
pub En: f64,
pub Ee: f64,
pub x: f64,
pub y: f64,
pub z: f64,
}
impl EnergyLoss {
pub fn new(Ee: f64, En: f64, x: f64, y: f64, z: f64) -> EnergyLoss {
EnergyLoss {
En,
Ee,
x,
y,
z
}
}
}