diff --git a/.gitignore b/.gitignore index 35dc1cc..32c234f 100644 --- a/.gitignore +++ b/.gitignore @@ -152,6 +152,7 @@ ipython_config.py __pycache__/ *.py[cod] *$py.class +.idea/ # C extensions *.so @@ -258,4 +259,4 @@ dmypy.json *.zip *.docx *.pdf -ignore/ \ No newline at end of file +ignore/ diff --git a/quadtree.py b/quadtree.py index 90beed0..dae8d2d 100644 --- a/quadtree.py +++ b/quadtree.py @@ -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) @@ -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: @@ -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