本文整理汇总了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))