From 27766127e26668f9097af1a4a94a9b13fd04f565 Mon Sep 17 00:00:00 2001 From: Sir James Clark Maxwell <71722499+SirJamesClarkMaxwell@users.noreply.github.com> Date: Sun, 14 Apr 2024 15:22:36 +0200 Subject: [PATCH] Fix successive calls of :meth:`.LinearTransformationScene.apply_matrix` (#3675) * docs: improve installation FAQ's * I have potentially resolved the issue when in LinearTransformationScene between two animations of transforming space we invoke the self.wait() * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * added another solutions in comments, added tests and removed wrong files from git * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * yeah , i forgot to save the file xd * fixed the test, removed the comments my in changed file * fix test and speed up test time for test_apply_matrix * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fixed the test, removed the comments my in changed file * fixed the test * Revert "docs: improve installation FAQ's" This reverts commit e53a1c8d6f14b77f389f79126f77bbcc48e6f869. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: JasonGrace2282 Co-authored-by: adeshpande <110117391+JasonGrace2282@users.noreply.github.com> --- manim/scene/vector_space_scene.py | 8 ++++++-- tests/test_graphical_units/test_vector_scene.py | 12 +++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/manim/scene/vector_space_scene.py b/manim/scene/vector_space_scene.py index d39ce32895..e9304115ef 100644 --- a/manim/scene/vector_space_scene.py +++ b/manim/scene/vector_space_scene.py @@ -1003,8 +1003,11 @@ def get_piece_movement(self, pieces: list | tuple | np.ndarray): Animation The animation of the movement. """ - start = VGroup(*pieces) - target = VGroup(*(mob.target for mob in pieces)) + + v_pieces = [piece for piece in pieces if isinstance(piece, VMobject)] + start = VGroup(*v_pieces) + target = VGroup(*(mob.target for mob in v_pieces)) + # don't add empty VGroups if self.leave_ghost_vectors and start.submobjects: # start.copy() gives a VGroup of Vectors @@ -1091,6 +1094,7 @@ def apply_matrix(self, matrix: np.ndarray | list | tuple, **kwargs): **kwargs Any valid keyword argument of self.apply_transposed_matrix() """ + self.apply_transposed_matrix(np.array(matrix).T, **kwargs) def apply_inverse(self, matrix: np.ndarray | list | tuple, **kwargs): diff --git a/tests/test_graphical_units/test_vector_scene.py b/tests/test_graphical_units/test_vector_scene.py index 59dfda44a9..75bc1806d1 100644 --- a/tests/test_graphical_units/test_vector_scene.py +++ b/tests/test_graphical_units/test_vector_scene.py @@ -1,6 +1,6 @@ from __future__ import annotations -from manim.scene.vector_space_scene import VectorScene +from manim.scene.vector_space_scene import LinearTransformationScene, VectorScene from manim.utils.testing.frames_comparison import frames_comparison __module_test__ = "vector_scene" @@ -14,3 +14,13 @@ def test_vector_to_coords(scene): scene.add(basis) scene.vector_to_coords(vector=vector) scene.wait() + + +def test_apply_matrix(): + scene = LinearTransformationScene(include_background_plane=False) + scene.setup() + matrix = [[-1, 1], [1, 1]] + # use short runtimes to speed up animation rendering + scene.apply_matrix(matrix, run_time=0.01) + scene.wait() + scene.apply_inverse(matrix, run_time=0.01)