+ def _apply_rotation(self, rectangle):
+ """Adjust the rectangle coordinates based on rotation"""
+ if self._rotation == 90:
+ return Rectangle(
+ self._width - rectangle.y2,
+ rectangle.x1,
+ self._width - rectangle.y1,
+ rectangle.x2,
+ )
+ if self._rotation == 180:
+ return Rectangle(
+ self._width - rectangle.x2,
+ self._height - rectangle.y2,
+ self._width - rectangle.x1,
+ self._height - rectangle.y1,
+ )
+ if self._rotation == 270:
+ return Rectangle(
+ rectangle.y1,
+ self._height - rectangle.x2,
+ rectangle.y2,
+ self._height - rectangle.x1,
+ )
+ return rectangle
+