Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

fix(svg): ignore point-less shape elements (#4917)

Benjamin Hackld94f7f64ba7b
diff --git a/manim/mobject/svg/svg_mobject.py b/manim/mobject/svg/svg_mobject.py
index c296130a2..5f67b8adc 100644
--- a/manim/mobject/svg/svg_mobject.py
+++ b/manim/mobject/svg/svg_mobject.py
@@ -338,7 +338,7 @@ class SVGMobject(VMobject, metaclass=ConvertToOpenGL):
logger.warning(f"Unsupported element type: {type(shape)}")
mob = None
if mob is None or not mob.has_points():
- return mob
+ return None
self.apply_style_to_mobject(mob, shape)
if isinstance(shape, se.Transformable) and shape.apply:
self.handle_transform(mob, shape.transform)
diff --git a/tests/module/mobject/svg/test_svg_mobject.py b/tests/module/mobject/svg/test_svg_mobject.py
index 764c4ee64..742525cbd 100644
--- a/tests/module/mobject/svg/test_svg_mobject.py
+++ b/tests/module/mobject/svg/test_svg_mobject.py
@@ -1,5 +1,7 @@
from __future__ import annotations
+from pathlib import Path
+
from manim import *
from tests.helpers.path_utils import get_svg_resource
@@ -56,6 +58,21 @@ def test_stroke_overrides_color():
assert svg.stroke_color.to_hex() == expected_color
+def test_empty_path_is_ignored(tmp_path: Path):
+ svg_path = tmp_path / "empty_path.svg"
+ svg_path.write_text(
+ '<svg xmlns="http://www.w3.org/2000/svg">'
+ '<path d=""/><path d="M 0 0 L 1 1"/>'
+ "</svg>",
+ encoding="utf-8",
+ )
+
+ svg = SVGMobject(svg_path)
+
+ assert len(svg.submobjects) == 1
+ assert svg.submobjects[0].has_points()
+
+
def test_single_path_turns_into_sequence_of_points():
svg = SVGMobject(
get_svg_resource("cubic_and_lineto.svg"),