A community-maintained Python framework for creating mathematical animations.
Fixed :func:`.svg_path.string_to_numbers` sometimes returning strings (#2192)
Josiah Winslowf91428e58022
diff --git a/manim/mobject/svg/svg_path.py b/manim/mobject/svg/svg_path.pyindex 0de275484..0e150df1e 100644--- a/manim/mobject/svg/svg_path.py+++ b/manim/mobject/svg/svg_path.py@@ -213,8 +213,8 @@ def string_to_numbers(num_string: str) -> List[float]:except ValueError:# in this case, it's something like "2.4.3.14 which should be parsed as "2.4 0.3 0.14"undotted_parts = s.split(".")- float_results.append(undotted_parts[0] + "." + undotted_parts[1])- float_results += ["." + u for u in undotted_parts[2:]]+ float_results.append(float(undotted_parts[0] + "." + undotted_parts[1]))+ float_results += [float("." + u) for u in undotted_parts[2:]]return float_resultsdiff --git a/tests/test_svg_mobject.py b/tests/test_svg_mobject.pyindex 6522b3615..c1dd01564 100644--- a/tests/test_svg_mobject.py+++ b/tests/test_svg_mobject.py@@ -1,6 +1,7 @@from colour import Colorfrom manim import *+from manim.mobject.svg.svg_path import string_to_numbersfrom tests.helpers.path_utils import get_svg_resource@@ -54,3 +55,23 @@ def test_stroke_overrides_color():stroke_color=expected_color,)assert svg.stroke_color == expected_color+++def test_string_to_numbers():+ cases = {+ "3, 14, 159": [3.0, 14.0, 159.0],+ "2.7 1828-1828": [2.7, 1828.0, -1828.0],+ "1-.618.033": [1.0, -0.618, 0.033],+ # this one is a real-world example!+ "1.5938,1.5938,0,0,1-.1559.6874": [+ 1.5938,+ 1.5938,+ 0.0,+ 0.0,+ 1.0,+ -0.1559,+ 0.6874,+ ],+ }+ for case, result in cases.items():+ assert string_to_numbers(case) == result