From a94f84011481a2436006c2466c445a407f96e30e Mon Sep 17 00:00:00 2001 From: Dmitry Vedenko Date: Tue, 26 Sep 2023 15:34:59 +0300 Subject: [PATCH] Apply epsilon offset to a SingleStep algorithm as well --- libraries/lib-snapping/SnapUtils.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/libraries/lib-snapping/SnapUtils.cpp b/libraries/lib-snapping/SnapUtils.cpp index 5c2c01d7632d..2d169d809a0b 100644 --- a/libraries/lib-snapping/SnapUtils.cpp +++ b/libraries/lib-snapping/SnapUtils.cpp @@ -315,13 +315,25 @@ class ProjectDependentMultiplierSnapItem final : public SnapRegistryItem return { time, false }; const auto multiplier = mMultiplierFunctor(project); - const auto step = (upwards ? 1.0 : -1.0) / multiplier; - const double result = time + step; + + const auto eps = + std::max(1.0, time) * std::numeric_limits::epsilon(); + + const auto current = static_cast(std::floor(time * (1.0 + eps) * multiplier)); + const auto next = upwards ? current + 1 : current - 1; + + double result = next / multiplier; if (result < 0.0) return { 0.0, false }; - return SnapWithMultiplier(result, multiplier, true); + while (static_cast(std::floor(result * multiplier)) < next) + result += eps; + + while (static_cast(std::floor(result * multiplier)) > next) + result -= eps; + + return { result, true }; } private: