Skip to content

Commit

Permalink
Ported improved implementation of :class:.SVGMobject from 3b1b/manim (
Browse files Browse the repository at this point in the history
#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>
  • Loading branch information
behackl and pre-commit-ci[bot] authored Sep 28, 2022
1 parent 3ad15bd commit 309c9d4
Show file tree
Hide file tree
Showing 41 changed files with 834 additions and 1,529 deletions.
2 changes: 1 addition & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
furo
myst-parser
sphinx
sphinx<5.1
sphinx-copybutton
sphinxext-opengraph
5 changes: 5 additions & 0 deletions manim/mobject/mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -2135,6 +2135,11 @@ def __len__(self):
def get_group_class(self):
return Group

@staticmethod
def get_mobject_type_class():
"""Return the base class of this mobject type."""
return Mobject

def split(self):
result = [self] if len(self.points) > 0 else []
return result + self.submobjects
Expand Down
5 changes: 5 additions & 0 deletions manim/mobject/opengl/opengl_mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -2281,6 +2281,11 @@ def align_to(
def get_group_class(self):
return OpenGLGroup

@staticmethod
def get_mobject_type_class():
"""Return the base class of this mobject type."""
return OpenGLMobject

# Alignment

def align_data_and_family(self, mobject):
Expand Down
4 changes: 4 additions & 0 deletions manim/mobject/opengl/opengl_point_cloud_mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ def get_shader_data(self):
self.read_data_to_shader(shader_data, "color", "rgbas")
return shader_data

@staticmethod
def get_mobject_type_class():
return OpenGLPMobject


class OpenGLPGroup(OpenGLPMobject):
def __init__(self, *pmobs, **kwargs):
Expand Down
16 changes: 14 additions & 2 deletions manim/mobject/opengl/opengl_vectorized_mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ def __init__(
def get_group_class(self):
return OpenGLVGroup

@staticmethod
def get_mobject_type_class():
return OpenGLVMobject

def init_data(self):
super().init_data()
self.data.pop("rgbas")
Expand Down Expand Up @@ -389,10 +393,18 @@ def get_colors(self):
fill_color = property(get_fill_color, set_fill)

def has_stroke(self):
return any(self.get_stroke_widths()) and any(self.get_stroke_opacities())
stroke_widths = self.get_stroke_widths()
stroke_opacities = self.get_stroke_opacities()
return (
stroke_widths is not None
and stroke_opacities is not None
and any(stroke_widths)
and any(stroke_opacities)
)

def has_fill(self):
return any(self.get_fill_opacities())
fill_opacities = self.get_fill_opacities()
return fill_opacities is not None and any(fill_opacities)

def get_opacity(self):
if self.has_fill():
Expand Down
2 changes: 0 additions & 2 deletions manim/mobject/svg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,5 @@
:toctree: ../reference
~brace
~style_utils
~svg_mobject
~svg_path
"""
16 changes: 10 additions & 6 deletions manim/mobject/svg/brace.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from typing import Sequence

import numpy as np
import svgelements as se

from manim._config import config
from manim.mobject.geometry.arc import Arc
Expand All @@ -18,12 +19,12 @@
from ...animation.fading import FadeIn
from ...animation.growing import GrowFromCenter
from ...constants import *
from ...mobject.svg.svg_path import SVGPathMobject
from ...mobject.types.vectorized_mobject import VMobject
from ...utils.color import BLACK
from ..svg.svg_mobject import VMobjectFromSVGPath


class Brace(SVGPathMobject):
class Brace(VMobjectFromSVGPath):
"""Takes a mobject and draws a brace adjacent to it.
Passing a direction vector determines the direction from which the
Expand Down Expand Up @@ -99,19 +100,22 @@ def __init__(
(target_width * sharpness - default_min_width) / 2,
)

path = path_string_template.format(
linear_section_length,
-linear_section_length,
path = se.Path(
path_string_template.format(
linear_section_length,
-linear_section_length,
)
)

super().__init__(
path_string=path,
path_obj=path,
stroke_width=stroke_width,
fill_opacity=fill_opacity,
background_stroke_width=background_stroke_width,
background_stroke_color=background_stroke_color,
**kwargs,
)
self.flip(RIGHT)
self.stretch_to_fit_width(target_width)
self.shift(left - self.get_corner(UP + LEFT) + self.buff * DOWN)

Expand Down
186 changes: 0 additions & 186 deletions manim/mobject/svg/style_utils.py

This file was deleted.

Loading

0 comments on commit 309c9d4

Please sign in to comment.