cleanup
This commit is contained in:
10
src/main.rs
10
src/main.rs
@@ -11,15 +11,15 @@ use crate::{
|
|||||||
|
|
||||||
fn hit_sphere(center: &Point3, radius: f64, r: &Ray) -> f64 {
|
fn hit_sphere(center: &Point3, radius: f64, r: &Ray) -> f64 {
|
||||||
let oc = r.origin() - *center;
|
let oc = r.origin() - *center;
|
||||||
let a = r.direction().dot(&r.direction());
|
let a = r.direction().length_squared();
|
||||||
let b = 2.0 * oc.dot(&r.direction());
|
let half_b = oc.dot(&r.direction());
|
||||||
let c = oc.dot(&oc) - radius*radius;
|
let c = oc.length_squared() - radius*radius;
|
||||||
let discriminant = b*b - 4.0*a*c;
|
let discriminant = half_b*half_b - a*c;
|
||||||
|
|
||||||
if discriminant < 0.0 {
|
if discriminant < 0.0 {
|
||||||
-1.0
|
-1.0
|
||||||
} else {
|
} else {
|
||||||
(-b - discriminant.sqrt()) / (2.0 * a)
|
(-half_b - discriminant.sqrt()) / a
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user