A community-maintained Python framework for creating mathematical animations.
Replaced renderer strings with :class:`.RendererType` enum entries (#3017)
Benjamin Hacklbd844f46d804
diff --git a/docs/source/plugins.rst b/docs/source/plugins.rstindex 2bc3c2743..0359d29b5 100644--- a/docs/source/plugins.rst+++ b/docs/source/plugins.rst@@ -81,6 +81,7 @@ For specifying multiple plugins, comma-separated values must be used.Creating Plugins****************+Plugins are intended to extend Manim's core functionality. If you aren't surewhether a feature should be included in Manim's core, feel free to ask overon the `Discord server <https://www.manim.community/discord/>`_. Visit@@ -132,3 +133,22 @@ For example,Here, Manim will call the function ``setup_things`` defined in``manim_awesomeplugin.imports`` and calls that. It returns a list of function ormodules which will be imported globally.++A note on Renderer Compatibility+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^++Depending on which renderer is currently active, custom mobjects+created in your plugin might want to behave differently as the+corresponding mobject base classes are (unfortunately) not fully+compatible.++The currently active renderer can be queried by checking the value+of ``manim.config.renderer``. All possible renderer types are given+by :class:`.constants.RendererType`. The module :mod:`.manim.mobject.utils`+contains utility functions that return the base class for the currently+active renderer.++A simple form of renderer compatibility (by hot-swapping the class+inheritance chain) for Mobjects directly inheriting from+:class:`.Mobject` or :class:`.VMobject` can be achieved by using the+:class:`.mobject.opengl.opengl_compatibility.ConvertToOpenGL` metaclass.diff --git a/docs/source/reference_index/mobjects.rst b/docs/source/reference_index/mobjects.rstindex cd0f0b72f..a736738e1 100644--- a/docs/source/reference_index/mobjects.rst+++ b/docs/source/reference_index/mobjects.rst@@ -18,5 +18,6 @@ Mobjects~mobject.text~mobject.three_d~mobject.types+ ~mobject.utils~mobject.value_tracker~mobject.vector_fielddiff --git a/manim/__init__.py b/manim/__init__.pyindex 7734f32a2..a69712275 100644--- a/manim/__init__.py+++ b/manim/__init__.py@@ -10,26 +10,16 @@ __version__: str = pkg_resources.get_distribution(__name__).versionimport sys+# isort: off+# Importing the config module should be the first thing we do, since other# modules depend on the global config dict for initialization.from ._config import *-# Workaround to set the renderer passed via CLI args *before* importing-# Manim's classes (as long as the metaclass approach for switching-# between OpenGL and cairo rendering is in place, classes depend-# on the value of config.renderer).-for i, arg in enumerate(sys.argv):- if arg.startswith("--renderer"):- if "=" in arg:- _, parsed_renderer = arg.split("=")- else:- parsed_renderer = sys.argv[i + 1]- config.renderer = parsed_renderer- elif arg == "--use_opengl_renderer":- config.renderer = "opengl"-# many scripts depend on this -> has to be loaded first-from .utils.commands import * # isort:skip+from .utils.commands import *++# isort: onfrom .animation.animation import *from .animation.changing import *diff --git a/manim/_config/default.cfg b/manim/_config/default.cfgindex 651951cf6..2bdd2d962 100644--- a/manim/_config/default.cfg+++ b/manim/_config/default.cfg@@ -96,9 +96,6 @@ partial_movie_dir = {video_dir}/partial_movie_files/{scene_name}# --renderer [cairo|opengl]renderer = cairo-# --use_opengl_renderer-use_opengl_renderer = False-# --enable_guienable_gui = Falsediff --git a/manim/_config/utils.py b/manim/_config/utils.pyindex 723a94ba8..cdbd62fce 100644--- a/manim/_config/utils.py+++ b/manim/_config/utils.py@@ -27,6 +27,7 @@ import colourimport numpy as npfrom .. import constants+from ..constants import RendererTypefrom ..utils.tex import TexTemplate, TexTemplateFromFilefrom ..utils.tex_templates import TexTemplateLibrary@@ -293,7 +294,6 @@ class ManimConfig(MutableMapping):"text_dir","upto_animation_number","renderer",- "use_opengl_renderer","enable_gui","gui_location","use_projection_fill_shaders",@@ -425,6 +425,31 @@ class ManimConfig(MutableMapping):else:raise ValueError(f"attempted to set {key} to {val}; must be in {values}")+ def _set_from_enum(self, key: str, enum_value: Any, enum_class: EnumMeta) -> None:+ """Set ``key`` to the enum object with value ``enum_value`` in the given+ ``enum_class``.++ Tests::++ >>> from enum import Enum+ >>> class Fruit(Enum):+ ... APPLE = 1+ ... BANANA = 2+ ... CANTALOUPE = 3+ >>> test_config = ManimConfig()+ >>> test_config._set_from_enum("fruit", 1, Fruit)+ >>> test_config._d['fruit']+ <Fruit.APPLE: 1>+ >>> test_config._set_from_enum("fruit", Fruit.BANANA, Fruit)+ >>> test_config._d['fruit']+ <Fruit.BANANA: 2>+ >>> test_config._set_from_enum("fruit", 42, Fruit)+ Traceback (most recent call last):+ ...+ ValueError: 42 is not a valid Fruit+ """+ self._d[key] = enum_class(enum_value)+def _set_boolean(self, key: str | int, val: Any) -> None:"""Set ``key`` to ``val`` if ``val`` is Boolean."""if val in [True, False]:@@ -549,7 +574,6 @@ class ManimConfig(MutableMapping):"disable_caching_warning","flush_cache","custom_folders",- "use_opengl_renderer","enable_gui","fullscreen","use_projection_fill_shaders",@@ -724,7 +748,6 @@ class ManimConfig(MutableMapping):"verbosity","renderer","background_color",- "use_opengl_renderer","enable_gui","fullscreen","use_projection_fill_shaders",@@ -801,7 +824,10 @@ class ManimConfig(MutableMapping):if args.tex_template:self.tex_template = TexTemplateFromFile(tex_filename=args.tex_template)- if self.renderer == "opengl" and getattr(args, "write_to_movie") is None:+ if (+ self.renderer == RendererType.OPENGL+ and getattr(args, "write_to_movie") is None+ ):# --write_to_movie was not passed on the command line, so don't generate video.self["write_to_movie"] = False@@ -1186,12 +1212,40 @@ class ManimConfig(MutableMapping):@propertydef renderer(self):- """Renderer: "cairo", "opengl"""+ """The currently active renderer.++ Populated with one of the available renderers in :class:`.RendererType`.++ Tests::++ >>> test_config = ManimConfig()+ >>> test_config.renderer is None # a new ManimConfig is unpopulated+ True+ >>> test_config.renderer = 'opengl'+ >>> test_config.renderer+ <RendererType.OPENGL: 'opengl'>+ >>> test_config.renderer = 42+ Traceback (most recent call last):+ ...+ ValueError: 42 is not a valid RendererType++ Check that capitalization of renderer types is irrelevant::++ >>> test_config.renderer = 'OpenGL'+ >>> test_config.renderer = 'cAirO'+ """return self._d["renderer"]@renderer.setter- def renderer(self, val: str) -> None:- """Renderer for animations."""+ def renderer(self, val: str | RendererType) -> None:+ """The setter of the renderer property.++ Takes care of switching inheritance bases using the+ :class:`.ConvertToOpenGL` metaclass.+ """+ if isinstance(val, str):+ val = val.lower()+ renderer = RendererType(val)try:from manim.mobject.opengl.opengl_compatibility import ConvertToOpenGLfrom manim.mobject.opengl.opengl_mobject import OpenGLMobject@@ -1201,7 +1255,7 @@ class ManimConfig(MutableMapping):from ..mobject.types.vectorized_mobject import VMobjectfor cls in ConvertToOpenGL._converted_classes:- if val == "opengl":+ if renderer == RendererType.OPENGL:conversion_dict = {Mobject: OpenGLMobject,VMobject: OpenGLVMobject,@@ -1223,26 +1277,7 @@ class ManimConfig(MutableMapping):# can just do nothing.pass- self._set_from_list(- "renderer",- val,- ["cairo", "opengl"],- )-- @property- def use_opengl_renderer(self):- """Whether or not to use the OpenGL renderer."""- return self._d["use_opengl_renderer"]-- @use_opengl_renderer.setter- def use_opengl_renderer(self, val: bool) -> None:- self._d["use_opengl_renderer"] = val- if val:- self._set_from_list(- "renderer",- "opengl",- ["cairo", "opengl"],- )+ self._set_from_enum("renderer", renderer, RendererType)media_dir = property(lambda self: self._d["media_dir"],diff --git a/manim/animation/animation.py b/manim/animation/animation.pyindex 286bca5fe..c77af0cbf 100644--- a/manim/animation/animation.py+++ b/manim/animation/animation.py@@ -6,6 +6,7 @@ from __future__ import annotationsfrom manim.mobject.opengl.opengl_mobject import OpenGLMobjectfrom .. import config, logger+from ..constants import RendererTypefrom ..mobject import mobjectfrom ..mobject.mobject import Mobjectfrom ..mobject.opengl import opengl_mobject@@ -149,7 +150,7 @@ class Animation:self.suspend_mobject_updating: bool = suspend_mobject_updatingself.lag_ratio: float = lag_ratioself._on_finish: Callable[[Scene], None] = _on_finish- if config["renderer"] == "opengl":+ if config["renderer"] == RendererType.OPENGL:self.starting_mobject: OpenGLMobject = OpenGLMobject()self.mobject: OpenGLMobject = (mobject if mobject is not None else OpenGLMobject()@@ -265,7 +266,7 @@ class Animation:return self.mobject, self.starting_mobjectdef get_all_families_zipped(self) -> Iterable[tuple]:- if config["renderer"] == "opengl":+ if config["renderer"] == RendererType.OPENGL:return zip(*(mob.get_family() for mob in self.get_all_mobjects()))return zip(*(mob.family_members_with_points() for mob in self.get_all_mobjects())diff --git a/manim/animation/changing.py b/manim/animation/changing.pyindex 501932e9f..fbe3a4c0d 100644--- a/manim/animation/changing.py+++ b/manim/animation/changing.py@@ -158,8 +158,5 @@ class TracedPath(VMobject, metaclass=ConvertToOpenGL):if self.dissipating_time:self.time += dtif self.time - 1 > self.dissipating_time:- if config["renderer"] == "opengl":- nppcc = self.n_points_per_curve- else:- nppcc = self.n_points_per_cubic_curve+ nppcc = self.n_points_per_curveself.set_points(self.points[nppcc:])diff --git a/manim/animation/composition.py b/manim/animation/composition.pyindex f3848b6a7..609e6547b 100644--- a/manim/animation/composition.py+++ b/manim/animation/composition.py@@ -11,6 +11,7 @@ from manim.mobject.opengl.opengl_mobject import OpenGLGroupfrom .._config import configfrom ..animation.animation import Animation, prepare_animation+from ..constants import RendererTypefrom ..mobject.mobject import Group, Mobjectfrom ..scene.scene import Scenefrom ..utils.iterables import remove_list_redundancies@@ -44,7 +45,7 @@ class AnimationGroup(Animation):mobjects = remove_list_redundancies([anim.mobject for anim in self.animations if not anim.is_introducer()],)- if config["renderer"] == "opengl":+ if config["renderer"] == RendererType.OPENGL:self.group = OpenGLGroup(*mobjects)else:self.group = Group(*mobjects)diff --git a/manim/animation/transform.py b/manim/animation/transform.pyindex d4584c896..20e5192fe 100644--- a/manim/animation/transform.py+++ b/manim/animation/transform.py@@ -36,7 +36,13 @@ from manim.mobject.opengl.opengl_mobject import OpenGLGroup, OpenGLMobjectfrom .. import configfrom ..animation.animation import Animation-from ..constants import DEFAULT_POINTWISE_FUNCTION_RUN_TIME, DEGREES, ORIGIN, OUT+from ..constants import (+ DEFAULT_POINTWISE_FUNCTION_RUN_TIME,+ DEGREES,+ ORIGIN,+ OUT,+ RendererType,+)from ..mobject.mobject import Group, Mobjectfrom ..utils.paths import path_along_arc, path_along_circlesfrom ..utils.rate_functions import smooth, squish_rate_func@@ -191,7 +197,7 @@ class Transform(Animation):self.target_copy = self.target_mobject.copy()# Note, this potentially changes the structure# of both mobject and target_mobject- if config["renderer"] == "opengl":+ if config.renderer == RendererType.OPENGL:self.mobject.align_data_and_family(self.target_copy)else:self.mobject.align_data(self.target_copy)@@ -222,7 +228,7 @@ class Transform(Animation):self.starting_mobject,self.target_copy,]- if config["renderer"] == "opengl":+ if config.renderer == RendererType.OPENGL:return zip(*(mob.get_family() for mob in mobs))return zip(*(mob.family_members_with_points() for mob in mobs))@@ -830,7 +836,7 @@ class FadeTransform(Transform):self.stretch = stretchself.dim_to_match = dim_to_matchmobject.save_state()- if config["renderer"] == "opengl":+ if config.renderer == RendererType.OPENGL:group = OpenGLGroup(mobject, target_mobject.copy())else:group = Group(mobject, target_mobject.copy())diff --git a/manim/animation/transform_matching_parts.py b/manim/animation/transform_matching_parts.pyindex 85fe5b4aa..8a400983b 100644--- a/manim/animation/transform_matching_parts.py+++ b/manim/animation/transform_matching_parts.py@@ -12,6 +12,7 @@ from manim.mobject.opengl.opengl_mobject import OpenGLGroup, OpenGLMobjectfrom manim.mobject.opengl.opengl_vectorized_mobject import OpenGLVGroup, OpenGLVMobjectfrom .._config import config+from ..constants import RendererTypefrom ..mobject.mobject import Group, Mobjectfrom ..mobject.types.vectorized_mobject import VGroup, VMobjectfrom .composition import AnimationGroup@@ -146,7 +147,7 @@ class TransformMatchingAbstractBase(AnimationGroup):for sm in self.get_mobject_parts(mobject):key = self.get_mobject_key(sm)if key not in shape_map:- if config["renderer"] == "opengl":+ if config["renderer"] == RendererType.OPENGL:shape_map[key] = OpenGLVGroup()else:shape_map[key] = VGroup()diff --git a/manim/cli/render/commands.py b/manim/cli/render/commands.pyindex f10567659..9c1fc83fb 100644--- a/manim/cli/render/commands.py+++ b/manim/cli/render/commands.py@@ -17,7 +17,7 @@ import requestsfrom ... import __version__, config, console, error_console, loggerfrom ..._config import tempconfig-from ...constants import EPILOG+from ...constants import EPILOG, RendererTypefrom ...utils.module_ops import scene_classes_from_filefrom .ease_of_access_options import ease_of_access_optionsfrom .global_options import global_options@@ -46,12 +46,6 @@ def render(SCENES is an optional list of scenes in the file."""- if args["use_opengl_renderer"]:- logger.warning(- "--use_opengl_renderer is deprecated, please use --renderer=opengl instead!",- )- args["renderer"] = "opengl"-if args["save_as_gif"]:logger.warning("--save_as_gif is deprecated, please use --format=gif instead!")args["format"] = "gif"@@ -90,7 +84,7 @@ def render(config.digest_args(click_args)file = Path(config.input_file)- if config.renderer == "opengl":+ if config.renderer == RendererType.OPENGL:from manim.renderer.opengl_renderer import OpenGLRenderertry:diff --git a/manim/cli/render/render_options.py b/manim/cli/render/render_options.pyindex 9b99e6272..22166beb7 100644--- a/manim/cli/render/render_options.py+++ b/manim/cli/render/render_options.py@@ -5,7 +5,7 @@ import reimport clickfrom cloup import option, option_group-from manim.constants import QUALITIES+from manim.constants import QUALITIES, RendererTypefrom ... import logger@@ -95,15 +95,12 @@ render_options = option_group(),option("--renderer",- type=click.Choice(["cairo", "opengl"], case_sensitive=False),+ type=click.Choice(+ [renderer_type.value for renderer_type in RendererType],+ case_sensitive=False,+ ),help="Select a renderer for your Scene.",- default=None,- ),- option(- "--use_opengl_renderer",- is_flag=True,- help="Render scenes using OpenGL (Deprecated).",- default=None,+ default="cairo",),option("-g",diff --git a/manim/constants.py b/manim/constants.pyindex 2eb8b9147..ef50e0b39 100644--- a/manim/constants.py+++ b/manim/constants.py@@ -4,12 +4,13 @@ Constant definitions.from __future__ import annotations+from enum import Enum+import numpy as npfrom cloup import Contextfrom PIL.Image import Resampling__all__ = [- "NOT_SETTING_FONT_MSG","SCENE_NOT_FOUND_MESSAGE","CHOOSE_NUMBER_MESSAGE","INVALID_NUMBER_MESSAGE",@@ -64,24 +65,16 @@ __all__ = ["PI","TAU","DEGREES",- "GIF_FILE_EXTENSION",- "FFMPEG_VERBOSITY_MAP",- "VERBOSITY_CHOICES","QUALITIES","DEFAULT_QUALITY",- "DEFAULT_QUALITY_SHORT","EPILOG","CONTEXT_SETTINGS","SHIFT_VALUE","CTRL_VALUE",+ "RendererType",]# Messages-NOT_SETTING_FONT_MSG: str = """-You haven't set font.-If you are not using English, this may cause text rendering problem.-You set font like:-text = Text('your text', font='your font')-"""+SCENE_NOT_FOUND_MESSAGE: str = """{} is not in the script"""@@ -200,18 +193,6 @@ TAU: float = 2 * PIDEGREES: float = TAU / 360"""The exchange rate between radians and degrees."""-# gif stuff-GIF_FILE_EXTENSION: str = ".gif"--FFMPEG_VERBOSITY_MAP: dict[str, str] = {- "DEBUG": "error",- "INFO": "error",- "WARNING": "error",- "ERROR": "error",- "CRITICAL": "fatal",-}-VERBOSITY_CHOICES = FFMPEG_VERBOSITY_MAP.keys()-# Video qualitiesQUALITIES: dict[str, dict[str, str | int | None]] = {"fourk_quality": {@@ -253,7 +234,6 @@ QUALITIES: dict[str, dict[str, str | int | None]] = {}DEFAULT_QUALITY: str = "high_quality"-DEFAULT_QUALITY_SHORT = QUALITIES[DEFAULT_QUALITY]["flag"]EPILOG = "Made with <3 by Manim Community developers."SHIFT_VALUE = 65505@@ -264,3 +244,23 @@ CONTEXT_SETTINGS = Context.settings(align_sections=True,show_constraints=True,)+++class RendererType(Enum):+ """An enumeration of all renderer types that can be assigned to+ the ``config.renderer`` attribute.++ Manim's configuration allows assigning string values to the renderer+ setting, the values are then replaced by the corresponding enum object.+ In other words, you can run::++ config.renderer = "opengl"++ and checking the renderer afterwards reveals that the attribute has+ assumed the value::++ <RendererType.OPENGL: 'opengl'>+ """++ CAIRO = "cairo" #: A renderer based on the cairo backend.+ OPENGL = "opengl" #: An OpenGL-based renderer.diff --git a/manim/mobject/geometry/boolean_ops.py b/manim/mobject/geometry/boolean_ops.pyindex a7900339b..9d3ccf034 100644--- a/manim/mobject/geometry/boolean_ops.py+++ b/manim/mobject/geometry/boolean_ops.py@@ -12,6 +12,8 @@ from manim import configfrom manim.mobject.opengl.opengl_compatibility import ConvertToOpenGLfrom manim.mobject.types.vectorized_mobject import VMobject+from ...constants import RendererType+__all__ = ["Union", "Intersection", "Difference", "Exclusion"]@@ -82,7 +84,7 @@ class _BooleanOps(VMobject, metaclass=ConvertToOpenGL):return path# In OpenGL it's quadratic beizer curves while on Cairo it's cubic...- if config.renderer == "opengl":+ if config.renderer == RendererType.OPENGL:subpaths = vmobject.get_subpaths_from_points(points)for subpath in subpaths:quads = vmobject.get_bezier_tuples_from_points(subpath)@@ -92,7 +94,7 @@ class _BooleanOps(VMobject, metaclass=ConvertToOpenGL):path.quadTo(*p1[:2], *p2[:2])if vmobject.consider_points_equals(subpath[0], subpath[-1]):path.close()- else:+ elif config.renderer == RendererType.CAIRO:subpaths = vmobject.gen_subpaths_from_points_2d(points)for subpath in subpaths:quads = vmobject.gen_cubic_bezier_tuples_from_points(subpath)diff --git a/manim/mobject/geometry/line.py b/manim/mobject/geometry/line.pyindex 418981374..695881ae9 100644--- a/manim/mobject/geometry/line.py+++ b/manim/mobject/geometry/line.py@@ -598,7 +598,7 @@ class Arrow(Line):def _set_stroke_width_from_length(self):"""Sets stroke width based on length."""max_ratio = self.max_stroke_width_to_length_ratio- if config.renderer == "opengl":+ if config.renderer == RendererType.OPENGL:self.set_stroke(width=min(self.initial_stroke_width, max_ratio * self.get_length()),recurse=False,diff --git a/manim/mobject/graphing/coordinate_systems.py b/manim/mobject/graphing/coordinate_systems.pyindex ae7665509..80f88b94c 100644--- a/manim/mobject/graphing/coordinate_systems.py+++ b/manim/mobject/graphing/coordinate_systems.py@@ -918,7 +918,7 @@ class CoordinateSystem:)self.add(axes, trig_plane)"""- if config.renderer != "opengl":+ if config.renderer == RendererType.CAIRO:surface = Surface(lambda u, v: self.c2p(u, v, function(u, v)),u_range=u_range,@@ -931,7 +931,7 @@ class CoordinateSystem:colorscale=colorscale,axis=colorscale_axis,)- else:+ elif config.renderer == RendererType.OPENGL:surface = OpenGLSurface(lambda u, v: self.c2p(u, v, function(u, v)),u_range=u_range,@@ -2336,7 +2336,7 @@ class ThreeDAxes(Axes):self.add(z_axis)self.z_axis = z_axis- if config.renderer != "opengl":+ if config.renderer == RendererType.CAIRO:self._add_3d_pieces()self._set_axis_shading()diff --git a/manim/mobject/mobject.py b/manim/mobject/mobject.pyindex 4def2c5a8..dddf3c563 100644--- a/manim/mobject/mobject.py+++ b/manim/mobject/mobject.py@@ -333,10 +333,7 @@ class Mobject:return resultdef __repr__(self):- if config["renderer"] == "opengl":- return super().__repr__()- else:- return str(self.name)+ return str(self.name)def reset_points(self):"""Sets :attr:`points` to be an empty array."""diff --git a/manim/mobject/opengl/opengl_compatibility.py b/manim/mobject/opengl/opengl_compatibility.pyindex 5bbb2af19..dc7c020e1 100644--- a/manim/mobject/opengl/opengl_compatibility.py+++ b/manim/mobject/opengl/opengl_compatibility.py@@ -8,21 +8,19 @@ from manim.mobject.opengl.opengl_point_cloud_mobject import OpenGLPMobjectfrom manim.mobject.opengl.opengl_three_dimensions import OpenGLSurfacefrom manim.mobject.opengl.opengl_vectorized_mobject import OpenGLVMobject+from ...constants import RendererType+class ConvertToOpenGL(ABCMeta):"""Metaclass for swapping (V)Mobject with its OpenGL counterpart at runtimedepending on config.renderer. This metaclass should only need to be inheritedon the lowest order inheritance classes such as Mobject and VMobject.-- Note that with this implementation, changing the value of ``config.renderer``- after Manim has been imported won't have the desired effect and will lead to- spurious errors."""_converted_classes = []def __new__(mcls, name, bases, namespace): # noqa: B902- if config.renderer == "opengl":+ if config.renderer == RendererType.OPENGL:# Must check class names to prevent# cyclic importing.base_names_to_opengl = {diff --git a/manim/mobject/opengl/opengl_mobject.py b/manim/mobject/opengl/opengl_mobject.pyindex 7b2d79d23..5e3cd2ecf 100644--- a/manim/mobject/opengl/opengl_mobject.py+++ b/manim/mobject/opengl/opengl_mobject.py@@ -104,8 +104,10 @@ class OpenGLMobject:listen_to_events=False,model_matrix=None,should_render=True,+ name: str | None = None,**kwargs,):+ self.name = self.__class__.__name__ if name is None else name# getattr in case data/uniforms are already defined in parent classes.self.data = getattr(self, "data", {})self.uniforms = getattr(self, "uniforms", {})@@ -163,7 +165,7 @@ class OpenGLMobject:return self.__class__.__name__def __repr__(self):- return self.__class__.__name__+ return str(self.name)def __sub__(self, other):raise NotImplementedErrordiff --git a/manim/mobject/opengl/opengl_vectorized_mobject.py b/manim/mobject/opengl/opengl_vectorized_mobject.pyindex 1d6f6d7a4..90b1f38b6 100644--- a/manim/mobject/opengl/opengl_vectorized_mobject.py+++ b/manim/mobject/opengl/opengl_vectorized_mobject.py@@ -315,7 +315,7 @@ class OpenGLVMobject(OpenGLMobject):def match_style(self, vmobject, recurse=True):vmobject_style = vmobject.get_style()- if config.renderer == "opengl":+ if config.renderer == RendererType.OPENGL:vmobject_style["stroke_width"] = vmobject_style["stroke_width"][0][0]self.set_style(**vmobject_style, recurse=False)if recurse:@@ -1639,7 +1639,7 @@ class OpenGLVGroup(OpenGLVMobject):>>> from manim import Triangle, Square>>> from manim.opengl import OpenGLVGroup>>> config.renderer- 'opengl'+ <RendererType.OPENGL: 'opengl'>>>> vg = OpenGLVGroup()>>> triangle, square = Triangle(), Square()>>> vg.add(triangle)diff --git a/manim/mobject/table.py b/manim/mobject/table.pyindex 989873644..7e8e45fca 100644--- a/manim/mobject/table.py+++ b/manim/mobject/table.py@@ -83,6 +83,7 @@ from ..animation.creation import Create, Writefrom ..animation.fading import FadeInfrom ..mobject.types.vectorized_mobject import VGroup, VMobjectfrom ..utils.color import BLACK, YELLOW+from .utils import get_vectorized_mobject_classclass Table(VGroup):@@ -328,13 +329,7 @@ class Table(VGroup):else:# Placeholder to use arrange_in_grid if top_left_entry is not set.# Import OpenGLVMobject to work with --renderer=opengl- if config.renderer == "opengl":- from manim.opengl import OpenGLVMobject-- dummy_class = OpenGLVMobject- else:- dummy_class = VMobject- dummy_mobject = dummy_class()+ dummy_mobject = get_vectorized_mobject_class()()col_labels = [dummy_mobject] + self.col_labelsmob_table.insert(0, col_labels)else:diff --git a/manim/mobject/text/numbers.py b/manim/mobject/text/numbers.pyindex 5a0c8413f..f5a3b9220 100644--- a/manim/mobject/text/numbers.py+++ b/manim/mobject/text/numbers.py@@ -252,7 +252,7 @@ class DecimalNumber(VMobject, metaclass=ConvertToOpenGL):for sm1, sm2 in zip(self.submobjects, old_submobjects):sm1.match_style(sm2)- if config.renderer != "opengl":+ if config.renderer == RendererType.CAIRO:for mob in old_family:# Dumb hack...due to how scene handles families# of animated mobjectsdiff --git a/manim/mobject/text/tex_mobject.py b/manim/mobject/text/tex_mobject.pyindex 413a0f022..92a4bd2cc 100644--- a/manim/mobject/text/tex_mobject.py+++ b/manim/mobject/text/tex_mobject.py@@ -214,9 +214,9 @@ class SingleStringMathTex(SVGMobject):return self.tex_stringdef init_colors(self, propagate_colors=True):- if config.renderer == "opengl":+ if config.renderer == RendererType.OPENGL:super().init_colors()- else:+ elif config.renderer == RendererType.CAIRO:super().init_colors(propagate_colors=propagate_colors)diff --git a/manim/mobject/text/text_mobject.py b/manim/mobject/text/text_mobject.pyindex 7ab523684..803d7b435 100644--- a/manim/mobject/text/text_mobject.py+++ b/manim/mobject/text/text_mobject.py@@ -488,10 +488,7 @@ class Text(SVGMobject):self.submobjects = [*self._gen_chars()]self.chars = self.get_group_class()(*self.submobjects)self.text = text_without_tabs.replace(" ", "").replace("\n", "")- if config.renderer == "opengl":- nppc = self.n_points_per_curve- else:- nppc = self.n_points_per_cubic_curve+ nppc = self.n_points_per_curvefor each in self:if len(each.points) == 0:continue@@ -778,9 +775,9 @@ class Text(SVGMobject):return svg_filedef init_colors(self, propagate_colors=True):- if config.renderer == "opengl":+ if config.renderer == RendererType.OPENGL:super().init_colors()- else:+ elif config.renderer == RendererType.CAIRO:super().init_colors(propagate_colors=propagate_colors)@@ -1151,10 +1148,7 @@ class MarkupText(SVGMobject):self.chars = self.get_group_class()(*self.submobjects)self.text = text_without_tabs.replace(" ", "").replace("\n", "")- if config.renderer == "opengl":- nppc = self.n_points_per_curve- else:- nppc = self.n_points_per_cubic_curve+ nppc = self.n_points_per_curvefor each in self:if len(each.points) == 0:continuediff --git a/manim/mobject/three_d/three_dimensions.py b/manim/mobject/three_d/three_dimensions.pyindex a47095a3e..6f53ca91d 100644--- a/manim/mobject/three_d/three_dimensions.py+++ b/manim/mobject/three_d/three_dimensions.py@@ -303,9 +303,9 @@ class Surface(VGroup, metaclass=ConvertToOpenGL):new_colors[i],color_index,)- if config.renderer == "opengl":+ if config.renderer == RendererType.OPENGL:mob.set_color(mob_color, recurse=False)- else:+ elif config.renderer == RendererType.CAIRO:mob.set_color(mob_color, family=False)break@@ -367,9 +367,9 @@ class Sphere(Surface):v_range=(0, PI),**kwargs,):- if config.renderer == "opengl":+ if config.renderer == RendererType.OPENGL:res_value = (101, 51)- else:+ elif config.renderer == RendererType.CAIRO:res_value = (24, 12)resolution = resolution if resolution is not None else res_value@@ -754,8 +754,13 @@ class Cylinder(Surface):def add_bases(self):"""Adds the end caps of the cylinder."""- color = self.color if config["renderer"] == "opengl" else self.fill_color- opacity = self.opacity if config["renderer"] == "opengl" else self.fill_opacity+ if config.renderer == RendererType.OPENGL:+ color = self.color+ opacity = self.opacity+ elif config.renderer == RendererType.CAIRO:+ color = self.fill_color+ opacity = self.fill_opacity+self.base_top = Circle(radius=self.radius,color=color,@@ -1115,9 +1120,9 @@ class Torus(Surface):resolution=None,**kwargs,):- if config.renderer == "opengl":+ if config.renderer == RendererType.OPENGL:res_value = (101, 101)- else:+ elif config.renderer == RendererType.CAIRO:res_value = (24, 24)resolution = resolution if resolution is not None else res_valuediff --git a/manim/mobject/types/vectorized_mobject.py b/manim/mobject/types/vectorized_mobject.pyindex 44a816791..3aa6dfe40 100644--- a/manim/mobject/types/vectorized_mobject.py+++ b/manim/mobject/types/vectorized_mobject.py@@ -120,6 +120,11 @@ class VMobject(Mobject):if stroke_color:self.stroke_color = stroke_color+ # OpenGL compatibility+ @property+ def n_points_per_curve(self):+ return self.n_points_per_cubic_curve+def get_group_class(self):return VGroup@@ -2262,7 +2267,7 @@ class VectorizedPoint(VMobject, metaclass=ConvertToOpenGL):)self.set_points(np.array([location]))- basecls = OpenGLVMobject if config.renderer == "opengl" else VMobject+ basecls = OpenGLVMobject if config.renderer == RendererType.OPENGL else VMobject@basecls.width.getterdef width(self):@@ -2461,7 +2466,7 @@ class DashedVMobject(VMobject, metaclass=ConvertToOpenGL):)# Family is already taken care of by get_subcurve# implementation- if config.renderer == "opengl":+ if config.renderer == RendererType.OPENGL:self.match_style(vmobject, recurse=False)else:self.match_style(vmobject, family=False)diff --git a/manim/mobject/utils.py b/manim/mobject/utils.pynew file mode 100644index 000000000..b38bb57f2--- /dev/null+++ b/manim/mobject/utils.py@@ -0,0 +1,107 @@+"""Utilities for working with mobjects."""++from __future__ import annotations++__all__ = [+ "get_mobject_class",+ "get_point_mobject_class",+ "get_vectorized_mobject_class",+]++from .._config import config+from ..constants import RendererType+from .mobject import Mobject+from .opengl.opengl_mobject import OpenGLMobject+from .opengl.opengl_point_cloud_mobject import OpenGLPMobject+from .opengl.opengl_vectorized_mobject import OpenGLVMobject+from .types.point_cloud_mobject import PMobject+from .types.vectorized_mobject import VMobject+++def get_mobject_class() -> type:+ """Gets the base mobject class, depending on the currently active renderer.++ .. NOTE::++ This method is intended to be used in the code base of Manim itself+ or in plugins where code should work independent of the selected+ renderer.++ Examples+ --------++ The function has to be explicitly imported. We test that+ the name of the returned class is one of the known mobject+ base classes::++ >>> from manim.mobject.utils import get_mobject_class+ >>> get_mobject_class().__name__ in ['Mobject', 'OpenGLMobject']+ True+ """+ if config.renderer == RendererType.CAIRO:+ return Mobject+ if config.renderer == RendererType.OPENGL:+ return OpenGLMobject+ raise NotImplementedError(+ "Base mobjects are not implemented for the active renderer."+ )+++def get_vectorized_mobject_class() -> type:+ """Gets the vectorized mobject class, depending on the currently+ active renderer.++ .. NOTE::++ This method is intended to be used in the code base of Manim itself+ or in plugins where code should work independent of the selected+ renderer.++ Examples+ --------++ The function has to be explicitly imported. We test that+ the name of the returned class is one of the known mobject+ base classes::++ >>> from manim.mobject.utils import get_vectorized_mobject_class+ >>> get_vectorized_mobject_class().__name__ in ['VMobject', 'OpenGLVMobject']+ True+ """+ if config.renderer == RendererType.CAIRO:+ return VMobject+ if config.renderer == RendererType.OPENGL:+ return OpenGLVMobject+ raise NotImplementedError(+ "Vectorized mobjects are not implemented for the active renderer."+ )+++def get_point_mobject_class() -> type:+ """Gets the point cloud mobject class, depending on the currently+ active renderer.++ .. NOTE::++ This method is intended to be used in the code base of Manim itself+ or in plugins where code should work independent of the selected+ renderer.++ Examples+ --------++ The function has to be explicitly imported. We test that+ the name of the returned class is one of the known mobject+ base classes::++ >>> from manim.mobject.utils import get_point_mobject_class+ >>> get_point_mobject_class().__name__ in ['PMobject', 'OpenGLPMobject']+ True+ """+ if config.renderer == RendererType.CAIRO:+ return PMobject+ if config.renderer == RendererType.OPENGL:+ return OpenGLPMobject+ raise NotImplementedError(+ "Point cloud mobjects are not implemented for the active renderer."+ )diff --git a/manim/mobject/vector_field.py b/manim/mobject/vector_field.pyindex 75b0f2814..14f2f64f3 100644--- a/manim/mobject/vector_field.py+++ b/manim/mobject/vector_field.py@@ -20,15 +20,15 @@ from PIL import Imagefrom manim.animation.updaters.update import UpdateFromAlphaFuncfrom manim.mobject.geometry.line import Vectorfrom manim.mobject.graphing.coordinate_systems import CoordinateSystem-from manim.mobject.opengl.opengl_vectorized_mobject import OpenGLVMobjectfrom .. import configfrom ..animation.composition import AnimationGroup, Successionfrom ..animation.creation import Createfrom ..animation.indication import ShowPassingFlash-from ..constants import OUT, RIGHT, UP+from ..constants import OUT, RIGHT, UP, RendererTypefrom ..mobject.mobject import Mobject-from ..mobject.types.vectorized_mobject import VGroup, VMobject+from ..mobject.types.vectorized_mobject import VGroup+from ..mobject.utils import get_vectorized_mobject_classfrom ..utils.bezier import interpolate, inverse_interpolatefrom ..utils.color import BLUE_E, GREEN, RED, YELLOW, color_to_rgb, rgb_to_colorfrom ..utils.rate_functions import ease_out_sine, linear@@ -799,7 +799,7 @@ class StreamLines(VectorField):max_steps = ceil(virtual_time / dt) + 1if not self.single_color:self.background_img = self.get_colored_background_image()- if config["renderer"] == "opengl":+ if config["renderer"] == RendererType.OPENGL:self.values_to_rgbas = self.get_vectorized_rgba_gradient_function(min_color_scheme_value,max_color_scheme_value,@@ -816,17 +816,14 @@ class StreamLines(VectorField):step = max_stepsif not step:continue- if config["renderer"] == "opengl":- line = OpenGLVMobject()- else:- line = VMobject()+ line = get_vectorized_mobject_class()()line.duration = step * dtstep = max(1, int(len(points) / self.max_anchors_per_line))line.set_points_smoothly(points[::step])if self.single_color:line.set_stroke(self.color)else:- if config["renderer"] == "opengl":+ if config.renderer == RendererType.OPENGL:# scaled for compatibility with cairoline.set_stroke(width=self.stroke_width / 4.0)norms = np.array(diff --git a/manim/scene/scene.py b/manim/scene/scene.pyindex 103a6a62d..bf5753750 100644--- a/manim/scene/scene.py+++ b/manim/scene/scene.py@@ -124,7 +124,7 @@ class Scene:self.mouse_press_callbacks = []self.interactive_mode = False- if config.renderer == "opengl":+ if config.renderer == RendererType.OPENGL:# Items associated with interactionself.mouse_point = OpenGLPoint()self.mouse_drag_point = OpenGLPoint()@@ -424,12 +424,12 @@ class Scene:listList of mobject family members."""- if config.renderer == "opengl":+ if config.renderer == RendererType.OPENGL:family_members = []for mob in self.mobjects:family_members.extend(mob.get_family())return family_members- else:+ elif config.renderer == RendererType.CAIRO:return extract_mobject_family_members(self.mobjects,use_z_index=self.renderer.camera.use_z_index,@@ -451,7 +451,7 @@ class Scene:The same scene after adding the Mobjects in."""- if config.renderer == "opengl":+ if config.renderer == RendererType.OPENGL:new_mobjects = []new_meshes = []for mobject_or_mesh in mobjects:@@ -463,7 +463,7 @@ class Scene:self.mobjects += new_mobjectsself.remove(*new_meshes)self.meshes += new_meshes- else:+ elif config.renderer == RendererType.CAIRO:mobjects = [*mobjects, *self.foreground_mobjects]self.restructure_mobjects(to_remove=mobjects)self.mobjects += mobjects@@ -498,7 +498,7 @@ class Scene:*mobjectsThe mobjects to remove."""- if config.renderer == "opengl":+ if config.renderer == RendererType.OPENGL:mobjects_to_remove = []meshes_to_remove = set()for mobject_or_mesh in mobjects:@@ -514,7 +514,7 @@ class Scene:filter(lambda mesh: mesh not in set(meshes_to_remove), self.meshes),)return self- else:+ elif config.renderer == RendererType.CAIRO:for list_name in "mobjects", "foreground_mobjects":self.restructure_mobjects(mobjects, list_name, False)return self@@ -1162,7 +1162,7 @@ class Scene:animation._setup_scene(self)animation.begin()- if config.renderer != "opengl":+ if config.renderer == RendererType.CAIRO:# Paint all non-moving objects onto the screen, so they don't# have to be rendered every frame(diff --git a/manim/scene/scene_file_writer.py b/manim/scene/scene_file_writer.pyindex f03f78319..0767d8e50 100644--- a/manim/scene/scene_file_writer.py+++ b/manim/scene/scene_file_writer.py@@ -8,7 +8,6 @@ import jsonimport osimport shutilimport subprocess-import sysfrom pathlib import Pathfrom typing import TYPE_CHECKING, Any@@ -21,7 +20,7 @@ from manim import __version__from .. import config, loggerfrom .._config.logger_utils import set_file_logger-from ..constants import GIF_FILE_EXTENSION+from ..constants import RendererTypefrom ..utils.file_ops import (add_extension_if_not_present,add_version_before_extension,@@ -149,7 +148,7 @@ class SceneFileWriter:if is_gif_format():self.gif_file_path = add_extension_if_not_present(- self.output_name, GIF_FILE_EXTENSION+ self.output_name, ".gif")if not config["output_file"]:@@ -384,9 +383,9 @@ class SceneFileWriter:frame_or_rendererPixel array of the frame."""- if config.renderer == "opengl":+ if config.renderer == RendererType.OPENGL:self.write_opengl_frame(frame_or_renderer)- else:+ elif config.renderer == RendererType.CAIRO:frame = frame_or_rendererif write_to_movie():self.writing_process.stdin.write(frame.tobytes())@@ -481,7 +480,7 @@ class SceneFileWriter:fps = config["frame_rate"]if fps == int(fps): # fps is integerfps = int(fps)- if config.renderer == "opengl":+ if config.renderer == RendererType.OPENGL:width, height = self.renderer.get_pixel_shape()else:height = config["pixel_height"]@@ -506,7 +505,7 @@ class SceneFileWriter:"-metadata",f"comment=Rendered with Manim Community v{__version__}",]- if config.renderer == "opengl":+ if config.renderer == RendererType.OPENGL:command += ["-vf", "vflip"]if is_webm_format():command += ["-vcodec", "libvpx-vp9", "-auto-alt-ref", "0"]diff --git a/manim/scene/three_d_scene.py b/manim/scene/three_d_scene.pyindex 258cdce1c..4e619b7ff 100644--- a/manim/scene/three_d_scene.py+++ b/manim/scene/three_d_scene.py@@ -20,7 +20,7 @@ from .. import configfrom ..animation.animation import Animationfrom ..animation.transform import Transformfrom ..camera.three_d_camera import ThreeDCamera-from ..constants import DEGREES+from ..constants import DEGREES, RendererTypefrom ..mobject.mobject import Mobjectfrom ..mobject.types.vectorized_mobject import VectorizedPoint, VGroupfrom ..renderer.opengl_renderer import OpenGLCamera@@ -117,7 +117,7 @@ class ThreeDScene(Scene):# can begin and end smoothlyabout: str = about.lower()try:- if config.renderer != "opengl":+ if config.renderer == RendererType.CAIRO:trackers = {"theta": self.camera.theta_tracker,"phi": self.camera.phi_tracker,@@ -126,7 +126,7 @@ class ThreeDScene(Scene):x: ValueTracker = trackers[about]x.add_updater(lambda m, dt: x.increment_value(rate * dt))self.add(x)- else:+ elif config.renderer == RendererType.OPENGL:cam: OpenGLCamera = self.cameramethods = {"theta": cam.increment_theta,@@ -144,7 +144,7 @@ class ThreeDScene(Scene):"""about: str = about.lower()try:- if config.renderer != "opengl":+ if config.renderer == RendererType.CAIRO:trackers = {"theta": self.camera.theta_tracker,"phi": self.camera.phi_tracker,@@ -153,7 +153,7 @@ class ThreeDScene(Scene):x: ValueTracker = trackers[about]x.clear_updaters()self.remove(x)- else:+ elif config.renderer == RendererType.OPENGL:self.camera.clear_updaters()except Exception:raise ValueError("Invalid ambient rotation angle.")@@ -254,7 +254,7 @@ class ThreeDScene(Scene):"""anims = []- if config.renderer != "opengl":+ if config.renderer == RendererType.CAIRO:self.camera: ThreeDCameravalue_tracker_pairs = [(phi, self.camera.phi_tracker),@@ -268,7 +268,7 @@ class ThreeDScene(Scene):anims.append(tracker.animate.set_value(value))if frame_center is not None:anims.append(self.camera._frame_center.animate.move_to(frame_center))- else:+ elif config.renderer == RendererType.OPENGL:cam: OpenGLCamera = self.cameracam2 = cam.copy()methods = {@@ -312,7 +312,7 @@ class ThreeDScene(Scene):# it is required to redraw every object. These lines remove frame_center from the Scene once# its animation is done, ensuring that manim does not think that it is moving. Since the# frame_center is never actually drawn, this shouldn't break anything.- if frame_center is not None and config.renderer != "opengl":+ if frame_center is not None and config.renderer == RendererType.CAIRO:self.remove(self.camera._frame_center)def get_moving_mobjects(self, *animations: Animation):@@ -351,10 +351,10 @@ class ThreeDScene(Scene):use_static_center_func : boolcenter_func : function"""- if config.renderer != "opengl":+ if config.renderer == RendererType.CAIRO:self.add(*mobjects)self.renderer.camera.add_fixed_orientation_mobjects(*mobjects, **kwargs)- else:+ elif config.renderer == RendererType.OPENGL:for mob in mobjects:mob: OpenGLMobjectmob.fix_orientation()@@ -372,11 +372,11 @@ class ThreeDScene(Scene):*mobjectsThe Mobjects whose orientation must be fixed."""- if config.renderer != "opengl":+ if config.renderer == RendererType.CAIRO:self.add(*mobjects)self.camera: ThreeDCameraself.camera.add_fixed_in_frame_mobjects(*mobjects)- else:+ elif config.renderer == RendererType.OPENGL:for mob in mobjects:mob: OpenGLMobjectmob.fix_in_frame()@@ -394,9 +394,9 @@ class ThreeDScene(Scene):*mobjectsThe Mobjects whose orientation must be unfixed."""- if config.renderer != "opengl":+ if config.renderer == RendererType.CAIRO:self.renderer.camera.remove_fixed_orientation_mobjects(*mobjects)- else:+ elif config.renderer == RendererType.OPENGL:for mob in mobjects:mob: OpenGLMobjectmob.unfix_orientation()@@ -413,9 +413,9 @@ class ThreeDScene(Scene):*mobjectsThe Mobjects whose position and orientation must be unfixed."""- if config.renderer != "opengl":+ if config.renderer == RendererType.CAIRO:self.renderer.camera.remove_fixed_in_frame_mobjects(*mobjects)- else:+ elif config.renderer == RendererType.OPENGL:for mob in mobjects:mob: OpenGLMobjectmob.unfix_from_frame()diff --git a/manim/utils/ipython_magic.py b/manim/utils/ipython_magic.pyindex 1e4fef9d9..c877cabd7 100644--- a/manim/utils/ipython_magic.py+++ b/manim/utils/ipython_magic.py@@ -13,6 +13,8 @@ from manim import Group, config, logger, tempconfigfrom manim.__main__ import mainfrom manim.renderer.shader import shader_program_cache+from ..constants import RendererType+try:from IPython import get_ipythonfrom IPython.core.interactiveshell import InteractiveShell@@ -128,21 +130,10 @@ else:config.digest_args(args)renderer = None- if config.renderer == "opengl":- # Check if the imported mobjects extend the OpenGLMobject class- # meaning ConvertToOpenGL did its job- if "OpenGLMobject" in [- parent_class.__name__ for parent_class in Group.mro()- ]:- from manim.renderer.opengl_renderer import OpenGLRenderer-- renderer = OpenGLRenderer()- else:- logger.warning(- "Renderer must be set to OpenGL in the configuration file "- "before importing Manim! Using cairo renderer instead.",- )- config.renderer = "cairo"+ if config.renderer == RendererType.OPENGL:+ from manim.renderer.opengl_renderer import OpenGLRenderer++ renderer = OpenGLRenderer()try:SceneClass = local_ns[config["scene_names"][0]]diff --git a/manim/utils/space_ops.py b/manim/utils/space_ops.pyindex fe5fb8f13..203462057 100644--- a/manim/utils/space_ops.py+++ b/manim/utils/space_ops.py@@ -45,7 +45,7 @@ from mapbox_earcut import triangulate_float32 as earcutfrom scipy.spatial.transform import Rotationfrom .. import config-from ..constants import DOWN, OUT, PI, RIGHT, TAU, UP+from ..constants import DOWN, OUT, PI, RIGHT, TAU, UP, RendererTypefrom ..utils.iterables import adjacent_pairs@@ -69,7 +69,7 @@ def quaternion_mult(Union[np.ndarray, List[Union[float, np.ndarray]]]Returns a list of product of two quaternions."""- if config.renderer == "opengl":+ if config.renderer == RendererType.OPENGL:if len(quats) == 0:return [1, 0, 0, 0]result = quats[0]@@ -83,7 +83,7 @@ def quaternion_mult(w1 * z2 + z1 * w2 + x1 * y2 - y1 * x2,]return result- else:+ elif config.renderer == RendererType.CAIRO:q1 = quats[0]q2 = quats[1]@@ -122,11 +122,11 @@ def quaternion_from_angle_axis(List[float]Gives back a quaternion from the angle and axis"""- if config.renderer == "opengl":+ if config.renderer == RendererType.OPENGL:if not axis_normalized:axis = normalize(axis)return [math.cos(angle / 2), *(math.sin(angle / 2) * axis)]- else:+ elif config.renderer == RendererType.CAIRO:return np.append(np.cos(angle / 2), np.sin(angle / 2) * normalize(axis))diff --git a/tests/module/mobject/mobject/test_set_attr.py b/tests/module/mobject/mobject/test_set_attr.pyindex 2e483062e..f9cdd40fe 100644--- a/tests/module/mobject/mobject/test_set_attr.py+++ b/tests/module/mobject/mobject/test_set_attr.py@@ -2,13 +2,13 @@ from __future__ import annotationsimport numpy as np-from manim import config+from manim import RendererType, configfrom manim.constants import RIGHTfrom manim.mobject.geometry.polygram import Squaredef test_Data():- config.renderer = "opengl"+ config.renderer = RendererType.OPENGLa = Square().move_to(RIGHT)data_bb = a.data["bounding_box"]np.testing.assert_array_equal(@@ -39,4 +39,6 @@ def test_Data():)np.testing.assert_array_equal(a.bounding_box, data_bb)- config.renderer = "cairo" # needs to be here or else the following cairo tests fail+ config.renderer = (+ RendererType.CAIRO+ ) # needs to be here or else the following cairo tests fail