Commit 9a529acd authored by Joseph Siddons's avatar Joseph Siddons
Browse files

Merge branch 'fix_rect_bound' into 'main'

Fix Rectangle intersection if the Rectangle falls completely within the other

Closes #5

See merge request !10
parents 724926b6 cfdb2d7e
...@@ -224,8 +224,14 @@ class SpaceTimeRectangle: ...@@ -224,8 +224,14 @@ class SpaceTimeRectangle:
# Other is fully south of self # Other is fully south of self
return False return False
# Handle east / west edges # Handle east / west edges
return self._test_east_west(other.west) or self._test_east_west( return (
other.east self._test_east_west(other.west)
or self._test_east_west(other.east)
# Fully contained within other
or (
other._test_east_west(self.west)
and other._test_east_west(self.east)
)
) )
def nearby( def nearby(
......
...@@ -192,8 +192,14 @@ class Rectangle: ...@@ -192,8 +192,14 @@ class Rectangle:
# Other is fully south of self # Other is fully south of self
return False return False
# Handle east / west edges # Handle east / west edges
return self._test_east_west(other.west) or self._test_east_west( return (
other.east self._test_east_west(other.west)
or self._test_east_west(other.east)
# Fully contained within other
or (
other._test_east_west(self.west)
and other._test_east_west(self.east)
)
) )
def nearby( def nearby(
......
...@@ -10,7 +10,7 @@ to usage of type annotations. ...@@ -10,7 +10,7 @@ to usage of type annotations.
As a dependency with `pip` As a dependency with `pip`
```bash ```bash
pip install git+git@git.noc.ac.uk:nocsurfaceprocesses/geospatialtools.git pip install git+ssh://git@git.noc.ac.uk/nocsurfaceprocesses/geospatialtools.git
``` ```
## Neighbours ## Neighbours
......
...@@ -72,6 +72,16 @@ class TestRect(unittest.TestCase): ...@@ -72,6 +72,16 @@ class TestRect(unittest.TestCase):
) )
assert not rect.intersects(test_rect) assert not rect.intersects(test_rect)
def test_inside(self):
# TEST: rectangle fully inside another
d = datetime(1978, 5, 17, 2, 33)
dt = timedelta(days=4, hours=7)
outer = Rectangle(-10, 10, d, -10, 10, dt)
inner = Rectangle(-5, 5, d, -5, 5, timedelta(days=1, hours=3))
assert outer.intersects(inner)
assert inner.intersects(outer)
class TestOctTree(unittest.TestCase): class TestOctTree(unittest.TestCase):
def test_divides(self): def test_divides(self):
......
...@@ -47,6 +47,14 @@ class TestRect(unittest.TestCase): ...@@ -47,6 +47,14 @@ class TestRect(unittest.TestCase):
assert test_rect.east < rect.west assert test_rect.east < rect.west
assert rect.intersects(test_rect) assert rect.intersects(test_rect)
def test_inside(self):
# TEST: rectangle fully inside another
outer = Rectangle(-10, 10, -10, 10)
inner = Rectangle(-5, 5, -5, 5)
assert outer.intersects(inner)
assert inner.intersects(outer)
class TestQuadTree(unittest.TestCase): class TestQuadTree(unittest.TestCase):
def test_divides(self): def test_divides(self):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment