Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
NOCSurfaceProcesses
GeoSpatialTools
Commits
2fa000a1
Commit
2fa000a1
authored
1 month ago
by
Joseph Siddons
Browse files
Options
Download
Plain Diff
Merge branch 'add-tree-len' into 'main'
Add length method to QuadTree and OctTree See merge request
!19
parents
bff58394
cf62e59a
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
33 additions
and
0 deletions
+33
-0
GeoSpatialTools/octtree.py
GeoSpatialTools/octtree.py
+18
-0
GeoSpatialTools/quadtree.py
GeoSpatialTools/quadtree.py
+13
-0
test/test_octtree.py
test/test_octtree.py
+1
-0
test/test_quadtree.py
test/test_quadtree.py
+1
-0
No files found.
GeoSpatialTools/octtree.py
View file @
2fa000a1
...
...
@@ -461,6 +461,24 @@ class OctTree:
out
+=
f
"
{
self
.
southeastfwd
}
"
return
out
def
len
(
self
,
_current_len
:
int
=
0
)
->
int
:
"""Get the number of points in the OctTree"""
_current_len
+=
len
(
self
.
points
)
print
(
_current_len
)
if
not
self
.
divided
:
return
_current_len
_current_len
=
self
.
northeastback
.
len
(
_current_len
)
_current_len
=
self
.
northwestback
.
len
(
_current_len
)
_current_len
=
self
.
southeastback
.
len
(
_current_len
)
_current_len
=
self
.
southwestback
.
len
(
_current_len
)
_current_len
=
self
.
northeastfwd
.
len
(
_current_len
)
_current_len
=
self
.
northwestfwd
.
len
(
_current_len
)
_current_len
=
self
.
southeastfwd
.
len
(
_current_len
)
_current_len
=
self
.
southwestfwd
.
len
(
_current_len
)
return
_current_len
def
divide
(
self
):
"""Divide the QuadTree"""
self
.
northwestfwd
=
OctTree
(
...
...
This diff is collapsed.
Click to expand it.
GeoSpatialTools/quadtree.py
View file @
2fa000a1
...
...
@@ -340,6 +340,19 @@ class QuadTree:
out
+=
f
"
{
self
.
southeast
}
"
return
out
def
len
(
self
,
_current_len
:
int
=
0
)
->
int
:
"""Get the number of points in the OctTree"""
_current_len
+=
len
(
self
.
points
)
if
not
self
.
divided
:
return
_current_len
_current_len
=
self
.
northeast
.
len
(
_current_len
)
_current_len
=
self
.
northwest
.
len
(
_current_len
)
_current_len
=
self
.
southeast
.
len
(
_current_len
)
_current_len
=
self
.
southwest
.
len
(
_current_len
)
return
_current_len
def
divide
(
self
):
"""Divide the QuadTree"""
self
.
northwest
=
QuadTree
(
...
...
This diff is collapsed.
Click to expand it.
test/test_octtree.py
View file @
2fa000a1
...
...
@@ -198,6 +198,7 @@ class TestOctTree(unittest.TestCase):
]
for
point
in
points
:
otree
.
insert
(
point
)
assert
otree
.
len
()
==
len
(
points
)
-
1
# NOTE: 1 point not added
assert
otree
.
divided
expected
=
[
points
[:
3
],
...
...
This diff is collapsed.
Click to expand it.
test/test_quadtree.py
View file @
2fa000a1
...
...
@@ -94,6 +94,7 @@ class TestQuadTree(unittest.TestCase):
for
point
in
points
:
qtree
.
insert
(
point
)
assert
qtree
.
divided
assert
qtree
.
len
()
==
len
(
points
)
res
=
[
qtree
.
points
,
qtree
.
northwest
.
points
,
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment