[RectCollection] advise the user what to do if they want to make a non-manhattan rotation

This commit is contained in:
Jan Petykiewicz 2026-09-14 21:55:06 -07:00
commit d48c0f2879

View file

@ -187,7 +187,12 @@ class RectCollection(Shape):
def rotate(self, theta: float) -> Self:
quarter_turns = int(numpy.rint(theta / (pi / 2)))
if not numpy.isclose(theta, quarter_turns * (pi / 2)):
raise PatternError('RectCollection only supports Manhattan rotations')
raise PatternError(
f'RectCollection cannot rotate by {theta!r} radians; only Manhattan rotations (multiples of pi/2) are supported. '
'Explicitly replace the collection with to_polygons(), or call Pattern.polygonize() '
'on the pattern containing it (including referenced child patterns) before transforming, '
'flattening, or computing hierarchical bounds.'
)
turns = quarter_turns % 4
if turns == 0 or self._rects.size == 0:
return self