1- use crate :: math:: { Point , Real } ;
1+ use crate :: math:: { Point , Real , Vector } ;
22use crate :: query:: { PointProjection , PointQuery } ;
33use crate :: shape:: { Cuboid , FeatureId , Voxels , VoxelsChunkRef } ;
44
@@ -8,11 +8,15 @@ impl PointQuery for Voxels {
88 self . chunk_bvh ( )
99 . project_point ( pt, Real :: MAX , |chunk_id, _| {
1010 let chunk = self . chunk_ref ( chunk_id) ;
11- Some ( chunk. project_local_point_and_get_vox_id ( pt, solid) . 0 )
11+ chunk
12+ . project_local_point_and_get_vox_id ( pt, solid)
13+ . map ( |( proj, _) | proj)
1214 } )
13- . unwrap ( )
14- . 1
15- . 1
15+ . map ( |res| res. 1 . 1 )
16+ . unwrap_or ( PointProjection :: new (
17+ false ,
18+ Vector :: repeat ( Real :: MAX ) . into ( ) ,
19+ ) )
1620 }
1721
1822 #[ inline]
@@ -23,13 +27,16 @@ impl PointQuery for Voxels {
2327 self . chunk_bvh ( )
2428 . project_point_and_get_feature ( pt, Real :: MAX , |chunk_id, _| {
2529 let chunk = self . chunk_ref ( chunk_id) ;
26- let ( proj, vox) = chunk. project_local_point_and_get_vox_id ( pt, false ) ;
2730 // TODO: we need a way to return both the voxel id, and the feature on the voxel.
28- Some ( ( proj, FeatureId :: Face ( vox) ) )
31+ chunk
32+ . project_local_point_and_get_vox_id ( pt, false )
33+ . map ( |( proj, vox) | ( proj, FeatureId :: Face ( vox) ) )
2934 } )
30- . unwrap ( )
31- . 1
32- . 1
35+ . map ( |res| res. 1 . 1 )
36+ . unwrap_or ( (
37+ PointProjection :: new ( false , Vector :: repeat ( Real :: MAX ) . into ( ) ) ,
38+ FeatureId :: Unknown ,
39+ ) )
3340 }
3441}
3542
@@ -39,7 +46,7 @@ impl<'a> VoxelsChunkRef<'a> {
3946 & self ,
4047 pt : & Point < Real > ,
4148 solid : bool ,
42- ) -> ( PointProjection , u32 ) {
49+ ) -> Option < ( PointProjection , u32 ) > {
4350 // TODO: optimize this naive implementation that just iterates on all the voxels
4451 // from this chunk.
4552 let base_cuboid = Cuboid :: new ( self . parent . voxel_size ( ) / 2.0 ) ;
@@ -59,6 +66,6 @@ impl<'a> VoxelsChunkRef<'a> {
5966 }
6067 }
6168
62- ( result, result_vox_id as u32 )
69+ ( smallest_dist < Real :: MAX ) . then_some ( ( result, result_vox_id as u32 ) )
6370 }
6471}
0 commit comments