本文整理匯總了Python中rectangle.Rectangle.get_overlap方法的典型用法代碼示例。如果您正苦於以下問題:Python Rectangle.get_overlap方法的具體用法?Python Rectangle.get_overlap怎麽用?Python Rectangle.get_overlap使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rectangle.Rectangle
的用法示例。
在下文中一共展示了Rectangle.get_overlap方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_overlap
# 需要導入模塊: from rectangle import Rectangle [as 別名]
# 或者: from rectangle.Rectangle import get_overlap [as 別名]
def test_overlap(self):
'''
Test overlap between circles and rectangles.
'''
new_rect1 = Rectangle(100, 100)
new_rect2 = Rectangle(50, 150, 50, 50)
circ1 = Circle(25)
circ2 = Circle(30, 0, -5)
self.assertEqual(-50, new_rect1.get_overlap(new_rect2))
self.assertEqual(new_rect1.get_overlap(new_rect2),
new_rect2.get_overlap(new_rect1))
self.assertEqual(-50, circ1.get_overlap(new_rect1))
self.assertEqual(circ1.get_overlap(new_rect1),
new_rect1.get_overlap(circ1))
self.assertAlmostEqual(math.sqrt(2)*25 - 25,
circ1.get_overlap(new_rect2))
self.assertEqual(circ1.get_overlap(new_rect2),
new_rect2.get_overlap(circ1))
self.assertEqual(-50, circ1.get_overlap(circ2))
self.assertEqual(circ1.get_overlap(circ2),
circ2.get_overlap(circ1))
circ1.set_position(80, 50)
self.assertEqual(-20, circ1.get_overlap(new_rect2))
self.assertEqual(circ1.get_overlap(new_rect2),
new_rect2.get_overlap(circ1))