Skip to content

Commit

Permalink
Add assertion to avoid passing negative value to sqrt().
Browse files Browse the repository at this point in the history
  • Loading branch information
syoyo committed Mar 9, 2017
1 parent 2d76f2f commit 525a3ee
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/cameras/realistic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,9 +452,10 @@ Float RealisticCamera::FocusThickLens(Float focusDistance) {
// Compute translation of lens, _delta_, to focus at _focusDistance_
Float f = fz[0] - pz[0];
Float z = -focusDistance;
Float c = (pz[1] - z - pz[0]) * (pz[1] - z * 4 * f - pz[0]);
CHECK_GT(c, 0) << "Coefficient must be positive. It looks focusDistance: " << focusDistance << " is too short for a given lenses configuration";
Float delta =
0.5f * (pz[1] - z + pz[0] -
std::sqrt((pz[1] - z - pz[0]) * (pz[1] - z - 4 * f - pz[0])));
0.5f * (pz[1] - z + pz[0] - std::sqrt(c));
return elementInterfaces.back().thickness + delta;
}

Expand Down

0 comments on commit 525a3ee

Please sign in to comment.