Skip to content

Commit f6d649b

Browse files
author
=
committed
post-merge refactoring
1 parent 70caa9f commit f6d649b

5 files changed

Lines changed: 25 additions & 36 deletions

File tree

client/src/sim.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,9 @@ impl Sim {
412412
}
413413
}
414414

415-
// helper function for handle_forces
415+
/// checks to see if there are any non-Void voxels near Position.
416+
// acts as a helper function for handle_forces
417+
// currently uses a hyperbolic equivilent of an AABB.
416418
fn check_collision(&self, pos: Position) -> bool {
417419
let params = self.params.as_ref().unwrap();
418420

@@ -441,10 +443,7 @@ impl Sim {
441443
ref voxels,
442444
} => {
443445
for voxel_address in cbb.every_voxel() {
444-
if match voxels.get(voxel_address as usize) {
445-
Material::Void => false,
446-
_ => true,
447-
} {
446+
if !matches!(voxels.get(voxel_address as usize), Material::Void) {
448447
return true;
449448
}
450449
}

common/src/collision.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ impl BoundingBox {
152152
}
153153
}
154154

155-
pub fn every_voxel_address<'a>(&'a self) -> impl Iterator<Item = VoxelAddress> + 'a {
155+
pub fn every_voxel_address(&self) -> impl Iterator<Item = VoxelAddress> + '_ {
156156
self.bounding_boxes.iter().flat_map(|cbb| {
157157
cbb.every_voxel().map(move |index| VoxelAddress {
158158
node: cbb.node,
@@ -242,7 +242,7 @@ impl ChunkBoundingBox {
242242
}
243243
}
244244

245-
pub fn every_voxel<'b>(&'b self) -> impl Iterator<Item = u32> + 'b {
245+
pub fn every_voxel(&self) -> impl Iterator<Item = u32> + '_ {
246246
let lwm = (self.dimension as u32) + 2;
247247
(self.min_xyz[2]..self.max_xyz[2]).flat_map(move |z| {
248248
(self.min_xyz[1]..self.max_xyz[1]).flat_map(move |y| {
@@ -260,9 +260,11 @@ lazy_static! {
260260
static ref PERPENDICULAR_VERTEX: [[Option<Vertex>; VERTEX_COUNT]; SIDE_COUNT] = {
261261
let mut result = [[None; VERTEX_COUNT]; SIDE_COUNT];
262262

263-
for s in 0..SIDE_COUNT {
264-
let side = Side::from_index(s);
263+
for side in Side::iter() {
265264
let incident_vertices = side.vertices();
265+
266+
// 'v' and 'vertex as usize' will have different values.
267+
#[allow(clippy::needless_range_loop)]
266268
for v in 0..5 {
267269
let vertex = incident_vertices[v];
268270
let mut vertex_counts = [0; VERTEX_COUNT];
@@ -280,9 +282,9 @@ lazy_static! {
280282
// inceident corners as not perpendicular
281283
for i in side.vertices().iter() {vertex_counts[*i as usize] = -1}
282284

283-
for i in 0..VERTEX_COUNT {
284-
if vertex_counts[i] == 2 {
285-
result[s][vertex as usize] = Some(Vertex::from_index(i));
285+
for i in Vertex::iter() {
286+
if vertex_counts[i as usize] == 2 {
287+
result[side as usize][vertex as usize] = Some(i);
286288
break;
287289
}
288290
}
@@ -295,10 +297,7 @@ lazy_static! {
295297
#[cfg(test)]
296298
mod tests {
297299
use super::*;
298-
use crate::node::{DualGraph, Node};
299-
use crate::Chunks;
300300
use crate::{graph::Graph, proto::Position, traversal::ensure_nearby};
301-
use approx::*;
302301

303302
const CHUNK_SIZE: u8 = 12_u8; // might want to test with multiple values in the future.
304303
static CHUNK_SIZE_F: f64 = CHUNK_SIZE as f64;
@@ -460,7 +459,7 @@ mod tests {
460459
BoundingBox::create_aabb(NodeId::ROOT, position, radius, &graph, CHUNK_SIZE);
461460

462461
let mut actual_voxels = 0;
463-
for address in bb.every_voxel_address() {
462+
for _address in bb.every_voxel_address() {
464463
actual_voxels += 1;
465464
}
466465

common/src/force.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl ForceParams {
3333
is_colliding: bool,
3434
time: f64,
3535
) -> na::Vector4<f64> {
36-
let mut velocity = inital_velocity.clone();
36+
let mut velocity = *inital_velocity;
3737

3838
// with current collsion detection tech, we want the player to slowly rise if they are in the ground
3939
if is_colliding {
@@ -48,17 +48,17 @@ impl ForceParams {
4848

4949
/// returns the change in velocity that occurs by pulled by gravity at "height" for "time"
5050
fn gravity(&self, down: &na::Vector4<f64>, height: f64, time: f64) -> na::Vector4<f64> {
51-
return match self.gravity_type {
51+
match self.gravity_type {
5252
GravityMethod::PlanarConstant => down * (self.gravity_intensity * time),
5353
GravityMethod::PlanarDivergent => {
5454
down * (self.gravity_intensity * time / height.cosh().powi(2))
5555
}
5656
GravityMethod::Zero => na::zero(),
57-
};
57+
}
5858
}
5959

6060
/// rewrites velocity to account for time spent under drag.
6161
fn air_drag(&self, inital_velocity: &na::Vector4<f64>, time: f64) -> na::Vector4<f64> {
62-
return inital_velocity * self.air_drag_factor.powf(time);
62+
inital_velocity * self.air_drag_factor.powf(time)
6363
}
6464
}

common/src/math.rs

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,12 @@ pub fn translate_normal<N: RealField>(
112112
v0: na::Vector4<N>,
113113
) -> na::Vector4<N> {
114114
let d = distance(&p0, &p1);
115-
if !(d >= na::zero()) {
115+
// TODO: verfiy this is equvilent to !(d >= na::zero())
116+
if na::zero::<N>() > d {
116117
return v0;
117118
}
118119

119-
let v1 = v0 * d.cosh() + p1 * d.sinh();
120-
return v1;
120+
v0 * d.cosh() + p1 * d.sinh()
121121
}
122122

123123
/// normalizes vector v with repect to translation matrix t
@@ -131,12 +131,12 @@ pub fn normalize_vector<N: RealField>(t: na::Matrix4<N>, v: na::Vector4<N>) -> n
131131
let v_mag = m.sqrt();
132132
let v_norm = v / v_mag;
133133

134-
return (v_norm + p * mip(&p, &v_norm)) * v_mag;
134+
(v_norm + p * mip(&p, &v_norm)) * v_mag
135135
}
136136

137137
/// make a orthogonal to b
138138
pub fn orthogonalize<N: RealField>(a: &na::Vector4<N>, b: &na::Vector4<N>) -> na::Vector4<N> {
139-
return a - b * (mip(a, b) / mip(b, b));
139+
a - b * (mip(a, b) / mip(b, b))
140140
}
141141

142142
#[rustfmt::skip]
@@ -297,20 +297,11 @@ mod tests {
297297

298298
assert_abs_diff_eq!(mip(&vec2, &orth), 0.0, epsilon = 1e-5);
299299
}
300-
/*
300+
301301
#[test]
302302
fn translate_normal_identity() {
303303
let p = na::Vector4::new(-0.03635, 0.95129, 0.0, 1.38068);
304304
let norm = na::Vector4::new(1.0, 0.0, 0.0, 0.0);
305305
assert_abs_diff_eq!(translate_normal(p, p, norm), norm, epsilon = 1e-5);
306-
}*/
307-
308-
fn translate_normal_still_normal() {
309-
let p1 = na::Vector4::new(-0.03635, 0.95129, 0.0, 1.38068);
310-
let p0 = origin();
311-
let norm = na::Vector4::new(1.0, 0.0, 0.0, 0.0);
312-
let trans = translate_normal(p0, p1, norm);
313-
assert_abs_diff_eq!(mip(&trans, &trans), 1.0, epsilon = 1e-5);
314-
assert_abs_diff_eq!(mip(&trans, &p1), 0.0, epsilon = 1e-5);
315306
}
316307
}

common/src/worldgen.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ impl NodeState {
130130
}
131131

132132
pub fn surface(&self) -> Plane<f64> {
133-
return self.surface;
133+
self.surface
134134
}
135135

136136
// if the node lies above the ground-plane or not

0 commit comments

Comments
 (0)