-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWindowQuery.py
More file actions
33 lines (24 loc) · 1016 Bytes
/
WindowQuery.py
File metadata and controls
33 lines (24 loc) · 1016 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from pyqtree import Index
from Graphstuff import *
from math import sin, cos, pi
# Checks if b1 is outside b2
def bboxoutside(b1, b2):
return (b1[0] < b2[0] or b1[1] < b2[1] or b1[2] > b2[2] or b1[3] > b2[3])
class TreeStruct:
bbox = (-10000, -10000, 10000, 10000)
##
# Maintain link from points to rectangle objects?
def __init__(self):
self.index = Index(bbox=self.bbox, max_items=40, max_depth=15)
def addRect(self, rect):
if (bboxoutside(rect.bbox, self.bbox)):
print('outside')
pass # TODO
self.index.insert(rect, rect.bbox)
def removeRect(self, rect):
self.index.remove(rect, rect.bbox)
def query(self, rect):
candidates = self.index.intersect(rect.bbox)
# return candidates
# TBD if we want to make the check both ways or are okay with overlaps only being detected on one end
return [candidate for candidate in candidates if rect.overlaps(candidate) or candidate.overlaps(rect)]