From 3fa124d13feda58e39a66de6dfdbb3daa5cf7276 Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Mon, 17 Jul 2023 21:30:23 -0700 Subject: [PATCH] speed up get_bounds when called on a manhattan ref --- masque/ref.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/masque/ref.py b/masque/ref.py index 26aeaba..2034eee 100644 --- a/masque/ref.py +++ b/masque/ref.py @@ -174,7 +174,21 @@ class Ref( if pattern.is_empty(): # no need to run as_pattern() return None - return self.as_pattern(pattern=pattern).get_bounds(library) # TODO can just take pattern's bounds and then transform those! + + # if rotation is manhattan, can take pattern's bounds and transform them + if numpy.isclose(self.rotation % (pi / 2), 0): + unrot_bounds = pattern.get_bounds(library) + if unrot_bounds is None: + return None + + if self.mirrored: + unrot_bounds[:, 1] *= -1 + + corners = (rotation_matrix_2d(self.rotation) @ unrot_bounds.T).T + bounds = numpy.vstack((numpy.min(corners, axis=0), + numpy.max(corners, axis=0))) * self.scale + [self.offset] + return bounds + return self.as_pattern(pattern=pattern).get_bounds(library) def __repr__(self) -> str: rotation = f' r{numpy.rad2deg(self.rotation):g}' if self.rotation != 0 else ''