From b50a5473cef1c1ea9f5f8e6de2fd277ebc05895d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=A1clav=20Bla=C5=BEej?= Date: Tue, 22 Aug 2023 15:26:40 +0100 Subject: [PATCH 1/3] fix: fix an issue with ImageMobject bounding box A missing point resulted in smaller bounding box causing issues it to be smaller when the object is rotated. Added the missing fourth point to ImageMobject points and altered call from camera. Filled in docstring that used to propagate from superclass, saying that ImageMobject has no points. --- manim/camera/camera.py | 2 +- manim/mobject/types/image_mobject.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/manim/camera/camera.py b/manim/camera/camera.py index b26e4aec0e..4e64163110 100644 --- a/manim/camera/camera.py +++ b/manim/camera/camera.py @@ -966,7 +966,7 @@ def display_image_mobject( The Pixel array to put the imagemobject in. """ corner_coords = self.points_to_pixel_coords(image_mobject, image_mobject.points) - ul_coords, ur_coords, dl_coords = corner_coords + ul_coords, ur_coords, dl_coords, _ = corner_coords right_vect = ur_coords - ul_coords down_vect = dl_coords - ul_coords center_coords = ul_coords + (right_vect + down_vect) / 2 diff --git a/manim/mobject/types/image_mobject.py b/manim/mobject/types/image_mobject.py index 5cefb1ac93..cb0248d3a5 100644 --- a/manim/mobject/types/image_mobject.py +++ b/manim/mobject/types/image_mobject.py @@ -86,12 +86,13 @@ def set_resampling_algorithm(self, resampling_algorithm: int): return self def reset_points(self): - # Corresponding corners of image are fixed to these 3 points + """Sets :attr:`points` to be the four image corners.""" self.points = np.array( [ UP + LEFT, UP + RIGHT, DOWN + LEFT, + DOWN + RIGHT, ], ) self.center() From 2b4f783948e3f26654e9913a3d797d7c83629998 Mon Sep 17 00:00:00 2001 From: Naveen M K Date: Sat, 2 Sep 2023 22:36:27 +0530 Subject: [PATCH 2/3] add a test to check that rotating an image to and from doesn't change it --- tests/test_graphical_units/test_img_and_svg.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/test_graphical_units/test_img_and_svg.py b/tests/test_graphical_units/test_img_and_svg.py index b234431abb..0aaae63d19 100644 --- a/tests/test_graphical_units/test_img_and_svg.py +++ b/tests/test_graphical_units/test_img_and_svg.py @@ -284,3 +284,19 @@ def test_ImageInterpolation(scene): scene.add(img1, img2, img3, img4, img5) [s.shift(4 * LEFT + pos * 2 * RIGHT) for pos, s in enumerate(scene.mobjects)] scene.wait() + + +def test_ImageMobject_points_length(): + file_path = get_svg_resource("tree_img_640x351.png") + im1 = ImageMobject(file_path) + assert len(im1.points) == 4 + +def test_ImageMobject_rotation(): + # see https://github.com/ManimCommunity/manim/issues/3067 + # rotating an image to and from the same angle should not change the image + file_path = get_svg_resource("tree_img_640x351.png") + im1 = ImageMobject(file_path) + im2 = im1.copy() + im1.rotate(PI / 2) + im1.rotate(-PI / 2) + np.testing.assert_array_equal(im1.points, im2.points) From 6bc53a85c624a2a3937d6288b844f53a01d621e6 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 2 Sep 2023 17:07:14 +0000 Subject: [PATCH 3/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/test_graphical_units/test_img_and_svg.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_graphical_units/test_img_and_svg.py b/tests/test_graphical_units/test_img_and_svg.py index 0aaae63d19..b2ae820cb6 100644 --- a/tests/test_graphical_units/test_img_and_svg.py +++ b/tests/test_graphical_units/test_img_and_svg.py @@ -291,6 +291,7 @@ def test_ImageMobject_points_length(): im1 = ImageMobject(file_path) assert len(im1.points) == 4 + def test_ImageMobject_rotation(): # see https://github.com/ManimCommunity/manim/issues/3067 # rotating an image to and from the same angle should not change the image