Skip to content
Snippets Groups Projects
Commit 7b78ff1f authored by Yoel's avatar Yoel
Browse files

Streamlined optional returns

parent c35d9a56
No related branches found
No related tags found
No related merge requests found
...@@ -25,7 +25,7 @@ std::optional<cam::Hit> Sphere::intersect(const cam::Ray& r) const { ...@@ -25,7 +25,7 @@ std::optional<cam::Hit> Sphere::intersect(const cam::Ray& r) const {
float theta = acos(t1HitPoint.y() / radius); float theta = acos(t1HitPoint.y() / radius);
float phi = M_PI + atan2(t1HitPoint.x(), t1HitPoint.z()); float phi = M_PI + atan2(t1HitPoint.x(), t1HitPoint.z());
return std::optional<cam::Hit>( return std::optional<cam::Hit>(
cam::Hit(t1HitPoint, t1HitPoint, t1, material)); {t1HitPoint, t1HitPoint, t1, material});
} else { } else {
float t2 = (-b + sqrt(b * b - 4 * a * c)) / (2 * a); float t2 = (-b + sqrt(b * b - 4 * a * c)) / (2 * a);
if (r.in_range(t2)) { if (r.in_range(t2)) {
...@@ -33,7 +33,7 @@ std::optional<cam::Hit> Sphere::intersect(const cam::Ray& r) const { ...@@ -33,7 +33,7 @@ std::optional<cam::Hit> Sphere::intersect(const cam::Ray& r) const {
float theta = acos(t2HitPoint.y() / radius); float theta = acos(t2HitPoint.y() / radius);
float phi = M_PI + atan2(t2HitPoint.x(), t2HitPoint.z()); float phi = M_PI + atan2(t2HitPoint.x(), t2HitPoint.z());
return std::optional<cam::Hit>( return std::optional<cam::Hit>(
cam::Hit(t2HitPoint, t2HitPoint, t2, material)); {t2HitPoint, t2HitPoint, t2, material});
} else { } else {
return std::nullopt; return std::nullopt;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment