fn hit(&self, r: &Ray, t_min: f64, t_max: f64) -> Option<HitRecord> {
        let oc = r.origin() - self.center;
        let a = r.direction().length_squared();
        let half_b = Vec3::dot(&oc, &r.direction());
        let c = oc.length_squared() - self.radius * self.radius;

        let discriminant = half_b * half_b - a * c;
        if discriminant < 0.0 {
            return None;
        }

        let sqrtd = discriminant.sqrt();

        // Find the nearest root that lies in the acceptable range
        let mut root = (-half_b - sqrtd) / a;
        if root < t_min || t_max < root {
            root = (-half_b + sqrtd) / a;
            if root < t_min || t_max < root {
                return None;
            }
        }

        let t = root;
        let intersection = r.at(t);
        let normal = (intersection - self.center) / self.radius;

        Some(HitRecord::new(r, normal, t, Arc::clone(&self.material)))
    }
/// Tries to hit a sphere object.
Tries to hit a sphere object.
Tries to hit a sphere object .
fn hit(&self, r: &Ray, t_min: f64, t_max: f64) -> Option<HitRecord> {
        let oc = r.origin() - self.center;
        let a = r.direction().length_squared();
        let half_b = Vec3::dot(&oc, &r.direction());
        let c = oc.length_squared() - self.radius * self.radius;
        let discriminant = half_b * half_b - a * c;
        if discriminant < 0.0 {
            return None;
        }
        let sqrtd = discriminant.sqrt();
        // Find the nearest root that lies in the acceptable range
        let mut root = (-half_b - sqrtd) / a;
        if root < t_min || t_max < root {
            root = (-half_b + sqrtd) / a;
            if root < t_min || t_max < root {
                return None;
            }
        }
        let t = root;
        let intersection = r.at(t);
        let normal = (intersection - self.center) / self.radius;
        Some(HitRecord::new(r, normal, t, Arc::clone(&self.material)))
    }
fn hit ( & self , r : & Ray , t_min : f64 , t_max : f64 ) -> Option < HitRecord > { let oc = r . origin ( ) - self . center ; let a = r . direction ( ) . length_squared ( ) ; let half_b = Vec3 :: dot ( & oc , & r . direction ( ) ) ; let c = oc . length_squared ( ) - self . radius * self . radius ; let discriminant = half_b * half_b - a * c ; if discriminant < 0.0 { return None ; } let sqrtd = discriminant . sqrt ( ) ; // Find the nearest root that lies in the acceptable range let mut root = ( - half_b - sqrtd ) / a ; if root < t_min || t_max < root { root = ( - half_b + sqrtd ) / a ; if root < t_min || t_max < root { return None ; } } let t = root ; let intersection = r . at ( t ) ; let normal = ( intersection - self . center ) / self . radius ; Some ( HitRecord :: new ( r , normal , t , Arc :: clone ( & self . material ) ) ) }
Tries to hit a sphere object.
Tries to hit a sphere object .
&self
r
&Ray
t_min
f64
t_max
f64