diff --git a/arkindex_worker/cache.py b/arkindex_worker/cache.py index 57823b7c75ea8907b832bbdfc1588bede9c88229..660c2b74b932291ad1f4c9b04a903f4cf8a7905a 100644 --- a/arkindex_worker/cache.py +++ b/arkindex_worker/cache.py @@ -79,7 +79,7 @@ class CachedElement(Model): bounding_box.width != self.image.width or bounding_box.height != self.image.height ): - box = f"{bounding_box.x},{bounding_box.y},{bounding_box.x + bounding_box.width},{bounding_box.y + bounding_box.height}" + box = f"{bounding_box.x},{bounding_box.y},{bounding_box.width},{bounding_box.height}" else: box = "full" diff --git a/tests/test_cache.py b/tests/test_cache.py index b034ed8b8846f732854550b60bfb460773f47e3d..349cde6aaf8dbef77c6284815eef3a1e33f28d2b 100644 --- a/tests/test_cache.py +++ b/tests/test_cache.py @@ -74,31 +74,91 @@ CREATE TABLE "transcriptions" ("id" TEXT NOT NULL PRIMARY KEY, "element_id" TEXT @pytest.mark.parametrize( - "image_width,image_height,polygon_width,polygon_height,max_size,expected_url", + "image_width,image_height,polygon_x,polygon_y,polygon_width,polygon_height,max_size,expected_url", [ # No max_size: no resize - (400, 600, 400, 600, None, "http://something/full/full/0/default.jpg"), + (400, 600, 0, 0, 400, 600, None, "http://something/full/full/0/default.jpg"), # No max_size: resize on bbox - (400, 600, 200, 100, None, "http://something/0,0,200,100/full/0/default.jpg"), + ( + 400, + 600, + 0, + 0, + 200, + 100, + None, + "http://something/0,0,200,100/full/0/default.jpg", + ), + ( + 400, + 600, + 50, + 50, + 200, + 100, + None, + "http://something/50,50,200,100/full/0/default.jpg", + ), # max_size equal to the image size, no resize - (400, 600, 400, 600, 600, "http://something/full/full/0/default.jpg"), - (600, 400, 600, 400, 600, "http://something/full/full/0/default.jpg"), - (400, 400, 400, 400, 400, "http://something/full/full/0/default.jpg"), + (400, 600, 0, 0, 400, 600, 600, "http://something/full/full/0/default.jpg"), + (600, 400, 0, 0, 600, 400, 600, "http://something/full/full/0/default.jpg"), + (400, 400, 0, 0, 400, 400, 400, "http://something/full/full/0/default.jpg"), + ( + 400, + 400, + 50, + 50, + 200, + 100, + 200, + "http://something/50,50,200,100/full/0/default.jpg", + ), # max_size is smaller than the image, resize - (400, 600, 400, 600, 400, "http://something/full/266,400/0/default.jpg"), - (400, 600, 200, 600, 400, "http://something/0,0,200,600/full/0/default.jpg"), - (600, 400, 600, 400, 400, "http://something/full/400,266/0/default.jpg"), - (400, 400, 400, 400, 200, "http://something/full/200,200/0/default.jpg"), + (400, 600, 0, 0, 400, 600, 400, "http://something/full/266,400/0/default.jpg"), + (600, 400, 0, 0, 600, 400, 400, "http://something/full/400,266/0/default.jpg"), + ( + 400, + 600, + 0, + 0, + 200, + 600, + 400, + "http://something/0,0,200,600/full/0/default.jpg", + ), + ( + 400, + 600, + 50, + 50, + 200, + 600, + 400, + "http://something/50,50,200,600/full/0/default.jpg", + ), + (400, 400, 0, 0, 400, 400, 200, "http://something/full/200,200/0/default.jpg"), # max_size above the image size, no resize - (400, 600, 400, 600, 800, "http://something/full/full/0/default.jpg"), - (600, 400, 600, 400, 800, "http://something/full/full/0/default.jpg"), - (400, 400, 400, 400, 800, "http://something/full/full/0/default.jpg"), + (400, 600, 0, 0, 400, 600, 800, "http://something/full/full/0/default.jpg"), + (600, 400, 0, 0, 600, 400, 800, "http://something/full/full/0/default.jpg"), + (400, 400, 0, 0, 400, 400, 800, "http://something/full/full/0/default.jpg"), + ( + 400, + 400, + 50, + 50, + 200, + 100, + 800, + "http://something/50,50,200,100/full/0/default.jpg", + ), ], ) def test_element_open_image( mocker, image_width, image_height, + polygon_x, + polygon_y, polygon_width, polygon_height, max_size, @@ -119,11 +179,11 @@ def test_element_open_image( type="element", image=image, polygon=[ - [0, 0], - [polygon_width, 0], - [polygon_width, polygon_height], - [0, polygon_height], - [0, 0], + [polygon_x, polygon_y], + [polygon_x + polygon_width, polygon_y], + [polygon_x + polygon_width, polygon_y + polygon_height], + [polygon_x, polygon_y + polygon_height], + [polygon_x, polygon_y], ], )