+ def _clip(self, rectangle):
+ if self._rotation in (90, 270):
+ width, height = self._height, self._width
+ else:
+ width, height = self._width, self._height
+
+ if rectangle.x1 < 0:
+ rectangle.x1 = 0
+ if rectangle.y1 < 0:
+ rectangle.y1 = 0
+ if rectangle.x2 > width:
+ rectangle.x2 = width
+ if rectangle.y2 > height:
+ rectangle.y2 = height
+
+ return rectangle
+