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
Joseph Siddons
GeoSpatialTools
Commits
8507d8e4
Commit
8507d8e4
authored
6 months ago
by
Joseph Siddons
Browse files
Options
Download
Email Patches
Plain Diff
test(ellipse): add tests for QuadTree and OctTree ellipse comparisons.
parent
72f1c331
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
91 additions
and
1 deletion
+91
-1
test/test_octtree.py
test/test_octtree.py
+51
-0
test/test_quadtree.py
test/test_quadtree.py
+40
-1
No files found.
test/test_octtree.py
View file @
8507d8e4
import
unittest
import
unittest
from
datetime
import
datetime
,
timedelta
from
datetime
import
datetime
,
timedelta
from
GeoSpatialTools
import
haversine
from
GeoSpatialTools.octtree
import
(
from
GeoSpatialTools.octtree
import
(
OctTree
,
OctTree
,
SpaceTimeRecord
as
Record
,
SpaceTimeRecord
as
Record
,
SpaceTimeRectangle
as
Rectangle
,
SpaceTimeRectangle
as
Rectangle
,
SpaceTimeEllipse
as
Ellipse
,
)
)
...
@@ -128,6 +130,55 @@ class TestOctTree(unittest.TestCase):
...
@@ -128,6 +130,55 @@ class TestOctTree(unittest.TestCase):
assert
res
==
expected
assert
res
==
expected
def
test_ellipse_query
(
self
):
d1
=
haversine
(
0
,
2.5
,
1
,
2.5
)
d2
=
haversine
(
0
,
2.5
,
0
,
3.0
)
theta
=
0
d
=
datetime
(
2023
,
3
,
24
,
12
,
0
)
test_datetime
=
d
+
timedelta
(
hours
=
4
)
test_timedelta
=
timedelta
(
hours
=
5
)
ellipse
=
Ellipse
(
12.5
,
2.5
,
test_datetime
,
d1
,
d2
,
theta
,
test_timedelta
)
# TEST: distint locii
assert
(
ellipse
.
p1_lon
,
ellipse
.
p1_lat
)
!=
(
ellipse
.
p2_lon
,
ellipse
.
p2_lat
,
)
d
=
datetime
(
2023
,
3
,
24
,
12
,
0
)
dt
=
timedelta
(
days
=
10
)
boundary
=
Rectangle
(
10
,
4
,
d
,
20
,
8
,
dt
)
otree
=
OctTree
(
boundary
,
capacity
=
3
)
points
:
list
[
Record
]
=
[
Record
(
10
,
4
,
d
,
"main"
),
Record
(
12
,
1
,
d
+
timedelta
(
hours
=
3
),
"main2"
),
Record
(
3
,
7
,
d
-
timedelta
(
days
=
3
),
"main3"
),
Record
(
13
,
2
,
d
+
timedelta
(
hours
=
17
),
"southeastfwd"
),
Record
(
3
,
6
,
d
-
timedelta
(
days
=
1
),
"northwestback"
),
Record
(
10
,
4
,
d
,
"northwestback"
),
Record
(
18
,
2
,
d
+
timedelta
(
days
=
23
),
"not added"
),
Record
(
12.6
,
2.1
,
d
+
timedelta
(
hours
=
2
),
"northeastfwd"
),
Record
(
13.5
,
2.6
,
test_datetime
,
"too north of eastern edge"
),
Record
(
12.6
,
3.0
,
test_datetime
,
"too east of northern edge"
),
# Locii
Record
(
ellipse
.
p1_lon
,
ellipse
.
p1_lat
,
test_datetime
,
"locii1"
),
Record
(
ellipse
.
p2_lon
,
ellipse
.
p2_lat
,
test_datetime
,
"locii2"
),
]
expected
=
[
Record
(
12.6
,
2.1
,
d
+
timedelta
(
hours
=
2
),
"northeastfwd"
),
Record
(
ellipse
.
p1_lon
,
ellipse
.
p1_lat
,
test_datetime
,
"locii1"
),
Record
(
ellipse
.
p2_lon
,
ellipse
.
p2_lat
,
test_datetime
,
"locii2"
),
]
for
point
in
points
:
otree
.
insert
(
point
)
res
=
otree
.
query_ellipse
(
ellipse
)
assert
res
==
expected
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
unittest
.
main
()
unittest
.
main
()
This diff is collapsed.
Click to expand it.
test/test_quadtree.py
View file @
8507d8e4
from
math
import
pi
import
unittest
import
unittest
from
GeoSpatialTools.quadtree
import
QuadTree
,
Record
,
Rectangle
from
GeoSpatialTools
import
haversine
from
GeoSpatialTools.quadtree
import
QuadTree
,
Record
,
Rectangle
,
Ellipse
class
TestRect
(
unittest
.
TestCase
):
class
TestRect
(
unittest
.
TestCase
):
...
@@ -96,6 +98,43 @@ class TestQuadTree(unittest.TestCase):
...
@@ -96,6 +98,43 @@ class TestQuadTree(unittest.TestCase):
assert
res
==
expected
assert
res
==
expected
def
test_ellipse_query
(
self
):
d1
=
haversine
(
0
,
2.5
,
1
,
2.5
)
d2
=
haversine
(
0
,
2.5
,
0
,
3.0
)
theta
=
0
ellipse
=
Ellipse
(
12.5
,
2.5
,
d1
,
d2
,
theta
)
# TEST: distint locii
assert
(
ellipse
.
p1_lon
,
ellipse
.
p1_lat
)
!=
(
ellipse
.
p2_lon
,
ellipse
.
p2_lat
,
)
boundary
=
Rectangle
(
10
,
4
,
20
,
8
)
qtree
=
QuadTree
(
boundary
,
capacity
=
3
)
points
:
list
[
Record
]
=
[
Record
(
10
,
5
),
Record
(
19
,
1
),
Record
(
0
,
0
),
Record
(
-
2
,
-
9.2
),
Record
(
13.5
,
2.6
),
# Just North of Eastern edge
Record
(
12.6
,
3.0
),
# Just East of Northern edge
Record
(
12.8
,
2.1
),
# Locii
Record
(
ellipse
.
p1_lon
,
ellipse
.
p1_lat
),
Record
(
ellipse
.
p2_lon
,
ellipse
.
p2_lat
),
]
expected
=
[
Record
(
12.8
,
2.1
),
Record
(
ellipse
.
p1_lon
,
ellipse
.
p1_lat
),
Record
(
ellipse
.
p2_lon
,
ellipse
.
p2_lat
),
]
for
point
in
points
:
qtree
.
insert
(
point
)
res
=
qtree
.
query_ellipse
(
ellipse
)
assert
res
==
expected
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
unittest
.
main
()
unittest
.
main
()
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