Skip to content

Commit

Permalink
Eliminated most Clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
davids91 committed Oct 20, 2024
1 parent 3c2c703 commit b0ca9c0
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 74 deletions.
15 changes: 6 additions & 9 deletions src/octree/convert/magicavoxel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,7 @@ where
}
}

fn iterate_vox_tree<F: FnMut(&Model, &V3c<i32>, &Matrix3<i8>) -> ()>(
vox_tree: &DotVoxData,
mut fun: F,
) {
fn iterate_vox_tree<F: FnMut(&Model, &V3c<i32>, &Matrix3<i8>)>(vox_tree: &DotVoxData, mut fun: F) {
let mut node_stack: Vec<(u32, V3c<i32>, Matrix3<i8>, u32)> = Vec::new();

match &vox_tree.scenes[0] {
Expand All @@ -128,7 +125,7 @@ fn iterate_vox_tree<F: FnMut(&Model, &V3c<i32>, &Matrix3<i8>) -> ()>(
}
}

while 0 < node_stack.len() {
while !node_stack.is_empty() {
let (current_node, translation, rotation, index) = *node_stack.last().unwrap();
match &vox_tree.scenes[current_node as usize] {
SceneNode::Transform {
Expand Down Expand Up @@ -251,7 +248,7 @@ where
.max(position.z + model_size_half_lyup.z)
.max(position.z - model_size_half_lyup.z);
});
max_position_lyup = max_position_lyup - min_position_lyup;
max_position_lyup -= min_position_lyup;
let max_dimension = max_position_lyup
.x
.max(max_position_lyup.y)
Expand All @@ -265,7 +262,7 @@ where
CoordinateSystemType::RZUP,
CoordinateSystemType::LYUP,
);
let position = V3c::from(*position);
let position = *position;
let position_lyup = convert_coordinate(
position,
CoordinateSystemType::RZUP,
Expand All @@ -279,7 +276,7 @@ where
if model_size_lyup.z < 0 { -1 } else { 0 },
);

let mut vmin = V3c::unit(max_dimension as u32);
let mut vmin = V3c::unit(max_dimension);
let mut vmax = V3c::unit(0u32);
for voxel in &model.voxels {
let voxel_position = convert_coordinate(
Expand All @@ -297,7 +294,7 @@ where

shocovox_octree
.insert(
&V3c::<u32>::from(current_position + voxel_position.into()),
&V3c::<u32>::from(current_position + voxel_position),
T::new(vox_tree.palette[voxel.i as usize].into(), 0),
)
.ok()
Expand Down
32 changes: 12 additions & 20 deletions src/octree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ where
return None;
}
BrickData::Solid(voxel) => {
return Some(&voxel);
return Some(voxel);
}
}
}
Expand All @@ -144,7 +144,7 @@ where
if voxel.is_empty() {
return None;
}
return Some(&voxel);
return Some(voxel);
}
},
NodeContent::Internal(_) => {
Expand Down Expand Up @@ -181,47 +181,39 @@ where
debug_assert!(DIM < self.octree_size as usize);

// Hash the position to the target child
let child_octant_at_position = child_octant_for(&bounds, position);
let child_octant_at_position = child_octant_for(bounds, position);

// If the child exists, query it for the voxel
match &mut bricks[child_octant_at_position as usize] {
BrickData::Empty => {
return None;
}
BrickData::Empty => None,
BrickData::Parted(ref mut brick) => {
let bounds = Cube::child_bounds_for(&bounds, child_octant_at_position);
let bounds = Cube::child_bounds_for(bounds, child_octant_at_position);
let mat_index = Self::mat_index(&bounds, &V3c::from(*position));
if !brick[mat_index.x][mat_index.y][mat_index.z].is_empty() {
return Some(&mut brick[mat_index.x][mat_index.y][mat_index.z]);
}
return None;
}
BrickData::Solid(ref mut voxel) => {
return Some(voxel);
None
}
BrickData::Solid(ref mut voxel) => Some(voxel),
}
}
NodeContent::UniformLeaf(brick) => match brick {
BrickData::Empty => {
return None;
}
BrickData::Empty => None,
BrickData::Parted(brick) => {
let mat_index = Self::mat_index(&bounds, &V3c::from(*position));
let mat_index = Self::mat_index(bounds, &V3c::from(*position));
if brick[mat_index.x][mat_index.y][mat_index.z].is_empty() {
return None;
}
return Some(&mut brick[mat_index.x][mat_index.y][mat_index.z]);
Some(&mut brick[mat_index.x][mat_index.y][mat_index.z])
}
BrickData::Solid(voxel) => {
if voxel.is_empty() {
return None;
}
return Some(voxel);
Some(voxel)
}
},
&mut NodeContent::Nothing | &mut NodeContent::Internal(_) => {
return None;
}
&mut NodeContent::Nothing | &mut NodeContent::Internal(_) => None,
}
}

Expand Down
14 changes: 9 additions & 5 deletions src/octree/raytracing/bevy/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,10 @@ where
BrickData::Empty => (empty_marker(), false),
BrickData::Solid(voxel) => {
let albedo = voxel.albedo();
if !map_to_color_index_in_palette.contains_key(&albedo) {
map_to_color_index_in_palette.insert(albedo, color_palette.len());
if let std::collections::hash_map::Entry::Vacant(e) =
map_to_color_index_in_palette.entry(albedo)
{
e.insert(color_palette.len());
color_palette.push(Vec4::new(
albedo.r as f32 / 255.,
albedo.g as f32 / 255.,
Expand All @@ -144,8 +146,10 @@ where
for y in 0..DIM {
for x in 0..DIM {
let albedo = brick[x][y][z].albedo();
if !map_to_color_index_in_palette.contains_key(&albedo) {
map_to_color_index_in_palette.insert(albedo, color_palette.len());
if let std::collections::hash_map::Entry::Vacant(e) =
map_to_color_index_in_palette.entry(albedo)
{
e.insert(color_palette.len());
color_palette.push(Vec4::new(
albedo.r as f32 / 255.,
albedo.g as f32 / 255.,
Expand Down Expand Up @@ -190,7 +194,7 @@ where
let mut map_to_node_index_in_nodes_buffer = HashMap::new();
for i in 0..self.nodes.len() {
if self.nodes.key_is_valid(i) {
map_to_node_index_in_nodes_buffer.insert(i as usize, nodes.len());
map_to_node_index_in_nodes_buffer.insert(i, nodes.len());
nodes.push(Self::create_node_properties(self.nodes.get(i)));
}
}
Expand Down
38 changes: 19 additions & 19 deletions src/octree/raytracing/raytracing_on_cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,22 @@ where
} else {
self.head_index -= 1;
}
return Some(result);
Some(result)
}
}

pub(crate) fn last(&self) -> Option<&T> {
if 0 == self.count {
None
} else {
return Some(&self.data[self.head_index]);
Some(&self.data[self.head_index])
}
}
pub(crate) fn last_mut(&mut self) -> Option<&mut T> {
if 0 == self.count {
None
} else {
return Some(&mut self.data[self.head_index]);
Some(&mut self.data[self.head_index])
}
}
}
Expand All @@ -101,15 +101,15 @@ where
}

/// https://en.wikipedia.org/wiki/Digital_differential_analyzer_(graphics_algorithm)
/// Calculate the length of the ray should its iteration be stepped one unit in the [x/y/z] direction.
/// Calculate the length of the ray in case the iteration is stepped one unit in the [x/y/z] direction.
/// Changes with minimum ray iteration length shall be applied
/// inputs: current distances of the 3 components of the ray, unit size, Ray, scale factors of each xyz components
/// output: the step to the next sibling
/// The step is also returned in the given unit size ( based on the cell bounds )
/// * `ray` - The ray to base the step on
/// * `ray_current_distance` - The distance the ray iteration is currently at
/// * `current_bounds` - The cell which boundaries the current ray iteration intersects
/// * `ray_scale_factors` - Pre-computed dda values for the ray
/// inputs: current distances of the 3 components of the ray, unit size, Ray, scale factors of each xyz components
/// output: the step to the next sibling
pub(crate) fn dda_step_to_next_sibling(
ray: &Ray,
ray_current_distance: &mut f32,
Expand Down Expand Up @@ -238,7 +238,7 @@ where
current_index += V3c::<i32>::from(step);
position += step * Self::UNIT_IN_BITMAP_SPACE;
}
return rgb_result;
rgb_result
}

/// Iterates on the given ray and brick to find a potential intersection in 3D space
Expand Down Expand Up @@ -357,20 +357,20 @@ where
}
BrickData::Solid(voxel) => {
let impact_point = ray.point_at(*ray_current_distance);
return Some((
&voxel,
Some((
voxel,
impact_point,
cube_impact_normal(&brick_bounds, &impact_point),
));
cube_impact_normal(brick_bounds, &impact_point),
))
}
BrickData::Parted(brick) => {
if let Some(leaf_brick_hit) = Self::traverse_brick(
&ray,
ray,
ray_current_distance,
brick,
brick_occupied_bits,
&brick_bounds,
&ray_scale_factors,
brick_bounds,
ray_scale_factors,
direction_lut_index,
) {
let hit_bounds = Cube {
Expand All @@ -396,13 +396,13 @@ where
/// return reference of the data, collision point and normal at impact, should there be any
pub fn get_by_ray(&self, ray: &Ray) -> Option<(&T, V3c<f32>, V3c<f32>)> {
// Pre-calculated optimization variables
let ray_scale_factors = Self::get_dda_scale_factors(&ray);
let ray_scale_factors = Self::get_dda_scale_factors(ray);
let direction_lut_index = hash_direction(&ray.direction) as usize;

let mut node_stack: NodeStack<u32> = NodeStack::default();
let mut current_bounds = Cube::root_bounds(self.octree_size as f32);
let (mut ray_current_distance, mut target_octant) =
if let Some(root_hit) = current_bounds.intersect_ray(&ray) {
if let Some(root_hit) = current_bounds.intersect_ray(ray) {
let ray_current_distance = root_hit.impact_distance.unwrap_or(0.);
(
ray_current_distance,
Expand Down Expand Up @@ -493,7 +493,7 @@ where
// POP
node_stack.pop();
step_vec = Self::dda_step_to_next_sibling(
&ray,
ray,
&mut ray_current_distance,
&current_bounds,
&ray_scale_factors,
Expand Down Expand Up @@ -543,7 +543,7 @@ where
loop {
// step the iteration to the next sibling cell!
step_vec = Self::dda_step_to_next_sibling(
&ray,
ray,
&mut ray_current_distance,
&target_bounds,
&ray_scale_factors,
Expand Down Expand Up @@ -572,7 +572,7 @@ where
}
})
// In case the current node is leaf
|| match self.nodes.get(current_node_key as usize) {
|| match self.nodes.get(current_node_key) {
// Empty or internal nodes are not evaluated in this condition;
// Basically if there's no hit with a uniformleaf
// | It's either because the leaf is solid empty
Expand Down
Loading

0 comments on commit b0ca9c0

Please sign in to comment.