@@ -393,18 +393,23 @@ where
393393 let pos1 = c1. position . clone ( ) ;
394394 let mut pos_helper_1 = c1. position_helper . clone ( ) ;
395395
396- // Iterate over all remaining cells in the voxel
397- for _ in n + 1 ..n_cells {
396+ let mut apply_restrictions_c2 = |c2 : & mut Agent | {
398397 // Properties of cell 2
399- let ( c2, _) = cells_mut. nth ( 0 ) . unwrap ( ) ;
400398 let pos2 = c2. position . clone ( ) ;
401- let bbox2 = c2. cell . bounding_box ;
399+ let bbox2 = c2. bounding_box ;
400+ let pos_helper_2 = & mut c2. position_helper ;
402401
403402 // Only compute if bounding boxes are intersecting
404403 if bounding_boxes_intersect ( & bbox1, & bbox2) {
405- apply_restrictions ( & pos1, & mut pos_helper_1 , & c2 . position ) ;
406- apply_restrictions ( & pos2, & mut c2 . position_helper , & pos1 ) ;
404+ apply_restrictions ( & pos1, & pos2 , & mut pos_helper_1 ) ;
405+ apply_restrictions ( & pos2, & pos1 , pos_helper_2 ) ;
407406 }
407+ } ;
408+
409+ // Iterate over all remaining cells in the voxel
410+ for _ in n + 1 ..n_cells {
411+ let ( c2, _) = cells_mut. nth ( 0 ) . unwrap ( ) ;
412+ apply_restrictions_c2 ( c2) ;
408413 }
409414
410415 // Get neighbor cells and gather restrictions from them
@@ -415,9 +420,7 @@ where
415420 let mut cells_mut_2 = neighbor. cells . iter_mut ( ) ;
416421 for _ in 0 ..n_cells2 {
417422 let ( c2, _) = cells_mut_2. nth ( 0 ) . unwrap ( ) ;
418- let pos2 = c2. position . clone ( ) ;
419- apply_restrictions ( & pos1, & mut pos_helper_1, & c2. position ) ;
420- apply_restrictions ( & pos2, & mut c2. position_helper , & pos1) ;
423+ apply_restrictions_c2 ( c2) ;
421424 }
422425 }
423426
0 commit comments