fn partition(n: usize, space: &AABB, candidates: &Candidates) -> (f32, usize, usize, usize) {
        let mut best_cost = f32::INFINITY;
        let mut best_candidate_index = 0;

        // Variables to keep count the number of items in both subspace for each dimension
        let mut n_l = [0; 3];
        let mut n_r = [n; 3];

        // Keep n_l and n_r for the best splitting candidate
        let mut best_n_l = 0;
        let mut best_n_r = n;

        // Find best candidate
        for (i, candidate) in candidates.iter().enumerate() {
            let dim = candidate.dimension();

            // If the right candidate removes it from the right subspace
            if candidate.is_right() {
                n_r[dim] -= 1;
            }

            // Compute the cost of the split and update the best split
            let cost = Self::cost(&candidate.plane, space, n_l[dim], n_r[dim]);
            if cost < best_cost {
                best_cost = cost;
                best_candidate_index = i;
                best_n_l = n_l[dim];
                best_n_r = n_r[dim];
            }

            // If the left candidate add it from the left subspace
            if candidate.is_left() {
                n_l[dim] += 1;
            }
        }
        (best_cost, best_candidate_index, best_n_l, best_n_r)
    }
/// Compute the best splitting candidate
/// Return:
/// * Cost of the split
/// * Index of the best candidate
/// * Number of items in the left partition
/// * Number of items in the right partition
Compute the best splitting candidate
Return:
Cost of the split
Index of the best candidate
Number of items in the left partition
Number of items in the right partition
Compute the best splitting candidate Return : Cost of the split Index of the best candidate Number of items in the left partition Number of items in the right partition
fn partition(n: usize, space: &AABB, candidates: &Candidates) -> (f32, usize, usize, usize) {
        let mut best_cost = f32::INFINITY;
        let mut best_candidate_index = 0;
        // Variables to keep count the number of items in both subspace for each dimension
        let mut n_l = [0; 3];
        let mut n_r = [n; 3];
        // Keep n_l and n_r for the best splitting candidate
        let mut best_n_l = 0;
        let mut best_n_r = n;
        // Find best candidate
        for (i, candidate) in candidates.iter().enumerate() {
            let dim = candidate.dimension();
            // If the right candidate removes it from the right subspace
            if candidate.is_right() {
                n_r[dim] -= 1;
            }
            // Compute the cost of the split and update the best split
            let cost = Self::cost(&candidate.plane, space, n_l[dim], n_r[dim]);
            if cost < best_cost {
                best_cost = cost;
                best_candidate_index = i;
                best_n_l = n_l[dim];
                best_n_r = n_r[dim];
            }
            // If the left candidate add it from the left subspace
            if candidate.is_left() {
                n_l[dim] += 1;
            }
        }
        (best_cost, best_candidate_index, best_n_l, best_n_r)
    }
fn partition ( n : usize , space : & AABB , candidates : & Candidates ) -> ( f32 , usize , usize , usize ) { let mut best_cost = f32 :: INFINITY ; let mut best_candidate_index = 0 ; // Variables to keep count the number of items in both subspace for each dimension let mut n_l = [ 0 ; 3 ] ; let mut n_r = [ n ; 3 ] ; // Keep n_l and n_r for the best splitting candidate let mut best_n_l = 0 ; let mut best_n_r = n ; // Find best candidate for ( i , candidate ) in candidates . iter ( ) . enumerate ( ) { let dim = candidate . dimension ( ) ; // If the right candidate removes it from the right subspace if candidate . is_right ( ) { n_r [ dim ] -= 1 ; } // Compute the cost of the split and update the best split let cost = Self :: cost ( & candidate . plane , space , n_l [ dim ] , n_r [ dim ] ) ; if cost < best_cost { best_cost = cost ; best_candidate_index = i ; best_n_l = n_l [ dim ] ; best_n_r = n_r [ dim ] ; } // If the left candidate add it from the left subspace if candidate . is_left ( ) { n_l [ dim ] += 1 ; } } ( best_cost , best_candidate_index , best_n_l , best_n_r ) }
Compute the best splitting candidate
Return:
 Cost of the split
 Index of the best candidate
 Number of items in the left partition
 Number of items in the right partition
Compute the best splitting candidate Return : Cost of the split Index of the best candidate Number of items in the left partition Number of items in the right partition
n
usize
space
&AABB
candidates
&Candidates