fn cost(p: &Plane, v: &AABB, n_l: usize, n_r: usize) -> f32 {
        // Split space
        let (v_l, v_r) = Self::split_space(v, p);

        // Compute the surface area of both subspace
        let (vol_l, vol_r) = (Self::surface_area(&v_l), Self::surface_area(&v_r));

        // Compute the surface area of the whole space
        let vol_v = vol_l + vol_r;

        // If one of the subspace is empty then the split can't be worth
        if vol_v == 0. || vol_l == 0. || vol_r == 0. {
            return f32::INFINITY;
        }

        // Decrease cost if it cuts empty space
        let factor = if n_l == 0 || n_r == 0 { 0.8 } else { 1. };

        factor * (K_T + K_I * (n_l as f32 * vol_l / vol_v + n_r as f32 * vol_r / vol_v))
    }
/// Surface Area Heuristic (SAH)
Surface Area Heuristic (SAH)
Surface Area Heuristic ( SAH )
fn cost(p: &Plane, v: &AABB, n_l: usize, n_r: usize) -> f32 {
        // Split space
        let (v_l, v_r) = Self::split_space(v, p);
        // Compute the surface area of both subspace
        let (vol_l, vol_r) = (Self::surface_area(&v_l), Self::surface_area(&v_r));
        // Compute the surface area of the whole space
        let vol_v = vol_l + vol_r;
        // If one of the subspace is empty then the split can't be worth
        if vol_v == 0. || vol_l == 0. || vol_r == 0. {
            return f32::INFINITY;
        }
        // Decrease cost if it cuts empty space
        let factor = if n_l == 0 || n_r == 0 { 0.8 } else { 1. };
        factor * (K_T + K_I * (n_l as f32 * vol_l / vol_v + n_r as f32 * vol_r / vol_v))
    }
fn cost ( p : & Plane , v : & AABB , n_l : usize , n_r : usize ) -> f32 { // Split space let ( v_l , v_r ) = Self :: split_space ( v , p ) ; // Compute the surface area of both subspace let ( vol_l , vol_r ) = ( Self :: surface_area ( & v_l ) , Self :: surface_area ( & v_r ) ) ; // Compute the surface area of the whole space let vol_v = vol_l + vol_r ; // If one of the subspace is empty then the split can't be worth if vol_v == 0. || vol_l == 0. || vol_r == 0. { return f32 :: INFINITY ; } // Decrease cost if it cuts empty space let factor = if n_l == 0 || n_r == 0 { 0.8 } else { 1. } ; factor * ( K_T + K_I * ( n_l as f32 * vol_l / vol_v + n_r as f32 * vol_r / vol_v ) ) }
Surface Area Heuristic (SAH)
Surface Area Heuristic ( SAH )
p
&Plane
v
&AABB
n_l
usize
n_r
usize