Skip to content

Commit

Permalink
change lerp
Browse files Browse the repository at this point in the history
the previous lerp implementation could cause in certain scenarios that if t = 1, the output would be different than the input.
Because of floating point precision, `a - (b - a)` wasn't guaranteed to return `b`.
Down the line, when using trim paths for example, this small difference could cause the path not to draw properly.
Changing it to this implementation solves the issue.

Diffs=
1be3488d52 change lerp (#9000)

Co-authored-by: hernan <[email protected]>
  • Loading branch information
bodymovin and bodymovin committed Feb 8, 2025
1 parent 20768e2 commit 2db93d8
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .rive_head
Original file line number Diff line number Diff line change
@@ -1 +1 @@
19b64a2c1bbe9d0e1e7166b3290e34e3e291b018
1be3488d52ec4c2f32a03eb111afca5b1f01ecd8
2 changes: 1 addition & 1 deletion include/rive/math/math_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ RIVE_ALWAYS_INLINE static float degreesToRadians(float degrees)

template <typename T> T lerp(const T& a, const T& b, float t)
{
return a + (b - a) * t;
return a * (1 - t) + b * t;
}
} // namespace rive

Expand Down
4 changes: 2 additions & 2 deletions tests/unit_tests/runtime/bezier_utils_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -530,9 +530,9 @@ TEST_CASE("find_cubic_convex_180_chops", "[bezier_utils]")
TEST_CASE("find_cubic_convex_180_chops_lines", "[bezier_utils]")
{
Vec2D p0 = {123, 200}, p3 = {223, 432};
for (float t0 = 0; t0 < 1; t0 += .12f)
for (float t0 = 1e-3f; t0 < 1; t0 += .12f)
{
for (float t1 = t0 + .097f; t0 < 1; t0 += .097f)
for (float t1 = t0 + .097f; t1 < 1; t1 += .097f)
{
Vec2D line[4] = {p0, lerp(p0, p3, t0), lerp(p0, p3, t1), p3};
float _[2];
Expand Down

0 comments on commit 2db93d8

Please sign in to comment.