From 1b5cf63182c423effa45b017be49467dffa7e9bb Mon Sep 17 00:00:00 2001 From: David Huggins-Daines Date: Wed, 27 Nov 2024 21:54:03 -0500 Subject: [PATCH] fix: slight optimization to get_bound and generic bbox --- playa/page.py | 4 +++- playa/utils.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/playa/page.py b/playa/page.py index 64f0c66e..dec1059f 100644 --- a/playa/page.py +++ b/playa/page.py @@ -1684,8 +1684,10 @@ def object_type(self): @property def bbox(self) -> Rect: + # These bboxes have already been computed in device space so + # we don't need all 4 corners! points = itertools.chain.from_iterable( - ((x0, y0), (x0, y1), (x1, y1), (x1, y0)) + ((x0, y0), (x1, y1)) for x0, y0, x1, y1 in (item.bbox for item in self) ) return get_bound(points) diff --git a/playa/utils.py b/playa/utils.py index 9deb1b00..cb3b7f41 100644 --- a/playa/utils.py +++ b/playa/utils.py @@ -261,7 +261,7 @@ def get_bound(pts: Iterable[Point]) -> Rect: Raises: ValueError on empty input (as there is no bounding box). """ - xs, ys = list(zip(*pts)) + xs, ys = zip(*pts) x0 = min(xs) y0 = min(ys) x1 = max(xs)