Skip to content
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

Allowing Swap to accept Group and VGroup and add Example #4211

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

irvanalhaq9
Copy link
Contributor

@irvanalhaq9 irvanalhaq9 commented Apr 3, 2025

Overview: What does this pull request change?

Fix #4210

This PR modifies CyclicReplace (which Swap is an alias for) to allow it to accept Group or VGroup directly, instead of always creating a new group internally.

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

Previously, CyclicReplace would create a new group from the given mobjects, making the previously created group unrecognized by self.remove(). Now, if a Group or VGroup is passed, it will be used directly rather than creating a new one.

This ensures that the original group remains in the scene, making it possible to remove it later if needed.

Example:

With this fix, the following code will now correctly remove text_group from the scene:

class SwapExample(Scene):
    def construct(self):
        text_a = Text("A").move_to(LEFT)
        text_b = Text("B").move_to(RIGHT)
        text_group = Group(text_a, text_b)
        self.play(FadeIn(text_group))
        self.play(Swap(text_group)) # passing a group, `Swap` does not create a new group
        self.wait()
        self.remove(text_group) # Successfully removes the group
        self.wait()

Links to added or changed documentation pages

https://manimce--4211.org.readthedocs.build/en/4211/reference/manim.animation.transform.Swap.html#manim.animation.transform.Swap

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

@@ -45,6 +45,7 @@
RendererType,
)
from ..mobject.mobject import Group, Mobject
from ..mobject.types.vectorized_mobject import VGroup

Check notice

Code scanning / CodeQL

Cyclic import Note

Import of module
manim.mobject.types.vectorized_mobject
begins an import cycle.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🆕 New
Development

Successfully merging this pull request may close these issues.

Using Swap on two Mobjects in a group can cause self.remove to not work on that group
1 participant