本文整理匯總了Python中rect.Rect.fits方法的典型用法代碼示例。如果您正苦於以下問題:Python Rect.fits方法的具體用法?Python Rect.fits怎麽用?Python Rect.fits使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rect.Rect
的用法示例。
在下文中一共展示了Rect.fits方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: PackNode
# 需要導入模塊: from rect import Rect [as 別名]
# 或者: from rect.Rect import fits [as 別名]
class PackNode(object):
"""
Creates an area which can recursively pack smaller areas into itself.
"""
def __init__(self, xywh):
self.rect = Rect(xywh)
def __repr__(self):
return "<%s %s>" % (self.__class__.__name__, self.rect)
def insert(self, xywh):
"""
Insert an rect into the current rect. Returns a new Node representing
the new rect.
Returns None if no space is available for the new rect.
"""
if hasattr(self, 'children'):
for child in self.children:
r = child.insert(xywh)
if r is not None:
return r
return None
rect = Rect(xywh)
if self.rect.fits(rect):
a = PackNode((self.rect.left+rect.width, self.rect.bottom, self.rect.width-rect.width, rect.height))
b = PackNode((self.rect.left, self.rect.bottom+rect.height, self.rect.width, self.rect.height-rect.height))
self.children = [a,b]
return PackNode((self.rect.left, self.rect.bottom, rect.width, rect.height))