Did I find the right examples for you? yes no

utils.spatial.overlaps

All Samples(6)  |  Call(4)  |  Derive(0)  |  Import(2)
```Calculate whether two objects are overlapping

Each parameter should either be a position tuple or an object with
a .pos and .size
```

```        def overlaps(o1, o2):
"""Calculate whether two objects are overlapping

Each parameter should either be a position tuple or an object with
a .pos and .size
"""
o1, o2 = autorect(o1), autorect(o2)
# If the objects don't overlap in the x or y axis, return False
for i in range(2):
if not (o2.pos[i] <= o1.pos[i] < o2.pos[i] + o2.size[i] or
o1.pos[i] <= o2.pos[i] < o1.pos[i] + o1.size[i]):
return False
return True
```

```#
from .obstacles import Obstacle
from .utils.spatial import Rect, overlaps

from math import ceil, sqrt
```
```    def pos_is_valid(self, pos, size):
tiles = self._calc_tiles(pos, pos, size)
for tile in tiles:
for rect in tile:
if overlaps(Rect(pos, size), rect):
```
```        for p in self._path(pos1, pos2):
for rect in rects:
if overlaps(Rect(p, size), rect):
hit = True
p = self._fix_overlap(p, size, rect.pos, rect.size, delta)
```

```from .replay import Replay, Round
from .units import SandboxedUnit, get_unit_property
from .utils.spatial import overlaps
from .world import World

```
```            return
# unit is finished waiting to attack
if not overlaps(unit, target):
return
target.health -= unit.melee_strength
```
```    def unit_grab(self, unit, uid, amount):
item = self.world.items.get(uid)
if item == None or not overlaps(unit, item):
return
capacity = int((unit.max_inventory_weight - unit.inventory_weight) /
```