From c063ff22a4edb42631ea73968e0421c4d1838397 Mon Sep 17 00:00:00 2001 From: Matthew Gordon Date: Fri, 3 Apr 2020 23:33:06 -0400 Subject: [PATCH] Replace anonymous tuple with tuple struct to improve readability --- src/raycasting/bounding_volume_hierarchy.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/raycasting/bounding_volume_hierarchy.rs b/src/raycasting/bounding_volume_hierarchy.rs index f26e9c7..dff56a5 100644 --- a/src/raycasting/bounding_volume_hierarchy.rs +++ b/src/raycasting/bounding_volume_hierarchy.rs @@ -31,6 +31,8 @@ fn centre(bounds: &BoundingBox) -> Point3 { ) } +struct PrimitiveInfo(BoundingBox, Arc>); + impl BoundingVolumeHierarchy { pub fn build<'a, I>(primitives: I) -> Self where @@ -39,25 +41,25 @@ impl BoundingVolumeHierarchy { Self::from_node_vec( primitives .into_iter() - .map(|primitive| (primitive.bounding_box(), Arc::clone(primitive))) + .map(|primitive| PrimitiveInfo(primitive.bounding_box(), Arc::clone(primitive))) .collect(), ) } - fn from_node_vec(nodes: Vec<(BoundingBox, Arc>)>) -> Self { + fn from_node_vec(nodes: Vec>) -> Self { let overall_bounds = nodes .iter() - .fold(BoundingBox::empty(), |a, (b, _)| a.union(b)); + .fold(BoundingBox::empty(), |a, PrimitiveInfo(b, _)| a.union(b)); let normalizer = Point3Normalizer::new(overall_bounds); let mut nodes = nodes; - nodes.sort_by(|(a, _), (b, _)| { + nodes.sort_by(|PrimitiveInfo(a, _), PrimitiveInfo(b, _)| { morton_order_value_3d(normalizer.normalize(centre(a))) .cmp(&morton_order_value_3d(normalizer.normalize(centre(b)))) }); Self::from_sorted_nodes(nodes.as_slice()) } - fn from_sorted_nodes(nodes: &[(BoundingBox, Arc>)]) -> Self { + fn from_sorted_nodes(nodes: &[PrimitiveInfo]) -> Self { if nodes.len() >= 2 { let midpoint = nodes.len() / 2; let left = Box::new(Self::from_sorted_nodes(&nodes[..midpoint])); @@ -69,7 +71,7 @@ impl BoundingVolumeHierarchy { right, } } else if nodes.len() == 1 { - let (bounds, ref primitive) = nodes[0]; + let PrimitiveInfo(bounds, ref primitive) = nodes[0]; BoundingVolumeHierarchy::Leaf { bounds, primitive: Arc::clone(primitive),