Skip to content

Commit 95b4625

Browse files
Fix of ImageMobject opacity bug (#4089)
* Fix issue 4072. * Added a unittest for the interpolate function in utils/bezier.py
1 parent def7241 commit 95b4625

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

manim/utils/bezier.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1059,7 +1059,7 @@ def interpolate(
10591059
* ``alpha`` is a :class:`float`, the return is another :class:`~.Point3D`.
10601060
* ``alpha`` is a :class:`~.ColVector`, the return is a :class:`~.Point3D_Array`.
10611061
"""
1062-
return start + alpha * (end - start)
1062+
return (1 - alpha) * start + alpha * end
10631063

10641064

10651065
def integer_interpolate(

tests/module/utils/test_bezier.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
_get_subdivision_matrix,
1111
get_quadratic_approximation_of_cubic,
1212
get_smooth_cubic_bezier_handle_points,
13+
interpolate,
1314
partial_bezier_points,
1415
split_bezier,
1516
subdivide_bezier,
@@ -215,3 +216,18 @@ def test_get_quadratic_approximation_of_cubic() -> None:
215216
]
216217
),
217218
)
219+
220+
221+
def test_interpolate() -> None:
222+
"""Test that :func:`interpolate` handles interpolation of both float and uint8 values."""
223+
start = 127.0
224+
end = 25.0
225+
alpha = 0.2
226+
val = interpolate(start, end, alpha)
227+
assert np.allclose(val, 106.6000000)
228+
229+
start = np.array(127, dtype=np.uint8)
230+
end = np.array(25, dtype=np.uint8)
231+
alpha = 0.09739
232+
val = interpolate(start, end, alpha)
233+
assert np.allclose(val, np.array([117.06622]))

0 commit comments

Comments
 (0)