@@ -431,15 +431,23 @@ impl<I: Index, R: Real> OctreeNode<I, R> {
431431 let mut counters: [ usize ; 8 ] = [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ;
432432 let mut non_ghost_counters: [ usize ; 8 ] = [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ;
433433
434+ let node_aabb = AxisAlignedBoundingBox3d :: new (
435+ grid. point_coordinates ( & self . min_corner ) ,
436+ grid. point_coordinates ( & self . max_corner ) ,
437+ ) ;
438+
434439 // Classify all particles of this leaf into the halfspaces relative to the split point
435440 assert_eq ! ( particles. len( ) , halfspace_flags. len( ) ) ;
436441 for ( particle_idx, particle_halfspace_flags) in
437442 particles. iter ( ) . copied ( ) . zip ( halfspace_flags. iter_mut ( ) )
438443 {
439- let relative_pos = particle_positions[ particle_idx] - split_coordinates;
444+ let pos = particle_positions[ particle_idx] ;
445+ let relative_pos = pos - split_coordinates;
446+
447+ let is_ghost_particle = !node_aabb. contains_point ( & pos) ;
440448
441449 // Check what the main octant (without margin) of the particle is to count ghost particles later
442- {
450+ if !is_ghost_particle {
443451 let main_octant: Octant = OctantAxisDirections :: classify ( & relative_pos) . into ( ) ;
444452 non_ghost_counters[ main_octant as usize ] += 1 ;
445453 }
@@ -538,6 +546,11 @@ impl<I: Index, R: Real> OctreeNode<I, R> {
538546 let tl_counters = ThreadLocal :: new ( ) ;
539547 let chunk_size = ChunkSize :: new ( parallel_policy, particles. len ( ) ) . chunk_size ;
540548
549+ let node_aabb = AxisAlignedBoundingBox3d :: new (
550+ grid. point_coordinates ( & self . min_corner ) ,
551+ grid. point_coordinates ( & self . max_corner ) ,
552+ ) ;
553+
541554 // Classify all particles of this leaf into its octants
542555 assert_eq ! ( particles. len( ) , octant_flags. len( ) ) ;
543556 particles
@@ -555,10 +568,13 @@ impl<I: Index, R: Real> OctreeNode<I, R> {
555568 . copied ( )
556569 . zip ( flags_chunk. iter_mut ( ) )
557570 . for_each ( |( particle_idx, particle_octant_flags) | {
571+ let pos = particle_positions[ particle_idx] ;
558572 let relative_pos = particle_positions[ particle_idx] - split_coordinates;
559573
574+ let is_ghost_particle = !node_aabb. contains_point ( & pos) ;
575+
560576 // Check what the main octant of the particle is (to count ghost particles)
561- {
577+ if !is_ghost_particle {
562578 let main_octant: Octant =
563579 OctantAxisDirections :: classify ( & relative_pos) . into ( ) ;
564580 non_ghost_counters[ main_octant as usize ] += 1 ;
0 commit comments