latest
This commit is contained in:
13
src/vec3.rs
13
src/vec3.rs
@@ -12,6 +12,10 @@ impl Vec3 {
|
||||
Vec3 { elements: [x, y, z] }
|
||||
}
|
||||
|
||||
pub fn new_empty() -> Self {
|
||||
Vec3::new(0.0, 0.0, 0.0)
|
||||
}
|
||||
|
||||
pub fn x(&self) -> f64 {
|
||||
self.elements[0]
|
||||
}
|
||||
@@ -59,6 +63,11 @@ impl Vec3 {
|
||||
pub fn random_range(min: f64, max: f64) -> Self {
|
||||
Vec3::new(random_range_f64(min, max), random_range_f64(min, max), random_range_f64(min, max))
|
||||
}
|
||||
|
||||
pub fn near_zero(&self) -> bool {
|
||||
let s = 1e-8;
|
||||
(self.x().abs() < s) && (self.y().abs() < s) && (self.z().abs() < s)
|
||||
}
|
||||
}
|
||||
|
||||
impl Add for Vec3 {
|
||||
@@ -212,4 +221,8 @@ pub fn random_in_hemisphere(normal: &Vec3) -> Vec3 {
|
||||
} else {
|
||||
return -in_unit_sphere;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn reflect(v: &Vec3, n: &Vec3) -> Vec3 {
|
||||
*v - 2.0 * v.dot(n) * *n
|
||||
}
|
||||
Reference in New Issue
Block a user