Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

fix: issue with ImageMobject bounding box (#3340)

Václav Blažej652f1b3d6a03
diff --git a/manim/camera/camera.py b/manim/camera/camera.py
index fe7f58ef2..902793cdb 100644
--- a/manim/camera/camera.py
+++ b/manim/camera/camera.py
@@ -965,7 +965,7 @@ class Camera:
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 5cefb1ac9..cb0248d3a 100644
--- a/manim/mobject/types/image_mobject.py
+++ b/manim/mobject/types/image_mobject.py
@@ -86,12 +86,13 @@ class AbstractImageMobject(Mobject):
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()
diff --git a/tests/test_graphical_units/test_img_and_svg.py b/tests/test_graphical_units/test_img_and_svg.py
index b234431ab..b2ae820cb 100644
--- a/tests/test_graphical_units/test_img_and_svg.py
+++ b/tests/test_graphical_units/test_img_and_svg.py
@@ -284,3 +284,20 @@ 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)