Skip to content

fix: issue with ImageMobject bounding box #3340

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Nov 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion manim/camera/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion manim/mobject/types/image_mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
17 changes: 17 additions & 0 deletions tests/test_graphical_units/test_img_and_svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)