Browse Source

formatting

pull/4/head
Stephen 5 months ago
parent
commit
fae7d388a6
3 changed files with 38 additions and 18 deletions
  1. +1
    -1
      rustfmt.toml
  2. +36
    -16
      src/tests.rs
  3. +1
    -1
      src/vector3d.rs

+ 1
- 1
rustfmt.toml View File

@ -1,2 +1,2 @@
tab_spaces = 4
hard_tabs = true
hard_tabs = true

+ 36
- 16
src/tests.rs View File

@ -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));
}
}

+ 1
- 1
src/vector3d.rs View File

@ -92,4 +92,4 @@ impl AddAssign for Vector3D {
self.y += other.y;
self.z += other.z;
}
}
}

Loading…
Cancel
Save