physsol/
point.rs

1use num_traits::{Float};
2use vec::*;
3use euler::{Wrap as EulerWrap, Var as EulerVar};
4use rk4::{Wrap as RK4Wrap, Var as RK4Var};
5
6macro_rules! point_struct {
7    ($P:ident, $V:ident) => (
8        #[derive(Clone, Debug, PartialEq)]
9        pub struct $P<T> where T: Copy + Float {
10            pub pos: $V<T>,
11            pub vel: $V<T>,
12        }
13    )
14}
15
16macro_rules! point_euler {
17    ($P:ident, $V:ident) => (
18        impl<'a, T> EulerVar<T> for EulerWrap<&'a mut $P<T>> where T: Copy + Float {
19            fn step(&mut self, dt: T) {
20                (&mut self.0.pos, &mut self.1.pos).step(dt);
21                (&mut self.0.vel, &mut self.1.vel).step(dt);
22            }
23        }
24        impl<'a, T> EulerVar<T> for EulerWrap<$P<T>> where T: Copy + Float {
25            fn step(&mut self, dt: T) {
26                (&mut self.0, &mut self.1).step(dt);
27            }
28        }
29    )
30}
31
32macro_rules! point_rk4 {
33    ($P:ident, $V:ident) => (
34        impl<'a, T> RK4Var<T> for RK4Wrap<&'a mut $P<T>> where T: Copy + Float {
35            fn step(&mut self, dt: T, f: fn(&mut RK4Wrap<&mut T>, T)) {
36                (&mut self.0.pos, &mut self.1.pos, &mut self.2.pos, &mut self.3.pos).step(dt, f);
37                (&mut self.0.vel, &mut self.1.vel, &mut self.2.vel, &mut self.3.vel).step(dt, f);
38            }
39        }
40        impl<'a, T> RK4Var<T> for RK4Wrap<$P<T>> where T: Copy + Float {
41            fn step(&mut self, dt: T, f: fn(&mut RK4Wrap<&mut T>, T)) {
42                (&mut self.0, &mut self.1, &mut self.2, &mut self.3).step(dt, f);
43            }
44        }
45    )
46}
47
48macro_rules! point_all {
49    ($P:ident, $V:ident) => (
50        point_struct!($P, $V);
51        point_euler!($P, $V);
52        point_rk4!($P, $V);
53    )
54}
55
56point_all!(Point2, Vec2);
57point_all!(Point3, Vec3);
58point_all!(Point4, Vec4);