Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Fix of ImageMobject opacity bug (#4089)

Henrik Skov Midtiby95b4625ef282
diff --git a/manim/utils/bezier.py b/manim/utils/bezier.py
index 129c26b3c..28958309a 100644
--- a/manim/utils/bezier.py
+++ b/manim/utils/bezier.py
@@ -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(
diff --git a/tests/module/utils/test_bezier.py b/tests/module/utils/test_bezier.py
index e7e02a89e..19d3076ff 100644
--- a/tests/module/utils/test_bezier.py
+++ b/tests/module/utils/test_bezier.py
@@ -10,6 +10,7 @@ from manim.utils.bezier import (
_get_subdivision_matrix,
get_quadratic_approximation_of_cubic,
get_smooth_cubic_bezier_handle_points,
+ interpolate,
partial_bezier_points,
split_bezier,
subdivide_bezier,
@@ -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]))