From cf86ee40a199dc84f7b8dd045e57b3a15bca79fb Mon Sep 17 00:00:00 2001 From: Crozet Sébastien Date: Tue, 6 Oct 2020 11:21:39 +0200 Subject: Use the WQuadtree for the exhaustive ray-cast too. --- src/geometry/wquadtree.rs | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/src/geometry/wquadtree.rs b/src/geometry/wquadtree.rs index 627ad9a..fe1ba2a 100644 --- a/src/geometry/wquadtree.rs +++ b/src/geometry/wquadtree.rs @@ -309,11 +309,9 @@ impl WQuadtree { // FIXME: implement a visitor pattern to merge intersect_aabb // and intersect_ray into a single method. - pub fn intersect_aabb(&self, aabb: &AABB) -> Vec { - let mut res = Vec::new(); - + pub fn intersect_aabb(&self, aabb: &AABB, out: &mut Vec) { if self.nodes.is_empty() { - return res; + return; } // Special case for the root. @@ -330,7 +328,7 @@ impl WQuadtree { // We found a leaf! // Unfortunately, invalid AABBs return a intersection as well. if let Some(proxy) = self.proxies.get(node.children[ii] as usize) { - res.push(proxy.data); + out.push(proxy.data); } } else { // Internal node, visit the child. @@ -343,15 +341,11 @@ impl WQuadtree { } } } - - res } - pub fn cast_ray(&self, ray: &Ray, max_toi: f32) -> Vec { - let mut res = Vec::new(); - + pub fn cast_ray(&self, ray: &Ray, max_toi: f32, out: &mut Vec) { if self.nodes.is_empty() { - return res; + return; } // Special case for the root. @@ -369,7 +363,7 @@ impl WQuadtree { // We found a leaf! // Unfortunately, invalid AABBs return a hit as well. if let Some(proxy) = self.proxies.get(node.children[ii] as usize) { - res.push(proxy.data); + out.push(proxy.data); } } else { // Internal node, visit the child. @@ -382,8 +376,6 @@ impl WQuadtree { } } } - - res } } -- cgit