Skip to content

Commit 7b059ef

Browse files
committed
Reorder image corners as UL, DL, DR, UR to reduce floating point error
1 parent 6aea7b6 commit 7b059ef

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

manim/camera/camera.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -973,15 +973,25 @@ def display_image_mobject(
973973
The pixel array to put the :class:`~.ImageMobject` in.
974974
"""
975975
sub_image = Image.fromarray(image_mobject.get_pixel_array(), mode="RGBA")
976+
977+
# PIL's image corner ordering is:
978+
# - UL (Up Left)
979+
# - DL (Down Left)
980+
# - DR (Down Right)
981+
# - UR (Up Right)
982+
# Respect this order to reduce floating point error.
976983
original_coords = np.array(
977984
[
978-
[0, 0],
979-
[sub_image.width, 0],
980-
[0, sub_image.height],
981-
[sub_image.width, sub_image.height],
985+
[0, 0], # UL corner
986+
[0, sub_image.height], # DL corner
987+
[sub_image.width, sub_image.height], # DR corner
988+
[sub_image.width, 0], # UR corner
982989
]
983990
)
984-
target_coords = self.points_to_pixel_coords(image_mobject, image_mobject.points)
991+
# ImageMobject corners are in a different order and must be reordered.
992+
ul_corner, ur_corner, dl_corner, dr_corner = image_mobject.points
993+
reordered_points = [ul_corner, dl_corner, dr_corner, ur_corner]
994+
target_coords = self.points_to_pixel_coords(image_mobject, reordered_points)
985995

986996
# Temporarily translate target coords to upper left corner to calculate the
987997
# smallest possible size for the target image.

0 commit comments

Comments
 (0)