Skip to content

Commit

Permalink
documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
stijnvermeeren-swisstopo committed May 14, 2024
1 parent 872a002 commit bd1487d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/stratigraphy/util/geometric_line_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ def merge_parallel_lines_quadtree(lines: list[Line], tol: int, angle_threshold:
lines_quad_tree = LinesQuadTree(width, height)

keys_queue = queue.Queue()
print("lines", len(lines))
for line in lines:
line_key = lines_quad_tree.add(line)
keys_queue.put(line_key)
Expand Down
25 changes: 25 additions & 0 deletions src/stratigraphy/util/linesquadtree.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,44 @@ class LinesQuadTree:
"""

def __init__(self, width: float, height: float):
"""Create a LinesQuadTree instance.
The LinesQuadTree will contain an actual quad tree with the end points of all lines, as well as a hashmap to
keep track of the lines themselves.
Args:
width (float): width of the area that should contain all (endpoints of) all lines.
height (float): height of the area that should contain all (endpoints of) all lines.
"""
self.qtree = quads.QuadTree(
(width / 2, height / 2), width + 1000, height + 1000
) # Add some margin to the width and height to allow for slightly negative values
self.hashmap = {}

def remove(self, line_key: str):
"""Remove a line from the quad tree.
If no matching line exists in the quad tree, then the method returns immediately without error.
Args:
line_key (str): The key of the line to be removed from the quad tree.
"""
if line_key in self.hashmap:
line = self.hashmap[line_key]
self._qtree_delete(line.start, line_key)
self._qtree_delete(line.end, line_key)
del self.hashmap[line_key]

def add(self, line: Line) -> str:
"""Add a line to the quad tree.
Args:
line (Line): the line to be added to the quad tree.
Returns:
str: the UUID key that is automatically generated for the new line.
"""
line_key = uuid.uuid4().hex
self.hashmap[line_key] = line

Expand Down

0 comments on commit bd1487d

Please sign in to comment.