Skip to content

fix: AnimationGroup with negative z_index #4268

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

These changes initially caused some issues with graphical tests. In a few cases, there were minor pixel differences, so I slightly changed some of the tests to account for this

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

@henrikmidtiby
Copy link
Contributor

Comments from a regular developer here.

I have tested the PR and it does indeed fix the problems reported in issue #3334 and #3914.

The code that have been removed calls the method get_moving_and_static_mobjects to optimize rendering speed.
I suspect that the real issue is in the method get_moving_and_static_mobjects, which causes the objects in the animation (with negative z-index) to be considered a static object.

It would be nice to see if this change impacts the rendering speed for scenes with many static objects.
This page might be helpful for measuring code speed: https://docs.manim.community/en/latest/contributing/performance.html

@henrikmidtiby
Copy link
Contributor

Status of the PR as I see it right now.

  • The original issue is fixed (good)
  • The performance optimization is back in place (good)
  • 38 of the unit tests fail (bad)

The test failures occur in these tests

FAILED tests/test_graphical_units/test_brace.py::test_brace_sharpness - AssertionError: 
FAILED tests/test_graphical_units/test_creation.py::test_bring_to_back_introducer - AssertionError: 
FAILED tests/test_graphical_units/test_creation.py::test_z_index_introducer - AssertionError: 
FAILED tests/test_graphical_units/test_brace.py::test_braceTip - AssertionError: 
FAILED tests/test_graphical_units/test_img_and_svg.py::test_Line - AssertionError: 
FAILED tests/test_graphical_units/test_indication.py::test_Circumscribe - AssertionError: 
FAILED tests/test_graphical_units/test_img_and_svg.py::test_CubicPath - AssertionError: 
FAILED tests/test_graphical_units/test_img_and_svg.py::test_CubicAndLineto - AssertionError: 
FAILED tests/test_graphical_units/test_img_and_svg.py::test_Rhomboid - AssertionError: 
FAILED tests/test_graphical_units/test_img_and_svg.py::test_Inheritance - AssertionError: 
FAILED tests/test_graphical_units/test_img_and_svg.py::test_MultiPartPath - AssertionError: 
FAILED tests/test_graphical_units/test_img_and_svg.py::test_QuadraticPath - AssertionError: 
FAILED tests/test_graphical_units/test_img_and_svg.py::test_SmoothCurves - AssertionError: 
FAILED tests/test_graphical_units/test_img_and_svg.py::test_UseTagInheritance - AssertionError: 
FAILED tests/test_graphical_units/test_img_and_svg.py::test_HalfEllipse - AssertionError: 
FAILED tests/test_graphical_units/test_img_and_svg.py::test_Heart - AssertionError: 
FAILED tests/test_graphical_units/test_img_and_svg.py::test_Arcs01 - AssertionError: 
FAILED tests/test_graphical_units/test_img_and_svg.py::test_Arcs02 - AssertionError: 
FAILED tests/test_graphical_units/test_img_and_svg.py::test_WeightSVG - AssertionError: 
FAILED tests/test_graphical_units/test_img_and_svg.py::test_BrachistochroneCurve - AssertionError: 
FAILED tests/test_graphical_units/test_img_and_svg.py::test_Penrose - AssertionError: 
FAILED tests/test_graphical_units/test_transform_matching_parts.py::test_TransformMatchingDisplaysCorrect - AssertionError: 
FAILED tests/test_graphical_units/test_img_and_svg.py::test_ManimLogo - AssertionError: 
FAILED tests/test_graphical_units/test_img_and_svg.py::test_UKFlag - AssertionError: 
FAILED tests/test_graphical_units/test_img_and_svg.py::test_SingleUSState - AssertionError: 
FAILED tests/test_graphical_units/test_updaters.py::test_LastFrameWhenCleared - AssertionError: 
FAILED tests/test_graphical_units/test_transform.py::test_ReplacementTransform - AssertionError: 
FAILED tests/test_graphical_units/test_img_and_svg.py::test_ContiguousUSMap - AssertionError: 
FAILED tests/test_graphical_units/test_img_and_svg.py::test_PixelizedText - AssertionError: 
FAILED tests/test_graphical_units/test_img_and_svg.py::test_VideoIcon - AssertionError: 
FAILED tests/test_graphical_units/test_img_and_svg.py::test_MultipleTransform - AssertionError: 
FAILED tests/test_graphical_units/test_img_and_svg.py::test_MatrixTransform - AssertionError: 
FAILED tests/test_graphical_units/test_img_and_svg.py::test_ScaleTransform - AssertionError: 
FAILED tests/test_graphical_units/test_vector_scene.py::test_vector_to_coords - AssertionError: 
FAILED tests/test_graphical_units/test_img_and_svg.py::test_TranslateTransform - AssertionError: 
FAILED tests/test_graphical_units/test_img_and_svg.py::test_SkewXTransform - AssertionError: 
FAILED tests/test_graphical_units/test_img_and_svg.py::test_SkewYTransform - AssertionError: 
FAILED tests/test_graphical_units/test_img_and_svg.py::test_RotateTransform - AssertionError: 

All tests fail the same way, with a message like this.

E           AssertionError: 
E           Not equal to tolerance rtol=1e-07, atol=1.01
E           Frame no -1. You can use --show_diff to visually show the difference.
E           Mismatched elements: 747 / 1639680 (0.0456%)
E           Max absolute difference among violations: 64
E           Max relative difference among violations: 1.

To see how the rendered scenes differ from the expected output test tests were run with this command

uv run pytest --durations-min=2 --show_diff

This generated a number of pdf files showing the actual output, the expected output and the difference.
It seems like the issue is related to how the edges of the object appears.
I have attached a few of these files.
UKFlag-diff.pdf
Rhomboid-diff.pdf

@Merzlikin-Matvey
Copy link
Author

Thank you for the feedback. Now I have some problems with tests. I will try to fix them

@github-project-automation github-project-automation bot moved this from 🆕 New to ❌ Rejected in Dev Board Jun 6, 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.

2 participants