Skip to content

Commit 652f1b3

Browse files
vaclavblazejVáclav Blažejnaveen521kkpre-commit-ci[bot]
authored
fix: issue with ImageMobject bounding box (#3340)
* 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. * add a test to check that rotating an image to and from doesn't change it * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: Václav Blažej <[email protected]> Co-authored-by: Naveen M K <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent d77a47a commit 652f1b3

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

manim/camera/camera.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,7 @@ def display_image_mobject(
965965
The Pixel array to put the imagemobject in.
966966
"""
967967
corner_coords = self.points_to_pixel_coords(image_mobject, image_mobject.points)
968-
ul_coords, ur_coords, dl_coords = corner_coords
968+
ul_coords, ur_coords, dl_coords, _ = corner_coords
969969
right_vect = ur_coords - ul_coords
970970
down_vect = dl_coords - ul_coords
971971
center_coords = ul_coords + (right_vect + down_vect) / 2

manim/mobject/types/image_mobject.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,13 @@ def set_resampling_algorithm(self, resampling_algorithm: int):
8686
return self
8787

8888
def reset_points(self):
89-
# Corresponding corners of image are fixed to these 3 points
89+
"""Sets :attr:`points` to be the four image corners."""
9090
self.points = np.array(
9191
[
9292
UP + LEFT,
9393
UP + RIGHT,
9494
DOWN + LEFT,
95+
DOWN + RIGHT,
9596
],
9697
)
9798
self.center()

tests/test_graphical_units/test_img_and_svg.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,3 +284,20 @@ def test_ImageInterpolation(scene):
284284
scene.add(img1, img2, img3, img4, img5)
285285
[s.shift(4 * LEFT + pos * 2 * RIGHT) for pos, s in enumerate(scene.mobjects)]
286286
scene.wait()
287+
288+
289+
def test_ImageMobject_points_length():
290+
file_path = get_svg_resource("tree_img_640x351.png")
291+
im1 = ImageMobject(file_path)
292+
assert len(im1.points) == 4
293+
294+
295+
def test_ImageMobject_rotation():
296+
# see https://github.com/ManimCommunity/manim/issues/3067
297+
# rotating an image to and from the same angle should not change the image
298+
file_path = get_svg_resource("tree_img_640x351.png")
299+
im1 = ImageMobject(file_path)
300+
im2 = im1.copy()
301+
im1.rotate(PI / 2)
302+
im1.rotate(-PI / 2)
303+
np.testing.assert_array_equal(im1.points, im2.points)

0 commit comments

Comments
 (0)