Skip to content

Use cooperative initialization for axes and split-screen cameras - #5071

Open
GreedyC wants to merge 1 commit into
ManimCommunity:mainfrom
GreedyC:codex/manim-5067-cooperative-init
Open

GreedyC wants to merge 1 commit into
ManimCommunity:mainfrom
GreedyC:codex/manim-5067-cooperative-init

Conversation

@GreedyC

@GreedyC GreedyC commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

Overview: What does this pull request change?

Uses cooperative initialization for Axes and SplitScreenCamera, and updates the LinearTransformationScene and ZoomedScene subclass examples to use super().

Refs #5067. This covers the axes/camera portion, not the whole issue. Arrow-tip initialization is already being addressed in #4959; this PR leaves tips.py and those tests untouched.

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

Axes currently initializes VGroup and CoordinateSystem explicitly. Replacing those calls alone would not work: CoordinateSystem comes after Mobject in the MRO, and Mobject does not forward initialization. This change places CoordinateSystem before VGroup and lets it consume its coordinate options and forward the remaining arguments. Mobject initialization still happens before the coordinate attributes are set, preserving the existing order. A regression checks that a coordinate-system subclass in the MRO is initialized once, with both Cairo and OpenGL.

SplitScreenCamera calls Camera before OldMultiCamera has created shifted_cameras. The overridden init_background() then accesses that missing field. It now initializes its parent once and registers the resized cameras through a small private helper, without repeating initialization or losing the supplied camera options. For odd pixel widths, the right camera gets the remaining width. Tests check initialization count, dimensions and composed pixel arrays.

Links to added or changed documentation pages

The CoordinateSystem docstring explains cooperative base ordering. The existing LinearTransformationScene and ZoomedScene subclass examples now use super().

Further Information and Comments

Local verification on macOS / Python 3.13.14:

  • Full suite: 1,516 passed, 2 skipped, 5 xfailed, 2 xpassed; zero failures. Unchanged upstream: 1,512 passed, with the same skips/xfails/xpasses and zero failures.
  • All four new regression cases fail against unchanged upstream and pass with the patch.
  • Related coordinate-system/OpenGL/camera tests: 29 passed, 1 existing skip; changed-module doctests: 3 passed.
  • Applicable pre-commit checks pass, including Ruff, codespell and mypy; git diff --check passes.

The first full runs exposed a missing Manim console entry point on PATH. After correcting PATH, both baseline and patched suites were rerun successfully. No existing test expectations or control images were changed. A full Sphinx build was not run; hosted checks are separate from these local results.

Codex assisted with the implementation, tests, local checks and this description.

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

@nikolajmunk

Copy link
Copy Markdown
Contributor

Thank you for this contribution, this mostly looks right. Thanks for flipping the MRO of Axes. I suspect that we might be getting rid of some of the affected scenes in a future release, but it's nice that things work properly until then!

Your PR introduces two new tests, test_axes_initializes_coordinate_system_subclass and test_split_screen_camera_initializes_parent_once. Would you mind explaining what these tests do and why they're testing for something relevant? Preferably with as little assistance from your AI agent as possible, it would be nice to hear from you yourself 😊

@nikolajmunk

Copy link
Copy Markdown
Contributor

Also, I note that the CI tools failed on building the docs. I'm not sure whether or not this is something caused by your code, but if you get the time, I'd appreciate if you tried building the docs locally to see if you get the same error.

@GreedyC

GreedyC commented Oct 19, 2026

Copy link
Copy Markdown
Contributor Author

AI-assisted follow-up on the local documentation build request:

The normal local Sphinx build stops earlier because this machine has no latex executable. I then used a small Sphinx page with the real manim directive to isolate image rendering:

.. manim:: ImageSmoke
    :save_last_frame:

    import numpy as np

    class ImageSmoke(Scene):
        def construct(self):
            self.add(ImageMobject(np.full((2, 2, 4), 255, dtype=np.uint8)))

With Python 3.13.14, Sphinx 8.2.3 and Pillow 13.0.0, this fails on both the PR head (ee846114) and upstream main (b31c77e1) at Camera.display_image_mobject, line 1128:

Image.fromarray(np.zeros((self.pixel_height, self.pixel_width)), mode="RGBA")
# ValueError: Invalid mode for data type

The same Sphinx rendering example succeeds on the PR head with Pillow 12.3.0. This reproduces the image-rendering failure independently of the initializer changes. The full HTML build with -t skip-manim also completes locally, with warnings, but that skips scene rendering and is not a full rendering-build pass.

No Pillow or camera changes have been added to this PR. The request for a personal explanation of the two tests is still awaiting the author's own reply.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants