Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Use OpenGLRoundedRectangle when necessary

Devin Neal69e7758203b7
diff --cc manim/mobject/svg/svg_mobject.py
index 5f7783796,8bab13cbb..05be1a576
--- a/manim/mobject/svg/svg_mobject.py
+++ b/manim/mobject/svg/svg_mobject.py
@@@ -17,9 -17,7 +17,9 @@@ from manim import logge
from ... import config
from ...constants import *
- from ...mobject.geometry import Circle, Rectangle, RoundedRectangle
- from ...mobject.opengl_geometry import OpenGLRectangle
+ from ...mobject.geometry import Circle, Line, Rectangle, RoundedRectangle
++from ...mobject.opengl_geometry import OpenGLRoundedRectangle, OpenGLRectangle
+from ...mobject.types.opengl_vectorized_mobject import OpenGLVGroup
from ...mobject.types.vectorized_mobject import VGroup, VMobject
from .style_utils import cascade_element_style, parse_style
from .svg_path import SVGPathMobject, string_to_numbers
@@@ -305,17 -323,41 +331,56 @@@ class SVGMobject(VMobject)
Returns
-------
- VMobjectFromSVGPathstring
- A VMobject representing the polygon.
+ Rectangle
+ Creates either a Rectangle, or RoundRectangle, VMobject from a
+ rect element.
"""
- # This seems hacky... yes it is.
- path_string = polygon_element.getAttribute("points").lstrip()
- for digit in string.digits:
- path_string = path_string.replace(" " + digit, " L" + digit)
- path_string = "M" + path_string
- if polygon_element.tagName == "polygon":
- path_string = path_string + "Z"
- return self.path_string_to_mobject(path_string, style)
+
+ stroke_width = rect_element.getAttribute("stroke-width")
+ corner_radius = rect_element.getAttribute("rx")
+
+ if stroke_width in ["", "none", "0"]:
+ stroke_width = 0
+
+ if corner_radius in ["", "0", "none"]:
+ corner_radius = 0
+
+ corner_radius = float(corner_radius)
+
+ parsed_style = parse_style(style)
+ parsed_style["stroke_width"] = stroke_width
+
+ if corner_radius == 0:
- mob = Rectangle(
- width=self.attribute_to_float(rect_element.getAttribute("width")),
- height=self.attribute_to_float(rect_element.getAttribute("height")),
- **parsed_style,
- )
++ if config["renderer"] == "opengl":
++ mob = OpenGLRectangle(
++ width=self.attribute_to_float(rect_element.getAttribute("width")),
++ height=self.attribute_to_float(rect_element.getAttribute("height")),
++ **parsed_style,
++ )
++ else:
++ mob = Rectangle(
++ width=self.attribute_to_float(rect_element.getAttribute("width")),
++ height=self.attribute_to_float(rect_element.getAttribute("height")),
++ **parsed_style,
++ )
+ else:
- mob = RoundedRectangle(
- width=self.attribute_to_float(rect_element.getAttribute("width")),
- height=self.attribute_to_float(rect_element.getAttribute("height")),
- corner_radius=corner_radius,
- **parsed_style,
- )
++ if config["renderer"] == "opengl":
++ mob = OpenGLRoundedRectangle(
++ width=self.attribute_to_float(rect_element.getAttribute("width")),
++ height=self.attribute_to_float(rect_element.getAttribute("height")),
++ corner_radius=corner_radius,
++ **parsed_style,
++ )
++ else:
++ mob = RoundedRectangle(
++ width=self.attribute_to_float(rect_element.getAttribute("width")),
++ height=self.attribute_to_float(rect_element.getAttribute("height")),
++ corner_radius=corner_radius,
++ **parsed_style,
++ )
+
+ mob.shift(mob.get_center() - mob.get_corner(UP + LEFT))
+ return mob
def circle_to_mobject(self, circle_element: MinidomElement, style: dict):
"""Creates a Circle VMobject from a SVG <circle> command.