From 510586f274a481c684216453f1e1639bf2f5f7b5 Mon Sep 17 00:00:00 2001 From: Anthony Lombardi Date: Tue, 19 Mar 2024 10:09:25 -0400 Subject: [PATCH] BUG: Fix edge cases in Slerp Regression initially introduced in 6b7ad8e. Slerp interpolation fails in some cases when t == 0 or t == 1 --- libautoscoper/src/Tracker.cpp | 6 ++++++ math/Quaternion.hpp | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/libautoscoper/src/Tracker.cpp b/libautoscoper/src/Tracker.cpp index 831b6f8a..aea2d893 100644 --- a/libautoscoper/src/Tracker.cpp +++ b/libautoscoper/src/Tracker.cpp @@ -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]; diff --git a/math/Quaternion.hpp b/math/Quaternion.hpp index aaee9411..d5167670 100644 --- a/math/Quaternion.hpp +++ b/math/Quaternion.hpp @@ -379,6 +379,10 @@ struct Quat friend Quat slerp(const Quat& p, const Quat& q, const T& t) { + if (t < std::numeric_limits::epsilon()) + return p; + if (t > T(1) - std::numeric_limits::epsilon()) + return q; T cosRad = dot(unit(p), unit(q)); T rad = acos(cosRad); if (rad < std::numeric_limits::epsilon()) {