<commit_before>use nalgebra::na::{AlgebraicVecExt, Rotate, Transform};
use bounding_volume::AABB;
use geom::Box;
use ray::{Ray, RayCast, RayCastWithTransform};

impl<N: Primitive + Orderable + Algebraic,
     V: AlgebraicVecExt<N> + Clone>
RayCast<N, V> for Box<N, V> {
    #[inline]
    fn toi_with_ray(&self, ray: &Ray<V>) -> Option<N> {
        AABB::new(-self.half_extents(), self.half_extents()).toi_with_ray(ray)
    }

    #[inline]
    fn toi_and_normal_with_ray(&self, ray: &Ray<V>) -> Option<(N, V)> {
        AABB::new(-self.half_extents(), self.half_extents()).toi_and_normal_with_ray(ray)
    }
}

impl<N: Primitive + Orderable + Algebraic,
     V: AlgebraicVecExt<N> + Clone,
     M: Rotate<V> + Transform<V>>
RayCastWithTransform<N, V, M> for Box<N, V> { }<commit_msg>Use the gjk-based ray cast when a box geometry is not 0.<commit_after>use nalgebra::na::{AlgebraicVecExt, Rotate, Transform, Identity, Cast};
use narrow::algorithm::johnson_simplex::JohnsonSimplex;
use bounding_volume::AABB;
use geom::{HasMargin, Box};
use ray::{Ray, RayCast, RayCastWithTransform};
use ray::ray_implicit::gjk_toi_and_normal_with_ray;

impl<N: Primitive + Orderable + Algebraic + Float + Cast<f32>,
     V: AlgebraicVecExt<N> + Clone>
RayCast<N, V> for Box<N, V> {
    #[inline]
    fn toi_with_ray(&self, ray: &Ray<V>) -> Option<N> {
        if self.margin().is_zero() {
            gjk_toi_and_normal_with_ray(
                &Identity::new(),
                self,
                &mut JohnsonSimplex::<N, V>::new_w_tls(),
                ray).map(|(n, _)| n)
        }
        else {
            AABB::new(-self.half_extents(), self.half_extents()).toi_with_ray(ray)
        }
    }

    #[inline]
    fn toi_and_normal_with_ray(&self, ray: &Ray<V>) -> Option<(N, V)> {
        if self.margin().is_zero() {
            AABB::new(-self.half_extents(), self.half_extents()).toi_and_normal_with_ray(ray)
        }
        else {
            gjk_toi_and_normal_with_ray(
                &Identity::new(),
                self,
                &mut JohnsonSimplex::<N, V>::new_w_tls(),
                ray)
        }
    }
}

impl<N: Primitive + Orderable + Algebraic + Float + Cast<f32>,
     V: AlgebraicVecExt<N> + Clone,
     M: Rotate<V> + Transform<V>>
RayCastWithTransform<N, V, M> for Box<N, V> { }
{'fraction_non_alphanumeric': 0.15915004336513444, 'fraction_numerical': 0.002168256721595837, 'mean_word_length': 3.0473684210526315, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '764143', 'n_tokens_mistral': 873, 'n_tokens_neox': 845, 'n_words': 157}