本文整理匯總了Python中rect.Rect.union方法的典型用法代碼示例。如果您正苦於以下問題:Python Rect.union方法的具體用法?Python Rect.union怎麽用?Python Rect.union使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rect.Rect
的用法示例。
在下文中一共展示了Rect.union方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: from rect import Rect [as 別名]
# 或者: from rect.Rect import union [as 別名]
def __init__(self, game, zone):
self.game = game
self.zone = zone
self.screen = self.game.screen
self.battles = [x for x in game.battles if x.zone == self.zone]
self.targets = [x for x in game.targets if x.zone == self.zone]
self.terrain = [x for x in game.terrain if x.zone == self.zone]
# Determine the size required for the map surface
map_size_rect = Rect()
for ter in self.terrain:
map_size_rect.union(ter.rect)
self.map_surface = pygame.Surface(map_size_rect.size)
# Draw all static terrain and targets to the map surface
for ter in self.terrain:
if ter.static:
self.map_surface.fill((255, 0, 0), ter)
ter.draw(self.map_surface)
for tar in self.targets:
if tar.static:
tar.draw(self.map_surface)
示例2: _NodeCursor
# 需要導入模塊: from rect import Rect [as 別名]
# 或者: from rect.Rect import union [as 別名]
class _NodeCursor(object):
@classmethod
def create(cls, rooto, rect):
idx = rooto.count
rooto.count += 1
rooto._ensure_pool(idx + 1)
#rooto.node_pool.extend([0,0])
#rooto.rect_pool.extend([0,0,0,0])
retv = _NodeCursor(rooto, idx, rect, 0, 0)
retv._save_back()
return retv
@classmethod
def create_with_children(cls, children, rooto):
rect = union_all([c for c in children])
nr = Rect(rect.x, rect.y, rect.xx, rect.yy)
assert (not rect.swapped_x)
nc = _NodeCursor.create(rooto, rect)
nc._set_children(children)
assert (not nc.is_leaf())
return nc
@classmethod
def create_leaf(cls, rooto, leaf_obj, leaf_rect):
rect = Rect(leaf_rect.x, leaf_rect.y, leaf_rect.xx, leaf_rect.yy)
rect.swapped_x = True # Mark as leaf by setting the xswap flag.
res = _NodeCursor.create(rooto, rect)
idx = res.index
res.first_child = rooto.leaf_count
rooto.leaf_count += 1
res.next_sibling = 0
rooto.leaf_pool.append(leaf_obj)
res._save_back()
res._become(idx)
assert (res.is_leaf())
return res
__slots__ = ("root", "npool", "rpool", "index", "rect", "next_sibling", "first_child")
def __init__(self, rooto, index, rect, first_child, next_sibling):
self.root = rooto
self.rpool = rooto.rect_pool
self.npool = rooto.node_pool
self.index = index
self.rect = rect
self.next_sibling = next_sibling
self.first_child = first_child
def walk(self, predicate):
if (predicate(self, self.leaf_obj())):
yield self
if not self.is_leaf():
for c in self.children():
for cr in c.walk(predicate):
yield cr
def query_rect(self, r):
""" Return things that intersect with 'r'. """
def p(o, x): return r.does_intersect(o.rect)
for rr in self.walk(p):
yield rr
def query_point(self, point):
""" Query by a point """
def p(o, x): return o.rect.does_containpoint(point)
for rr in self.walk(p):
yield rr
def lift(self):
return _NodeCursor(self.root,
self.index,
self.rect,
self.first_child,
self.next_sibling)
def _become(self, index):
recti = index * 4
nodei = index * 2
rp = self.rpool
x = rp[recti]
y = rp[recti + 1]
xx = rp[recti + 2]
yy = rp[recti + 3]
if (x == 0.0 and y == 0.0 and xx == 0.0 and yy == 0.0):
self.rect = NullRect
else:
self.rect = Rect(x, y, xx, yy)
self.next_sibling = self.npool[nodei]
self.first_child = self.npool[nodei + 1]
self.index = index
#.........這裏部分代碼省略.........