Skip to content

fix: AnimationGroup with negative z_index #4277

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 69 commits into from

Conversation

Merzlikin-Matvey
Copy link

Overview: What does this pull request change?

Fixes an AnimationGroup behaviour with negative z_index Mobjects. More about this problem you can see in these issues:
#3334 and #3914

Motivation and Explanation: Why and how do your changes improve the library?

Mobjects with negative z_index have problems with playing in animations. This PR fixes it

Links to added or changed documentation pages

There are no changes to the documentation

Further Information and Comments

I had already opened a pull request, but I decided to close it due to many issues with the previous solution. I have taken all the shortcomings, now there are no performance or graphical test issues.

Reviewer Checklist

  • The PR title is descriptive enough for the changelog, and the PR is labeled correctly
  • If applicable: newly added non-private functions and classes have a docstring including a short summary and a PARAMETERS section
  • If applicable: newly added functions and classes are tested

Merzlikin-Matvey and others added 25 commits June 8, 2025 19:46
…Animation`, `ShowPartial`, `Create`, `ShowPassingFlash`, and `DrawBorderThenFill` (ManimCommunity#4214)

Co-authored-by: Francisco Manríquez Novoa <[email protected]>
Co-authored-by: Francisco Manríquez <[email protected]>
…ically (ManimCommunity#4265)

* add a random generator to hold the seed for random generation

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* add DOCSTRING for new class RandomColorGenerator

* fix RandomColorGenerator doctest

* introduce the sample colors param in RandomColorGenerator

* Update docstrings to include sample_colors param for RandomColorGenerator

* fix cyclic import issues

* fix indentations for code blocks

* docstring formatting changes

* removed performance warning
added class method

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Benjamin Hackl <[email protected]>
* Fixed mypy errors in several files with a few errors in each file.

* Fixed a few easy mypy errors.

* Fix mypy issues in animation/changing.py

* Handled mypy issues in _config/cli_colors.py

* Handled mypy issues in mobject/logo.py

* Handling mypy errors in fading.py

* Removed a default parameter (scene = None) in the method clean_up_from_scene in the class FadeOut

* Handled mypy errors in graphing/scale.py

* Handled a few mypy errors in updaters/update.py

* Handled mypy errors in three_d_utils.py

* Updated mypy.ini to check more files

* Avoid a circular import loop.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update manim/animation/changing.py

Co-authored-by: Francisco Manríquez Novoa <[email protected]>

* Update manim/animation/changing.py

Co-authored-by: Francisco Manríquez Novoa <[email protected]>

* Update manim/animation/changing.py

Co-authored-by: Francisco Manríquez Novoa <[email protected]>

* Update manim/mobject/logo.py

Co-authored-by: Francisco Manríquez Novoa <[email protected]>

* Update manim/animation/changing.py

Co-authored-by: Francisco Manríquez Novoa <[email protected]>

* Update manim/animation/changing.py

Co-authored-by: Francisco Manríquez Novoa <[email protected]>

* Update manim/animation/changing.py

Cleaner way to indicate the float type

Co-authored-by: Francisco Manríquez Novoa <[email protected]>

* Update manim/animation/changing.py

Co-authored-by: Francisco Manríquez Novoa <[email protected]>

* Updated the type annotations of MoveAlongPath and ChangingDecimal

* Suggestions from review by chopan50

* Fix missing import.

* Update mypy.ini

Co-authored-by: Francisco Manríquez Novoa <[email protected]>

* Update mypy.ini

Co-authored-by: Francisco Manríquez Novoa <[email protected]>

* Update mypy.ini

Co-authored-by: Francisco Manríquez Novoa <[email protected]>

* Update mypy.ini

Co-authored-by: Francisco Manríquez Novoa <[email protected]>

* Updated mypy.ini

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Francisco Manríquez Novoa <[email protected]>
…es/advanced_tex_fonts.py` (ManimCommunity#4305)

Co-authored-by: Louis Pierre Jean Gerard <[email protected]>
Co-authored-by: Francisco Manríquez Novoa <[email protected]>
…nfiguration file (ManimCommunity#4306)

* Explicitly mention all files where type errors are ignored in mypy.ini

* Minor adjustments to mypy.ini suggested by chopan50
…Community#4260)

* Stop ignoring errors from manim/scene.py

Count: 307 errors

Type annotations on scene/vector_space_scene.py

Add type annotations to scene/vector_space_scene.py

Mypy count: 210

Reverting two changes that triggers an error in the automatic testing.

Further work on type hinting.

Avoid forwarding positional arguments from Arrow to Line in the constructor.

Revert "Avoid forwarding positional arguments from Arrow to Line in the constructor."

This reverts commit 80ae857.

Removed several type ignore statements and addressed comments from JasonGrace2282

Revert "Activate mypy check of mobject.geometry.*"

This reverts commit d477c9a.

Revert "Removed several type ignore statements and addressed comments from JasonGrace2282"

This reverts commit 07bbe3f.

Added type annotations to zoomed_scene.py

Error count: 308 -> 303

Adding type annotations to all methods in vector_space_scene.py

Error count: 303 -> 272

Get rid of no-untyped-call errors from my in the vector_space_scene.py file

Error count: 272 -> 343

Handle type issues related to ManimColor in vector_space_scene.py

Handle var-annotated issues in vector_space_scene.py

Error count: 332 -> 330

Handling has-type type errors in vector_space_scene.py

Error count: 330 -> 285

Handled name-defined type issues in vector_space_scene.py

Error count: 285 -> 282

Address type issue with calling an untyped method.

Error count: 282 -> 281

Fix some typing issues in transform_mathcing_parts.py

Change stroke_width to float in vector_space_scene.py

Handled a few type errors.

Error count: 267

Handled several typing issues in three_d_scene.py

Error count: 267 -> 248

Dealing with type errors in scene_file_writer.py

Error count: 248 -> 216

Ensured that all methods in scene.py have type declarations.

Error count: 216 -> 225

Handle type issues related to interactivity by asserting that the camera is the OpenGLCamera

Error count: 225 -> 182

Handle type issues in scene.py

Error count: 182 -> 167

Asserting that the renderer or camera is of the proper type to use certain methods.

This is mainly related to interactive elements and the 3D camera used in the ThreeDScene

Error count: 167 -> 143

Avoid cyclic import of dependencies

Error count: 143 -> 143

Handling no-untyped-call type errors in manim/scene/scene.py

Error count: 143 -> 131

Handling assignment type errors in manim/scene/*.py

Error count: 131 -> 121

Handling arg-type type errors in manim/scene/*.py

Error count: 121 -> 116

Handling arg-type type errors in manim/scene/*.py

Error count: 116 -> 112

Fixing various type errors

Error count: 112 -> 102

Fixing various type errors

Error count: 102 -> 97

Fixing various type errors

Error count: 97 -> 90

Some aggressive changes to silence a significant number of type errors.

Error count: 90 -> 66

Commented out an import (IPython) that makes the CI tests fail.

Fix various type errors.

More type annotations.

Code cleanup.

Remove the property mobject_updater_lists of the Scene class as it is not used anywhere.

Handle import-untyped typing issues.

More work on type annotations in manin/scene/.*

More work on scenes/*.py looking at the dependency opengl_renderer.py

More work on types in scenes/*.py

Ignored an old bunch of type ignore statements.

More work on dependencies for scene.py

More work on dependencies for scene.py

* Stop ignoring errors from manim/scene/scene.py

mypy error count: 307

* Adding type annotations to scene.py (C1)

* Adding type annotations to scene.py (C2.1)

* Adding type annotations to scene.py (C2.2)

* Adding type annotations to scene.py (C2.3)

* Adding type annotations to scene.py (C3)

* Adding type annotations to scene.py (C4)

* Adding type annotations to scene.py (C5)

* Adding type annotations to scene.py (C6)

* Adding type annotations to scene.py (C7)

* ...

* Focus on scene.py

* Adding type annotations to vector_space_scene.py

* Added types to opengl_renderer.py

* Added types to cairo_renderer.py

* Fixed the last mypy errors in scene.py - many was ignored

* Fixed the last mypy errors in vector_space_scene.py - many was ignored

* Got rid of the last mypy errors.

* Activate mypy check of vector_space_scene.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Code cleanup.

* Update manim/gui/gui.py

Co-authored-by: Francisco Manríquez Novoa <[email protected]>

* Update manim/renderer/opengl_renderer.py

Co-authored-by: Francisco Manríquez Novoa <[email protected]>

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update manim/scene/scene.py

Co-authored-by: Francisco Manríquez Novoa <[email protected]>

* Update manim/scene/scene.py

Co-authored-by: Francisco Manríquez Novoa <[email protected]>

* Update manim/scene/scene.py

Co-authored-by: Francisco Manríquez Novoa <[email protected]>

* Update manim/scene/scene.py

Co-authored-by: Francisco Manríquez Novoa <[email protected]>

* Update manim/scene/scene.py

Co-authored-by: Francisco Manríquez Novoa <[email protected]>

* Implementing suggestions from chopan50

* Explicitly mention all files where type errors are ignored in mypy.ini

# Conflicts:
#	mypy.ini

* Fix issue

* Updates based on comments from chopan50

* Updates suggested by Chopan50

* Addressed more comments from chopan50

* Addressing more comments from chopan50

* Added docstring to SceneInteractAction

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Differentiate between _AnimationBuilder from an mobject and an opengl_mobject

* Avoid a nameclash with the mobject module and variable name

* Last touches.

* Rolled back some changes related to _AnimationBuilder

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Francisco Manríquez Novoa <[email protected]>
…geMObject and then use it in the set_opacity method (ManimCommunity#4313)

Change from PR 2923 by NicoWeio
* replace setup texlive action

* cleanup in packages to install

* one more
…#4324)

* Update __init__.py

* Update manim/__init__.py

Co-authored-by: Benjamin Hackl <[email protected]>

---------

Co-authored-by: Benjamin Hackl <[email protected]>
…#4322)

* Fixed all mypy errors in polyhedra.py

* Added type annotations to matrix.py
chopan050 and others added 18 commits July 29, 2025 07:57
* Starting to work on type annotations for tex_mobject.py

* More work

* Finished.

* Code cleanup.

* ...

* Removed the ignore errors line in mypy for tex_mobject

* Fix typing of colors

---------

Co-authored-by: Francisco Manríquez Novoa <[email protected]>
* Adding type annotations to three_d_camera.py

* Suggestions from Chopan50

* Removed a comment.

---------

Co-authored-by: Francisco Manríquez Novoa <[email protected]>
…cene.py` (ManimCommunity#4133)

* Add type hints to scene/scene_file_write.py

* Add type hints to scene/scene_file_write.py

* Add type hints to scene/section.py

* Add type hints to scene/zoomed_scene.py

* Add type hints to scene/moving_camera_scene.py

* Fix typing of variable scene_name

* Fix typing

* Fix one more type hint
…imCommunity#4125)

Co-authored-by: Francisco Manríquez Novoa <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
….py` and `opengl_three_dimensions.py` (ManimCommunity#4359)

Co-authored-by: Francisco Manríquez Novoa <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
…as pdf (ManimCommunity#4370)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Francisco Manríquez Novoa <[email protected]>
* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.11.0 → v0.12.7](astral-sh/ruff-pre-commit@v0.11.0...v0.12.7)
- [github.com/pre-commit/mirrors-mypy: v1.15.0 → v1.17.1](pre-commit/mirrors-mypy@v1.15.0...v1.17.1)

* Fix errors

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: JasonGrace2282 <[email protected]>
* exclude check for cyclic imports by CodeQL

* also exclude py/unsafe-cyclic-import
* Fixed surface animations in OpenGL

* bevel cube joints
Copy link
Member

@behackl behackl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution, and sorry for the slow reply!

I've left one comment with a suggestion that might make your fix even a bit more robust, could you take a look (or let us know if you don't want to revisit this issue again)?

Comment on lines 856 to 861
for anim in animations:
if isinstance(anim, AnimationGroup):
for sub in anim.animations:
animation_mobjects.append(sub.mobject)
else:
animation_mobjects.append(anim.mobject)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like (without testing it) there might perhaps still be issues with nested groups?

Could you try whether assembling the animation_mobjects list as a flattened list of all (recursively enumerated) mobjects in the potentially nested groups still has your fix work as intended?

The easiest way to do this is probably by doing something along the lines of

for anim in animations:
    animation_mobjects.extend(anim.mobject.get_family())

Copy link
Author

@Merzlikin-Matvey Merzlikin-Matvey Aug 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for review! I am going to fix it in a few days, but I think I will open another PR for this (because there are problems with merge conflicts etc)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opened new PR. Nested groups now work fine. Please review it
#4389

@behackl behackl closed this Aug 11, 2025
@github-project-automation github-project-automation bot moved this from 🆕 New to ❌ Rejected in Dev Board Aug 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Rejected
Development

Successfully merging this pull request may close these issues.