A community-maintained Python framework for creating mathematical animations.
Fixed bug in :meth:`.VMobject.proportion_from_point` that caused proportions greater than 1 to be returned (#2770)
mooncaker816b583720ac268
diff --git a/manim/utils/bezier.py b/manim/utils/bezier.pyindex 6f8187eef..4a489318b 100644--- a/manim/utils/bezier.py+++ b/manim/utils/bezier.py@@ -478,7 +478,7 @@ def proportions_along_bezier_curve_for_point(roots = [[root for root in rootlist if root.imag == 0] for rootlist in roots]roots = reduce(np.intersect1d, roots) # Get common roots.- roots = np.array([r.real for r in roots])+ roots = np.array([r.real for r in roots if 0 <= r.real <= 1])return rootsdiff --git a/tests/test_vectorized_mobject.py b/tests/test_vectorized_mobject.pyindex 181efc044..5e87c820c 100644--- a/tests/test_vectorized_mobject.py+++ b/tests/test_vectorized_mobject.py@@ -3,7 +3,17 @@ from math import cos, sinimport numpy as npimport pytest-from manim import Circle, Line, Mobject, RegularPolygon, Square, VDict, VGroup, VMobject+from manim import (+ Circle,+ Line,+ Mobject,+ Polygon,+ RegularPolygon,+ Square,+ VDict,+ VGroup,+ VMobject,+)from manim.constants import PI@@ -295,3 +305,14 @@ def test_vmobject_point_at_angle():a = Circle()p = a.point_at_angle(4 * PI)np.testing.assert_array_equal(a.points[0], p)+++def test_proportion_from_point():+ A = np.sqrt(3) * np.array([0, 1, 0])+ B = np.array([-1, 0, 0])+ C = np.array([1, 0, 0])+ abc = Polygon(A, B, C)+ abc.shift(np.array([-1, 0, 0]))+ abc.scale(0.8)+ props = [abc.proportion_from_point(p) for p in abc.get_vertices()]+ np.testing.assert_allclose(props, [0, 1 / 3, 2 / 3])