manim icon indicating copy to clipboard operation
manim copied to clipboard

Mobject.split() behaves differently between Cairo and OpenGL

Open nikolajmunk opened this issue 3 months ago • 2 comments

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

nikolajmunk avatar Aug 11 '26 11:08 nikolajmunk

Did some digging; it seems like the "include self if it has points" behavior was removed from ManimGL in 2021 (commit and PR).

nikolajmunk avatar Aug 11 '26 15:08 nikolajmunk

Would a focused contribution clarifying the split() contract be useful during the current refactor? I would first add cases for objects with points, children, and both, across Cairo and OpenGL. Before changing either implementation, could you confirm whether split() should include self and whether it should return a copy? I can then keep any fix and documentation limited to that agreed behavior. Is this already covered by ongoing refactor work?

Src-Bhavesh avatar Oct 08 '26 08:10 Src-Bhavesh