chore: Unit convertor by value, clean stale code
The Vec3::as_unit() function accepts input by reference. It passes back out a copy, however, and some inputs are even temporaries. I bet the optimizer can see through this game and will do the right thing if I give it a value instead. It should perform copy elision as appropriate, even if I'm missing out on Rust's move semantics here. Remove some old, unused, and unuseable functions.
This commit is contained in:
16
src/main.rs
16
src/main.rs
@@ -125,7 +125,7 @@ fn ray_color(r: Ray, world: &dyn Hittable, depth: u32, srng: &mut SmallRng, dist
|
||||
}
|
||||
}
|
||||
|
||||
let unitdir = Vec3::as_unit(&r.dir);
|
||||
let unitdir = Vec3::as_unit(r.dir);
|
||||
let t = 0.5 * (unitdir.y + 1.0);
|
||||
return Vec3::ones() * (1.0 - t) + Vec3::new(0.5, 0.7, 1.0) * t
|
||||
}
|
||||
@@ -134,17 +134,3 @@ fn degrees_to_radians(degrees: f32) -> f32 {
|
||||
degrees * std::f32::consts::PI / 180.0
|
||||
}
|
||||
|
||||
fn hit_sphere(center: Vec3, radius: f32, ray: &Ray) -> f32{
|
||||
let oc = ray.orig - center;
|
||||
let a = ray.dir.length_squared();
|
||||
let half_b = Vec3::dot(oc, ray.dir);
|
||||
let c = oc.length_squared() - radius*radius;
|
||||
let discriminant = half_b*half_b - a*c;
|
||||
|
||||
if discriminant < 0.0 {
|
||||
return -1.0;
|
||||
} else {
|
||||
return (-half_b - discriminant.sqrt()) / a;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user