Skip to content

Commit

Permalink
General QuadTree Class, using Node, Point and Child(enum) classes
Browse files Browse the repository at this point in the history
Added finding points in given range
Added getlines method
  • Loading branch information
MrDenkoV committed Dec 3, 2019
1 parent d2d0cbc commit 4bd4c73
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ ipython_config.py
__pycache__/
*.py[cod]
*$py.class
.idea/

# C extensions
*.so
Expand Down Expand Up @@ -258,4 +259,4 @@ dmypy.json
*.zip
*.docx
*.pdf
ignore/
ignore/
24 changes: 24 additions & 0 deletions quadtree.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,19 @@ def create_kids(node, points):
create_kids(se, tabse)


def _get_lines(node, sol):
if node.kidscount!=0:
_get_lines(node.get_kid(Child.NE.value), sol)
_get_lines(node.get_kid(Child.NW.value), sol)
_get_lines(node.get_kid(Child.SE.value), sol)
_get_lines(node.get_kid(Child.SW.value), sol)
else:
sol += [[(node.east, node.north), (node.west, node.north)]]
sol += [[(node.west, node.north), (node.west, node.south)]]
sol += [[(node.west, node.south), (node.east, node.south)]]
sol += [[(node.east, node.south), (node.east, node.north)]]


class QuadTree:
def __init__(self, points, n=100, w=0, s=0, e=100):
self.root = Node(n, w, s, e, None)
Expand All @@ -98,6 +111,11 @@ def find_points(self, lowerleft, upperright, solution, tree=None):
for kid in tree.kids:
self.find_points(lowerleft, upperright, solution, kid)

def get_lines(self):
sol = []
_get_lines(self.root, sol)
return sol


def druk(quad, depth=0):
if quad is None:
Expand Down Expand Up @@ -140,6 +158,12 @@ def get_points(_=0):
print(point)
print(len(solution))

lines = quad.get_lines()

print('Lines:')
for line in lines:
print(line)

# TODO Better input
# TODO Visualization

0 comments on commit 4bd4c73

Please sign in to comment.