Skip to content

Instantly share code, notes, and snippets.

@voloshink
Last active October 13, 2022 05:35
Show Gist options
  • Select an option

  • Save voloshink/aabdca829dc8787c238e8b1e75c602cc to your computer and use it in GitHub Desktop.

Select an option

Save voloshink/aabdca829dc8787c238e8b1e75c602cc to your computer and use it in GitHub Desktop.
def range_query(self, window):
exploration = [self.root]
total = 0
while len(exploration) > 0:
node = exploration.pop()
bucket = node.bucket
overlap = intersect(window, bucket)
if overlap == 0:
continue
if node.isLeaf():
total += len(node.points) * overlap/node.area()
else:
exploration.append(node.left)
exploration.append(node.right)
return total
def true_range_query(self, window):
minx, miny, maxx, maxy = window
exploration = [self.root]
total = 0
while len(exploration) > 0:
node = exploration.pop()
bucket = node.bucket
overlap = intersect(window, bucket)
if overlap == 0:
continue
if node.isLeaf():
for point in node.points:
x, y = point[0], point[1]
if x >= minx and x <= maxx and y >= miny and y <= maxy:
total += 1
else:
exploration.append(node.left)
exploration.append(node.right)
return total
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment