Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Removed Container ABC (#1652)

Jason Villanueva6f13981f23d0
diff --git a/docs/source/contributing/testing.rst b/docs/source/contributing/testing.rst
index cc24c99c6..4a4e56a09 100644
--- a/docs/source/contributing/testing.rst
+++ b/docs/source/contributing/testing.rst
@@ -87,7 +87,6 @@ The ``manim/tests`` directory looks like this:
├── __init__.py
├── test_camera.py
├── test_config.py
- ├── test_container.py
├── test_copy.py
├── test_vectorized_mobject.py
├── test_graphical_units
diff --git a/docs/source/reference.rst b/docs/source/reference.rst
index 68d1f52ae..adbef2ac3 100644
--- a/docs/source/reference.rst
+++ b/docs/source/reference.rst
@@ -229,4 +229,3 @@ Other modules
:toctree: reference
constants
- container
diff --git a/manim/__init__.py b/manim/__init__.py
index 903fb922b..d9be9319f 100644
--- a/manim/__init__.py
+++ b/manim/__init__.py
@@ -51,7 +51,6 @@ from .camera.moving_camera import *
from .camera.multi_camera import *
from .camera.three_d_camera import *
from .constants import *
-from .container import *
from .mobject.changing import *
from .mobject.coordinate_systems import *
from .mobject.frame import *
diff --git a/manim/container.py b/manim/container.py
deleted file mode 100644
index 69764216a..000000000
--- a/manim/container.py
+++ /dev/null
@@ -1,52 +0,0 @@
-"""
-Abstract base class for several objects used by manim. In particular, both
-:class:`~.Scene` and :class:`~.Mobject` inherit from Container.
-"""
-
-
-__all__ = ["Container"]
-
-
-from abc import ABC, abstractmethod
-
-from . import logger
-
-
-class Container(ABC):
- """Abstract base class for several objects used by manim. In particular, both
- :class:`~.Scene` and :class:`~.Mobject` inherit from Container.
-
- Parameters
- ----------
- kwargs : Any
-
- """
-
- def __init__(self, **kwargs):
- if kwargs:
- logger.debug("Container received extra kwargs: %s", kwargs)
-
- if hasattr(self, "CONFIG"):
- logger.error(
- "CONFIG has been removed from ManimCommunity. Please use keyword arguments instead."
- )
-
- @abstractmethod
- def add(self, *items):
- """Abstract method to add items to Container.
-
- Parameters
- ----------
- items : Any
- Objects to be added.
- """
-
- @abstractmethod
- def remove(self, *items):
- """Abstract method to remove items from Container.
-
- Parameters
- ----------
- items : Any
- Objects to be added.
- """
diff --git a/manim/mobject/geometry.py b/manim/mobject/geometry.py
index 7d1912357..878025cbb 100644
--- a/manim/mobject/geometry.py
+++ b/manim/mobject/geometry.py
@@ -2431,9 +2431,8 @@ class ArrowTip(VMobject, metaclass=ConvertToOpenGL):
.. manim:: CustomTipExample
>>> class MyCustomArrowTip(ArrowTip, RegularPolygon):
- ... def __init__(self, **kwargs):
+ ... def __init__(self, length=0.35, **kwargs):
... RegularPolygon.__init__(self, n=5, **kwargs)
- ... length = 0.35
... self.width = length
... self.stretch_to_fit_height(length)
>>> arr = Arrow(np.array([-2, -2, 0]), np.array([2, 2, 0]),
diff --git a/manim/mobject/mobject.py b/manim/mobject/mobject.py
index fbe8fe552..3092ef9f9 100644
--- a/manim/mobject/mobject.py
+++ b/manim/mobject/mobject.py
@@ -33,7 +33,6 @@ from colour import Color
from .. import config
from ..constants import *
-from ..container import Container
from ..utils.color import (
BLACK,
WHITE,
@@ -63,7 +62,7 @@ if TYPE_CHECKING:
from ..animation.animation import Animation
-class Mobject(Container):
+class Mobject:
"""Mathematical Object: base class for objects that can be displayed on screen.
There is a compatibility layer that allows for
@@ -94,7 +93,7 @@ class Mobject(Container):
] = {}
cls._add_intrinsic_animation_overrides()
- def __init__(self, color=WHITE, name=None, dim=3, target=None, z_index=0, **kwargs):
+ def __init__(self, color=WHITE, name=None, dim=3, target=None, z_index=0):
self.color = Color(color) if color else None
self.name = self.__class__.__name__ if name is None else name
self.dim = dim
@@ -122,8 +121,6 @@ class Mobject(Container):
self.init_gl_points()
self.init_gl_colors()
- Container.__init__(self, **kwargs)
-
@classmethod
def animation_override_for(
cls, animation_class: Type["Animation"]
diff --git a/manim/mobject/number_line.py b/manim/mobject/number_line.py
index 396a4b90c..094c67607 100644
--- a/manim/mobject/number_line.py
+++ b/manim/mobject/number_line.py
@@ -124,8 +124,7 @@ class NumberLine(Line):
if decimal_number_config is None:
decimal_number_config = {
"num_decimal_places": self.decimal_places_from_step(),
- "font_size": 24,
- } # font_size does nothing
+ }
self.length = length
self.unit_size = unit_size
@@ -267,7 +266,6 @@ class NumberLine(Line):
buff = self.line_to_number_buff
num_mob = DecimalNumber(x, **number_config)
- # font_size does not exist yet in decimal number
num_mob.scale(self.number_scale_value)
num_mob.next_to(self.number_to_point(x), direction=direction, buff=buff)
@@ -284,15 +282,13 @@ class NumberLine(Line):
def get_labels(self):
return self.get_number_mobjects()
- def add_numbers(self, x_values=None, excluding=None, font_size=24, **kwargs):
+ def add_numbers(self, x_values=None, excluding=None, **kwargs):
if x_values is None:
x_values = self.get_tick_range()
if excluding is None:
excluding = self.numbers_to_exclude
- kwargs["font_size"] = font_size
-
numbers = VGroup()
for x in x_values:
if x in excluding:
diff --git a/manim/mobject/svg/svg_mobject.py b/manim/mobject/svg/svg_mobject.py
index cd1c8561e..754decefd 100644
--- a/manim/mobject/svg/svg_mobject.py
+++ b/manim/mobject/svg/svg_mobject.py
@@ -74,6 +74,7 @@ class SVGMobject(VMobject, metaclass=ConvertToOpenGL):
fill_opacity=1.0,
should_subdivide_sharp_curves=False,
should_remove_null_curves=False,
+ color=None,
**kwargs,
):
self.def_map = {}
@@ -81,14 +82,17 @@ class SVGMobject(VMobject, metaclass=ConvertToOpenGL):
self.ensure_valid_file()
self.should_center = should_center
self.unpack_groups = unpack_groups
- self.path_string_config = {
- "should_subdivide_sharp_curves": should_subdivide_sharp_curves,
- "should_remove_null_curves": should_remove_null_curves,
- }
- # Force color to default to None if not set
- if "color" not in kwargs:
- kwargs["color"] = None
- super().__init__(fill_opacity=fill_opacity, stroke_width=stroke_width, **kwargs)
+ self.path_string_config = (
+ {
+ "should_subdivide_sharp_curves": should_subdivide_sharp_curves,
+ "should_remove_null_curves": should_remove_null_curves,
+ }
+ if config.renderer == "opengl"
+ else {}
+ )
+ super().__init__(
+ color=color, fill_opacity=fill_opacity, stroke_width=stroke_width, **kwargs
+ )
self.move_into_position(width, height)
def ensure_valid_file(self):
diff --git a/manim/mobject/svg/text_mobject.py b/manim/mobject/svg/text_mobject.py
index a6b30f1d5..3875f8841 100644
--- a/manim/mobject/svg/text_mobject.py
+++ b/manim/mobject/svg/text_mobject.py
@@ -136,7 +136,7 @@ class Paragraph(VGroup):
def __init__(self, *text, line_spacing=-1, alignment=None, **config):
self.line_spacing = line_spacing
self.alignment = alignment
- VGroup.__init__(self, **config)
+ VGroup.__init__(self)
lines_str = "\n".join(list(text))
self.lines_text = Text(lines_str, line_spacing=line_spacing, **config)
@@ -165,9 +165,7 @@ class Paragraph(VGroup):
self.lines[1].extend(
[self.alignment for _ in range(chars_lines_text_list.__len__())]
)
- self.get_group_class().__init__(
- self, *[self.lines[0][i] for i in range(self.lines[0].__len__())], **config
- )
+ self.add(*self.lines[0])
self.move_to(np.array([0, 0, 0]))
if self.alignment:
self.set_all_lines_alignments(self.alignment)
diff --git a/manim/mobject/three_dimensions.py b/manim/mobject/three_dimensions.py
index 5b944f654..5bf4e6a3c 100644
--- a/manim/mobject/three_dimensions.py
+++ b/manim/mobject/three_dimensions.py
@@ -691,13 +691,14 @@ class Arrow3D(Line3D):
color=WHITE,
**kwargs
):
- Line3D.__init__(self, start=start, end=end, **kwargs)
+ Line3D.__init__(
+ self, start=start, end=end, thickness=thickness, color=color, **kwargs
+ )
self.length = np.linalg.norm(self.vect)
self.set_start_and_end_attrs(
self.start,
self.end - height * self.direction,
- thickness=thickness,
**kwargs,
)
diff --git a/manim/mobject/types/point_cloud_mobject.py b/manim/mobject/types/point_cloud_mobject.py
index 8994b8110..3ca8a653b 100644
--- a/manim/mobject/types/point_cloud_mobject.py
+++ b/manim/mobject/types/point_cloud_mobject.py
@@ -269,12 +269,7 @@ class PointCloudDot(Mobject1D):
):
self.radius = radius
Mobject1D.__init__(
- self,
- radius=radius,
- stroke_width=stroke_width,
- density=density,
- color=color,
- **kwargs
+ self, stroke_width=stroke_width, density=density, color=color, **kwargs
)
self.shift(center)
diff --git a/manim/mobject/types/vectorized_mobject.py b/manim/mobject/types/vectorized_mobject.py
index 4b775ce6d..9b32f1f89 100644
--- a/manim/mobject/types/vectorized_mobject.py
+++ b/manim/mobject/types/vectorized_mobject.py
@@ -2006,7 +2006,7 @@ class CurvesAsSubmobjects(VGroup):
class LineGradientExample(Scene):
def construct(self):
- curve = ParametricFunction(lambda t: [t, np.sin(t), 0], t_min = -PI, t_max=PI,stroke_width=10)
+ curve = ParametricFunction(lambda t: [t, np.sin(t), 0], t_range=[-PI, PI, 0.01], stroke_width=10)
new_curve = CurvesAsSubmobjects(curve)
new_curve.set_color_by_gradient(BLUE, RED)
self.add(new_curve.shift(UP), curve)
diff --git a/manim/scene/scene.py b/manim/scene/scene.py
index 1b7d3a0ce..b49b580dd 100644
--- a/manim/scene/scene.py
+++ b/manim/scene/scene.py
@@ -13,7 +13,6 @@ import sys
import threading
import time
import types
-import warnings
from queue import Queue
try:
@@ -31,7 +30,6 @@ from .. import config, logger
from ..animation.animation import Animation, Wait, prepare_animation
from ..camera.camera import Camera
from ..constants import *
-from ..container import Container
from ..gui.gui import configure_pygui
from ..mobject.mobject import Mobject, _AnimationBuilder
from ..mobject.opengl_mobject import OpenGLMobject, OpenGLPoint
@@ -43,7 +41,6 @@ from ..utils.family import extract_mobject_family_members
from ..utils.family_ops import restructure_list_to_exclude_certain_family_members
from ..utils.file_ops import open_media_file
from ..utils.iterables import list_difference_update, list_update
-from ..utils.space_ops import rotate_vector
class RerunSceneHandler(FileSystemEventHandler):
@@ -57,7 +54,7 @@ class RerunSceneHandler(FileSystemEventHandler):
self.queue.put(("rerun_file", [], {}))
-class Scene(Container):
+class Scene:
"""A Scene is the canvas of your animation.
The primary role of :class:`Scene` is to provide the user with tools to manage
@@ -95,11 +92,12 @@ class Scene(Container):
camera_class=Camera,
always_update_mobjects=False,
random_seed=None,
- **kwargs,
+ skip_animations=False,
):
self.camera_class = camera_class
self.always_update_mobjects = always_update_mobjects
self.random_seed = random_seed
+ self.skip_animations = skip_animations
self.animations = None
self.stop_condition = None
@@ -123,7 +121,7 @@ class Scene(Container):
if renderer is None:
self.renderer = CairoRenderer(
camera_class=self.camera_class,
- skip_animations=kwargs.get("skip_animations", False),
+ skip_animations=self.skip_animations,
)
else:
self.renderer = renderer
@@ -136,8 +134,6 @@ class Scene(Container):
random.seed(self.random_seed)
np.random.seed(self.random_seed)
- Container.__init__(self, **kwargs)
-
@property
def camera(self):
return self.renderer.camera
diff --git a/manim/utils/rate_functions.py b/manim/utils/rate_functions.py
index 3b03f13e6..e0c44d436 100644
--- a/manim/utils/rate_functions.py
+++ b/manim/utils/rate_functions.py
@@ -20,8 +20,7 @@ for the non-standard ones
plot = (
ParametricFunction(
lambda x: [x, rate_func(x), 0],
- t_min=0,
- t_max=1,
+ t_range=[0, 1, .01],
use_smoothing=False,
color=YELLOW,
)
diff --git a/tests/test_container.py b/tests/test_container.py
deleted file mode 100644
index d88534ad0..000000000
--- a/tests/test_container.py
+++ /dev/null
@@ -1,79 +0,0 @@
-import pytest
-
-from manim import Container, Mobject, Scene, tempconfig
-
-
-def test_ABC():
- """Test that the Container class cannot be instantiated."""
- with pytest.raises(TypeError):
- Container()
-
- # The following should work without raising exceptions
- Mobject()
-
- with tempconfig({"dry_run": True}):
- Scene()
-
-
-def container_add(obj, get_submobjects):
- """Call this function with a Container instance to test its add() method."""
- # check that obj.submobjects is updated correctly
- assert len(get_submobjects()) == 0
- obj.add(Mobject())
- assert len(get_submobjects()) == 1
- obj.add(*(Mobject() for _ in range(10)))
- assert len(get_submobjects()) == 11
-
- # check that adding a mobject twice does not actually add it twice
- repeated = Mobject()
- obj.add(repeated)
- assert len(get_submobjects()) == 12
- obj.add(repeated)
- assert len(get_submobjects()) == 12
-
- # check that Container.add() returns the Mobject (for chained calls)
- assert obj.add(Mobject()) is obj
-
-
-def container_remove(obj, get_submobjects):
- """Call this function with a Container instance to test its remove() method."""
- to_remove = Mobject()
- obj.add(to_remove)
- obj.add(*(Mobject() for _ in range(10)))
- assert len(get_submobjects()) == 11
- obj.remove(to_remove)
- assert len(get_submobjects()) == 10
- obj.remove(to_remove)
- assert len(get_submobjects()) == 10
-
- # check that Container.remove() returns the instance (for chained calls)
- assert obj.add(Mobject()) is obj
-
-
-def test_mobject_add():
- """Test Mobject.add()."""
- obj = Mobject()
- container_add(obj, lambda: obj.submobjects)
-
- # a Mobject cannot contain itself
- with pytest.raises(ValueError):
- obj.add(obj)
-
- # can only add Mobjects
- with pytest.raises(TypeError):
- obj.add("foo")
-
-
-def test_mobject_remove():
- """Test Mobject.remove()."""
- obj = Mobject()
- container_remove(obj, lambda: obj.submobjects)
-
-
-def test_scene_add_remove():
- """Test Scene.add() and Scene.remove()."""
- with tempconfig({"dry_run": True}):
- scene = Scene()
- container_add(scene, lambda: scene.mobjects)
- scene = Scene()
- container_remove(scene, lambda: scene.mobjects)
diff --git a/tests/test_graphical_units/test_graphscene.py b/tests/test_graphical_units/test_graphscene.py
index e34d14bdd..4e7f9ea8c 100644
--- a/tests/test_graphical_units/test_graphscene.py
+++ b/tests/test_graphical_units/test_graphscene.py
@@ -11,7 +11,6 @@ class PlotFunctions(GraphScene):
GraphScene.__init__(
self,
graph_origin=ORIGIN,
- function_color=RED,
axes_color=GREEN,
x_labeled_nums=range(-10, 12, 2),
**kwargs
diff --git a/tests/test_mobject.py b/tests/test_mobject.py
new file mode 100644
index 000000000..5a1bdf7e6
--- /dev/null
+++ b/tests/test_mobject.py
@@ -0,0 +1,49 @@
+import pytest
+
+from manim import Mobject
+
+
+def test_mobject_add():
+ """Test Mobject.add()."""
+ """Call this function with a Container instance to test its add() method."""
+ # check that obj.submobjects is updated correctly
+ obj = Mobject()
+ assert len(obj.submobjects) == 0
+ obj.add(Mobject())
+ assert len(obj.submobjects) == 1
+ obj.add(*(Mobject() for _ in range(10)))
+ assert len(obj.submobjects) == 11
+
+ # check that adding a mobject twice does not actually add it twice
+ repeated = Mobject()
+ obj.add(repeated)
+ assert len(obj.submobjects) == 12
+ obj.add(repeated)
+ assert len(obj.submobjects) == 12
+
+ # check that Mobject.add() returns the Mobject (for chained calls)
+ assert obj.add(Mobject()) is obj
+ obj = Mobject()
+
+ # a Mobject cannot contain itself
+ with pytest.raises(ValueError):
+ obj.add(obj)
+
+ # can only add Mobjects
+ with pytest.raises(TypeError):
+ obj.add("foo")
+
+
+def test_mobject_remove():
+ """Test Mobject.remove()."""
+ obj = Mobject()
+ to_remove = Mobject()
+ obj.add(to_remove)
+ obj.add(*(Mobject() for _ in range(10)))
+ assert len(obj.submobjects) == 11
+ obj.remove(to_remove)
+ assert len(obj.submobjects) == 10
+ obj.remove(to_remove)
+ assert len(obj.submobjects) == 10
+
+ assert obj.remove(Mobject()) is obj
diff --git a/tests/test_number_line.py b/tests/test_number_line.py
index f633850d1..3c7786875 100644
--- a/tests/test_number_line.py
+++ b/tests/test_number_line.py
@@ -7,7 +7,7 @@ def test_unit_vector():
"""Check if the magnitude of unit vector along
the NumberLine is equal to its unit_size."""
axis1 = NumberLine(unit_size=0.4)
- axis2 = NumberLine(width=12, x_min=-2, x_max=5)
+ axis2 = NumberLine(x_range=[-2, 5], length=12)
for axis in (axis1, axis2):
assert np.linalg.norm(axis.get_unit_vector()) == axis.unit_size
diff --git a/tests/test_scene.py b/tests/test_scene.py
new file mode 100644
index 000000000..3c34a7915
--- /dev/null
+++ b/tests/test_scene.py
@@ -0,0 +1,35 @@
+import pytest
+
+from manim import Mobject, Scene, tempconfig
+
+
+def test_scene_add_remove():
+ with tempconfig({"dry_run": True}):
+ scene = Scene()
+ assert len(scene.mobjects) == 0
+ scene.add(Mobject())
+ assert len(scene.mobjects) == 1
+ scene.add(*(Mobject() for _ in range(10)))
+ assert len(scene.mobjects) == 11
+
+ # Check that adding a mobject twice does not actually add it twice
+ repeated = Mobject()
+ scene.add(repeated)
+ assert len(scene.mobjects) == 12
+ scene.add(repeated)
+ assert len(scene.mobjects) == 12
+
+ # Check that Scene.add() returns the Scene (for chained calls)
+ assert scene.add(Mobject()) is scene
+ to_remove = Mobject()
+ scene = Scene()
+ scene.add(to_remove)
+ scene.add(*(Mobject() for _ in range(10)))
+ assert len(scene.mobjects) == 11
+ scene.remove(to_remove)
+ assert len(scene.mobjects) == 10
+ scene.remove(to_remove)
+ assert len(scene.mobjects) == 10
+
+ # Check that Scene.remove() returns the instance (for chained calls)
+ assert scene.add(Mobject()) is scene