|
|
@ -15,28 +15,48 @@ fn assert_eq_floats(a: f64, b: f64) { |
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_calc_gravity() {
|
|
|
|
let a = RigidPoint::new(Vector3D::new(0.0, 0.0, 0.0), Vector3D::new(0.0, 0.0, 0.0), 1000.0, 0, 0.1);
|
|
|
|
let b = RigidPoint::new(Vector3D::new(10.0, 10.0, 20.0), Vector3D::new(0.0, 0.0, 0.0), 50.0, 1, 0.1);
|
|
|
|
|
|
|
|
let mut u = Universe { particles: vec![a, b], delta: 1.0};
|
|
|
|
let a = RigidPoint::new(
|
|
|
|
Vector3D::new(0.0, 0.0, 0.0),
|
|
|
|
Vector3D::new(0.0, 0.0, 0.0),
|
|
|
|
1000.0,
|
|
|
|
0,
|
|
|
|
0.1,
|
|
|
|
);
|
|
|
|
let b = RigidPoint::new(
|
|
|
|
Vector3D::new(10.0, 10.0, 20.0),
|
|
|
|
Vector3D::new(0.0, 0.0, 0.0),
|
|
|
|
50.0,
|
|
|
|
1,
|
|
|
|
0.1,
|
|
|
|
);
|
|
|
|
|
|
|
|
let mut u = Universe {
|
|
|
|
particles: vec![a, b],
|
|
|
|
delta: 1.0,
|
|
|
|
};
|
|
|
|
|
|
|
|
calc_velocities(&mut u, 1.0);
|
|
|
|
|
|
|
|
assert_eq!(u.particles[0].position, Vector3D::new(0.0, 0.0, 0.0));
|
|
|
|
assert_eq_floats(G * u.particles[1].mass / 24.494 / 24.494, u.particles[0].velocity.dist());
|
|
|
|
assert_eq_floats(G * u.particles[0].mass / 24.494 / 24.494, u.particles[1].velocity.dist());
|
|
|
|
assert_eq_floats(
|
|
|
|
G * u.particles[1].mass / 24.494 / 24.494,
|
|
|
|
u.particles[0].velocity.dist(),
|
|
|
|
);
|
|
|
|
assert_eq_floats(
|
|
|
|
G * u.particles[0].mass / 24.494 / 24.494,
|
|
|
|
u.particles[1].velocity.dist(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_octree_partitioning() {
|
|
|
|
//oct = Octree::new(Vector::new(0.0, 0.0, 0.0), Vector3::new(100.0, 100.0, 100.0));
|
|
|
|
let min: Vector3D = Vector3D::new(0.0, 0.0, 0.0);
|
|
|
|
let max: Vector3D = Vector3D::new(100.0, 100.0, 100.0);
|
|
|
|
let center = (min + max) / 2.0;
|
|
|
|
for i in 0..8 {
|
|
|
|
let (new_min, new_max) = Octree::get_octant_bounding_box_from_id(min, max, center, i);
|
|
|
|
let new_center = (new_min + new_max) / 2.0;
|
|
|
|
assert_eq!(i, Octree::get_id_from_center(center, new_center));
|
|
|
|
}
|
|
|
|
//oct = Octree::new(Vector::new(0.0, 0.0, 0.0), Vector3::new(100.0, 100.0, 100.0));
|
|
|
|
let min: Vector3D = Vector3D::new(0.0, 0.0, 0.0);
|
|
|
|
let max: Vector3D = Vector3D::new(100.0, 100.0, 100.0);
|
|
|
|
let center = (min + max) / 2.0;
|
|
|
|
for i in 0..8 {
|
|
|
|
let (new_min, new_max) = Octree::get_octant_bounding_box_from_id(min, max, center, i);
|
|
|
|
let new_center = (new_min + new_max) / 2.0;
|
|
|
|
assert_eq!(i, Octree::get_id_from_center(center, new_center));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|