def testInitEmpty(self): lt = point.empty() rb = point.empty() rect = fromPoints(lt, rb) self.assertEqual(rect.topLeft(), lt) self.assertEqual(rect.rightBottom(), rb) self.assertEqual(rect.topRight(), point.fromXY(rb.x, lt.y)) self.assertEqual(rect.leftBottom(), point.fromXY(lt.x, rb.y))
def testUnion2(self): rect1 = fromSizes(point.empty(), 50, 50) rect2 = fromSizes(point.fromXY(30, 30), 10, 10) rect = rect1.unionWith(rect2) self.assertEqual(rect.topLeft().x, 0) self.assertEqual(rect.topLeft().y, 50) self.assertEqual(rect.rightBottom().x, 50) self.assertEqual(rect.rightBottom().y, 0)
def __init__(self, point1=point.empty(), point2=point.empty()): """Initialize rect with two points Note: The result will be: rect.left < rect.right rect.bottom < rect.top """ self.__topLeft = point.empty() self.__rightBottom = point.empty() if point1.x < point2.x: self.__topLeft.x = point1.x self.__rightBottom.x = point2.x else: self.__topLeft.x = point2.x self.__rightBottom.x = point1.x if point1.y > point2.y: self.__topLeft.y = point1.y self.__rightBottom.y = point2.y else: self.__topLeft.y = point2.y self.__rightBottom.y = point1.y
def empty(): """Initialize empty rect""" return Rect(point.empty(), point.empty())