Skip to content

Mobject.split() behaves differently between Cairo and OpenGL #4932

Description

@nikolajmunk

Description of bug / unexpected behavior

As mentioned in #4914, the behavior of split is different between the two types of Mobject. Here is the implementation of Mobject.split:

def split(self) -> list[Mobject]:
    result: list[Mobject] = [self] if len(self.points) > 0 else []
    return result + self.submobjects

and here is the implementation of OpenGLMobject.split:

def split(self) -> Sequence[OpenGLMobject]:
    return self.submobjects

In short, the Cairo version potentially includes the calling mobject itself if it has any points, and otherwise simply returns a copy of self.submobjects. The OpenGL version never includes the mobject itself and it doesn't copy self.submobjects but simply returns the list itself.

It seems like this difference has existed since OpenGLMobject was introduced in the library, and nothing has broken horribly, so probably this isn't a huge issue in Manim's own source code. It might confuse users who switch from one to the other, though.

Expected behavior

I expect both types of Mobject to behave identically. I don't know which is the correct behavior; the method has no docstring and I haven't been able to find a case where split is called on a mobject which both has 1) points and 2) submobjects, so it isn't clear to me how to find out.

How to reproduce the issue

Code for reproducing the problem
class SplitTest(Scene):
    def construct(self):
        mob = Circle().move_to((-2, 1, 0))
        mob.add(Square().move_to((0, 1, 0)))
        mob.add(Triangle().move_to((2, 1, 0)))
        self.add(mob)
        self.add(mob[:].copy().shift(DOWN * 2))

Additional media files

Images/GIFs

This is the output when rendering with Cairo:
Cairo version

This is the output when rendering with OpenGL:
OpenGL version

Logs

Terminal output
PASTE HERE OR PROVIDE LINK TO https://pastebin.com/ OR SIMILAR

System specifications

System Details
  • OS (with version, e.g., Windows 10 v2004 or macOS 10.15 (Catalina)):
  • RAM:
  • Python version (python/py/python3 --version):
  • Installed modules (provide output from pip list):
PASTE HERE
LaTeX details
  • LaTeX distribution (e.g. TeX Live 2020):
  • Installed LaTeX packages:

Additional comments

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions