Skip to content

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

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.
@irvanalhaq9 irvanalhaq9 force-pushed the fix-cyclicreplace-group branch from 0873d68 to 2393d6c Compare April 20, 2025 14:52
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