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:
@@ -1,9 +1,9 @@
|
||||
|
||||
use crate::ray::Ray;
|
||||
use crate::hittable::HitRecord;
|
||||
use crate::Vec3;
|
||||
use crate::vec3;
|
||||
use crate::vec3::Vec3;
|
||||
|
||||
use rand::Rng;
|
||||
use rand::rngs::SmallRng;
|
||||
use rand::distributions::Uniform;
|
||||
|
||||
@@ -49,7 +49,7 @@ impl Material {
|
||||
},
|
||||
Material::Metal { albedo, fuzz } => {
|
||||
let reflected = Vec3::reflect(
|
||||
Vec3::as_unit(&ray_in.dir),
|
||||
Vec3::as_unit(ray_in.dir),
|
||||
rec.normal
|
||||
);
|
||||
*scattered = Ray{
|
||||
@@ -63,7 +63,7 @@ impl Material {
|
||||
*attenuation = Vec3::ones();
|
||||
let refraction_ratio = if rec.front_face { 1.0 / index_refraction } else { *index_refraction };
|
||||
|
||||
let unit_direction = Vec3::as_unit(&ray_in.dir);
|
||||
let unit_direction = Vec3::as_unit(ray_in.dir);
|
||||
let refracted = Vec3::refract(unit_direction, rec.normal, refraction_ratio);
|
||||
|
||||
*scattered = Ray {
|
||||
|
||||
Reference in New Issue
Block a user