From 22030a409f6e4e2ff905cf4e197d66c7a1a456a0 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..0471fb30 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 means that something went terribly wrong + 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..e21fda6d 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 == T(0)) + return p; + if (t == T(1)) + return q; T cosRad = dot(unit(p), unit(q)); T rad = acos(cosRad); if (rad < std::numeric_limits::epsilon()) {