Refactor near_zero method

This commit is contained in:
2026-02-17 02:10:44 +05:30
committed by GitHub
parent 726701d65a
commit 3c066309c3
+3 -4
View File
@@ -47,7 +47,7 @@ class vec3 {
bool near_zero() const {
// Return true if the vector is close to zero in all dimensions.
auto s = 1e-8;
return (std::fabs(e[0]) < s) && (std::fabs(e[1]) < s) && (std::fabs(e[2]) < s);
}
@@ -61,11 +61,10 @@ class vec3 {
}
};
// point3 is just an alias for vec3, but useful for geometric clarity in the code.
using point3 = vec3;
// Vector Utility Functions
inline std::ostream& operator<<(std::ostream& out, const vec3& v) {
return out << v.e[0] << ' ' << v.e[1] << ' ' << v.e[2];
@@ -131,7 +130,7 @@ inline vec3 random_unit_vector() {
inline vec3 random_on_hemisphere(const vec3& normal) {
vec3 on_unit_sphere = random_unit_vector();
if (dot(on_unit_sphere, normal) > 0.0) // In the same hemisphere as the normal
if (dot(on_unit_sphere, normal) > 0.0)
return on_unit_sphere;
else
return -on_unit_sphere;