Skip to content

Commit

Permalink
Apply epsilon offset to a SingleStep algorithm as well
Browse files Browse the repository at this point in the history
  • Loading branch information
crsib committed Sep 26, 2023
1 parent d6226f4 commit a94f840
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions libraries/lib-snapping/SnapUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<double>::epsilon();

const auto current = static_cast<int>(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<int>(std::floor(result * multiplier)) < next)
result += eps;

while (static_cast<int>(std::floor(result * multiplier)) > next)
result -= eps;

return { result, true };
}

private:
Expand Down

0 comments on commit a94f840

Please sign in to comment.