pub fn generalized_intersections<'a>(
        object: &'a dyn Shape,
        bounds: &Bounds,
        transformed_ray: &Ray,
    ) -> Vec<Intersection<'a>> {
        let (xtmin, xtmax) = Self::check_axis(
            transformed_ray.origin.x,
            transformed_ray.direction.x,
            bounds.min.x,
            bounds.max.x,
        );
        let (ytmin, ytmax) = Self::check_axis(
            transformed_ray.origin.y,
            transformed_ray.direction.y,
            bounds.min.y,
            bounds.max.y,
        );

        let mut tmin = xtmin.max(ytmin);
        let mut tmax = xtmax.min(ytmax);

        // Optimized version, as suggested in the practice section.
        //
        if tmin > tmax {
            return vec![];
        }

        let (ztmin, ztmax) = Self::check_axis(
            transformed_ray.origin.z,
            transformed_ray.direction.z,
            bounds.min.z,
            bounds.max.z,
        );

        tmin = tmin.max(ztmin);
        tmax = tmax.min(ztmax);

        if tmin > tmax {
            vec![]
        } else {
            vec![
                Intersection {
                    t: tmin,
                    uv: None,
                    object,
                },
                Intersection {
                    t: tmax,
                    uv: None,
                    object,
                },
            ]
        }
    }
// Passing the object as parameter rather than modeling this as associated method, it allows to
// use this logic on any Shape.
//
Passing the object as parameter rather than modeling this as associated method, it allows to
use this logic on any Shape.
Passing the object as parameter rather than modeling this as associated method it allows to use this logic on any Shape .
pub fn generalized_intersections<'a>(
        object: &'a dyn Shape,
        bounds: &Bounds,
        transformed_ray: &Ray,
    ) -> Vec<Intersection<'a>> {
        let (xtmin, xtmax) = Self::check_axis(
            transformed_ray.origin.x,
            transformed_ray.direction.x,
            bounds.min.x,
            bounds.max.x,
        );
        let (ytmin, ytmax) = Self::check_axis(
            transformed_ray.origin.y,
            transformed_ray.direction.y,
            bounds.min.y,
            bounds.max.y,
        );
        let mut tmin = xtmin.max(ytmin);
        let mut tmax = xtmax.min(ytmax);
        // Optimized version, as suggested in the practice section.
        //
        if tmin > tmax {
            return vec![];
        }
        let (ztmin, ztmax) = Self::check_axis(
            transformed_ray.origin.z,
            transformed_ray.direction.z,
            bounds.min.z,
            bounds.max.z,
        );
        tmin = tmin.max(ztmin);
        tmax = tmax.min(ztmax);
        if tmin > tmax {
            vec![]
        } else {
            vec![
                Intersection {
                    t: tmin,
                    uv: None,
                    object,
                },
                Intersection {
                    t: tmax,
                    uv: None,
                    object,
                },
            ]
        }
    }
pub fn generalized_intersections < ' a > ( object : & ' a dyn Shape , bounds : & Bounds , transformed_ray : & Ray , ) -> Vec < Intersection < ' a > > { let ( xtmin , xtmax ) = Self :: check_axis ( transformed_ray . origin . x , transformed_ray . direction . x , bounds . min . x , bounds . max . x , ) ; let ( ytmin , ytmax ) = Self :: check_axis ( transformed_ray . origin . y , transformed_ray . direction . y , bounds . min . y , bounds . max . y , ) ; let mut tmin = xtmin . max ( ytmin ) ; let mut tmax = xtmax . min ( ytmax ) ; // Optimized version, as suggested in the practice section. // if tmin > tmax { return vec ! [ ] ; } let ( ztmin , ztmax ) = Self :: check_axis ( transformed_ray . origin . z , transformed_ray . direction . z , bounds . min . z , bounds . max . z , ) ; tmin = tmin . max ( ztmin ) ; tmax = tmax . min ( ztmax ) ; if tmin > tmax { vec ! [ ] } else { vec ! [ Intersection { t tmin uv None object } Intersection { t tmax uv None object } ] } }
Passing the object as parameter rather than modeling this as associated method, it allows to
use this logic on any Shape.
Passing the object as parameter rather than modeling this as associated method it allows to use this logic on any Shape .
object
&'a dyn Shape
bounds
&Bounds
transformed_ray
&Ray