Last active
October 13, 2022 05:35
-
-
Save voloshink/aabdca829dc8787c238e8b1e75c602cc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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