Skip to content

Commit 309c9d4

Browse files
Ported improved implementation of :class:.SVGMobject from 3b1b/manim (#2898)
* port SVGMobject from 3b1b/manim * added svgelements as dependency * revert change of default values * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * set default stroke_width of svg elements to 0 if not set * fix handling of circles with different rx/ry * turn more methods into staticmethods * removed duplicated method * set/adapt stroke-width of some test SVGs * updated control data * forgot some control data * fixed init_colors in tex_mobject and text_mobject * minor changes, added docstrings * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * module docstring, removed import * vector_to_coords changed again * nail sphinx version to below 5.1 to fix rtd (?) * update test_text control data for science * changed Brace to use VMobjectFromSVGPath * remove unused classes and methods depending on old SVG path implementation * remove style_utils and svg_path modules * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * change test_text to use monospace font * restore geometry.polygram * added get_mobject_type_class auxiliary method; changed polyline implementation to ad-hoc approach * restore test_text to previous version * skip Use tags as svgelements already populates them Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 3ad15bd commit 309c9d4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+834
-1529
lines changed

docs/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
furo
22
myst-parser
3-
sphinx
3+
sphinx<5.1
44
sphinx-copybutton
55
sphinxext-opengraph

manim/mobject/mobject.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2135,6 +2135,11 @@ def __len__(self):
21352135
def get_group_class(self):
21362136
return Group
21372137

2138+
@staticmethod
2139+
def get_mobject_type_class():
2140+
"""Return the base class of this mobject type."""
2141+
return Mobject
2142+
21382143
def split(self):
21392144
result = [self] if len(self.points) > 0 else []
21402145
return result + self.submobjects

manim/mobject/opengl/opengl_mobject.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2281,6 +2281,11 @@ def align_to(
22812281
def get_group_class(self):
22822282
return OpenGLGroup
22832283

2284+
@staticmethod
2285+
def get_mobject_type_class():
2286+
"""Return the base class of this mobject type."""
2287+
return OpenGLMobject
2288+
22842289
# Alignment
22852290

22862291
def align_data_and_family(self, mobject):

manim/mobject/opengl/opengl_point_cloud_mobject.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ def get_shader_data(self):
155155
self.read_data_to_shader(shader_data, "color", "rgbas")
156156
return shader_data
157157

158+
@staticmethod
159+
def get_mobject_type_class():
160+
return OpenGLPMobject
161+
158162

159163
class OpenGLPGroup(OpenGLPMobject):
160164
def __init__(self, *pmobs, **kwargs):

manim/mobject/opengl/opengl_vectorized_mobject.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ def __init__(
142142
def get_group_class(self):
143143
return OpenGLVGroup
144144

145+
@staticmethod
146+
def get_mobject_type_class():
147+
return OpenGLVMobject
148+
145149
def init_data(self):
146150
super().init_data()
147151
self.data.pop("rgbas")
@@ -389,10 +393,18 @@ def get_colors(self):
389393
fill_color = property(get_fill_color, set_fill)
390394

391395
def has_stroke(self):
392-
return any(self.get_stroke_widths()) and any(self.get_stroke_opacities())
396+
stroke_widths = self.get_stroke_widths()
397+
stroke_opacities = self.get_stroke_opacities()
398+
return (
399+
stroke_widths is not None
400+
and stroke_opacities is not None
401+
and any(stroke_widths)
402+
and any(stroke_opacities)
403+
)
393404

394405
def has_fill(self):
395-
return any(self.get_fill_opacities())
406+
fill_opacities = self.get_fill_opacities()
407+
return fill_opacities is not None and any(fill_opacities)
396408

397409
def get_opacity(self):
398410
if self.has_fill():

manim/mobject/svg/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,5 @@
77
:toctree: ../reference
88
99
~brace
10-
~style_utils
1110
~svg_mobject
12-
~svg_path
1311
"""

manim/mobject/svg/brace.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from typing import Sequence
88

99
import numpy as np
10+
import svgelements as se
1011

1112
from manim._config import config
1213
from manim.mobject.geometry.arc import Arc
@@ -18,12 +19,12 @@
1819
from ...animation.fading import FadeIn
1920
from ...animation.growing import GrowFromCenter
2021
from ...constants import *
21-
from ...mobject.svg.svg_path import SVGPathMobject
2222
from ...mobject.types.vectorized_mobject import VMobject
2323
from ...utils.color import BLACK
24+
from ..svg.svg_mobject import VMobjectFromSVGPath
2425

2526

26-
class Brace(SVGPathMobject):
27+
class Brace(VMobjectFromSVGPath):
2728
"""Takes a mobject and draws a brace adjacent to it.
2829
2930
Passing a direction vector determines the direction from which the
@@ -99,19 +100,22 @@ def __init__(
99100
(target_width * sharpness - default_min_width) / 2,
100101
)
101102

102-
path = path_string_template.format(
103-
linear_section_length,
104-
-linear_section_length,
103+
path = se.Path(
104+
path_string_template.format(
105+
linear_section_length,
106+
-linear_section_length,
107+
)
105108
)
106109

107110
super().__init__(
108-
path_string=path,
111+
path_obj=path,
109112
stroke_width=stroke_width,
110113
fill_opacity=fill_opacity,
111114
background_stroke_width=background_stroke_width,
112115
background_stroke_color=background_stroke_color,
113116
**kwargs,
114117
)
118+
self.flip(RIGHT)
115119
self.stretch_to_fit_width(target_width)
116120
self.shift(left - self.get_corner(UP + LEFT) + self.buff * DOWN)
117121

manim/mobject/svg/style_utils.py

Lines changed: 0 additions & 186 deletions
This file was deleted.

0 commit comments

Comments
 (0)