Skip to content

Commit

Permalink
BUG: Fix edge cases in Slerp
Browse files Browse the repository at this point in the history
Regression initially introduced in 6b7ad8e. Slerp interpolation fails in
some cases when t == 0 or t == 1
  • Loading branch information
NicerNewerCar authored and jcfr committed Mar 26, 2024
1 parent e78b70e commit 468324a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions libautoscoper/src/Tracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,12 @@ bool Tracker::calculate_viewport(const CoordFrame& modelview, const Camera& came
return false;
}

// Check if min_max is unchanged from the initial values
if (min_max[0] == 1.0 && min_max[1] == 1.0 && min_max[2] == -1.0 && min_max[3] == -1.0) {
// This usually means that the rotation was all NaN
return false;
}

// clip min_max to rad_min_max_film
if (min_max[0] < rad_min_max_film[0]) {
min_max[0] = rad_min_max_film[0];
Expand Down
4 changes: 4 additions & 0 deletions math/Quaternion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,10 @@ struct Quat

friend Quat slerp(const Quat& p, const Quat& q, const T& t)
{
if (t < std::numeric_limits<T>::epsilon())
return p;
if (t > T(1) - std::numeric_limits<T>::epsilon())
return q;
T cosRad = dot(unit(p), unit(q));
T rad = acos(cosRad);
if (rad < std::numeric_limits<T>::epsilon()) {
Expand Down

0 comments on commit 468324a

Please sign in to comment.