Skip to content

Commit

Permalink
Fix of ImageMobject opacity bug (#4089)
Browse files Browse the repository at this point in the history
* Fix issue 4072.

* Added a unittest for the interpolate function in utils/bezier.py
  • Loading branch information
henrikmidtiby authored Jan 19, 2025
1 parent def7241 commit 95b4625
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion manim/utils/bezier.py
Original file line number Diff line number Diff line change
Expand Up @@ -1059,7 +1059,7 @@ def interpolate(
* ``alpha`` is a :class:`float`, the return is another :class:`~.Point3D`.
* ``alpha`` is a :class:`~.ColVector`, the return is a :class:`~.Point3D_Array`.
"""
return start + alpha * (end - start)
return (1 - alpha) * start + alpha * end


def integer_interpolate(
Expand Down
16 changes: 16 additions & 0 deletions tests/module/utils/test_bezier.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
_get_subdivision_matrix,
get_quadratic_approximation_of_cubic,
get_smooth_cubic_bezier_handle_points,
interpolate,
partial_bezier_points,
split_bezier,
subdivide_bezier,
Expand Down Expand Up @@ -215,3 +216,18 @@ def test_get_quadratic_approximation_of_cubic() -> None:
]
),
)


def test_interpolate() -> None:
"""Test that :func:`interpolate` handles interpolation of both float and uint8 values."""
start = 127.0
end = 25.0
alpha = 0.2
val = interpolate(start, end, alpha)
assert np.allclose(val, 106.6000000)

start = np.array(127, dtype=np.uint8)
end = np.array(25, dtype=np.uint8)
alpha = 0.09739
val = interpolate(start, end, alpha)
assert np.allclose(val, np.array([117.06622]))

0 comments on commit 95b4625

Please sign in to comment.