ManimCommunity / ManimCommunity/manim

Mobject.split() behaves differently between Cairo and OpenGL

Open
#4,932 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
40.9k
Forks
3.1k
Avg merge
3d 12h
Merged PRs (30d)
25

Description

## 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`:
```py
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`:
```py
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

```py
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

Contributor guide

Open the contributing guide

Research direction

Start by comparing the Mobject.split and OpenGLMobject.split implementations, then run the supplied SplitTest reproduction under Cairo and OpenGL. Determine and document the shared split contract, and verify that both implementations return equivalent results for mobjects with points and submobjects.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
computer-graphics
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.