當前位置: 首頁>>代碼示例>>Python>>正文


Python Rectangle.get_overlap方法代碼示例

本文整理匯總了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))
開發者ID:msimberg,項目名稱:packman,代碼行數:27,代碼來源:shapetest.py


注:本文中的rectangle.Rectangle.get_overlap方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。