diff --git a/GeoSpatialTools/octtree.py b/GeoSpatialTools/octtree.py index 00299867ac405ed8219cd644dce7b4edb299beb8..2a8bc2a8e83f73c6504315ecabd95a9ac4414b4c 100644 --- a/GeoSpatialTools/octtree.py +++ b/GeoSpatialTools/octtree.py @@ -224,8 +224,14 @@ class SpaceTimeRectangle: # Other is fully south of self return False # Handle east / west edges - return self._test_east_west(other.west) or self._test_east_west( - other.east + return ( + 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( diff --git a/GeoSpatialTools/quadtree.py b/GeoSpatialTools/quadtree.py index 1bf7e7d40f84786238e6a2ba11e8300ba8181c12..dc26f844d3c9101a2b194b416a9d772a7b42339b 100644 --- a/GeoSpatialTools/quadtree.py +++ b/GeoSpatialTools/quadtree.py @@ -192,8 +192,14 @@ class Rectangle: # Other is fully south of self return False # Handle east / west edges - return self._test_east_west(other.west) or self._test_east_west( - other.east + return ( + 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( diff --git a/README.md b/README.md index e997cd98786fec2f8303df4048c16ed9c26e1ea4..3ae4369fb5a719cda05f340dcd1510ad8d372f23 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ to usage of type annotations. As a dependency with `pip` ```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 diff --git a/test/test_octtree.py b/test/test_octtree.py index 000dd3aed78a444616730da4c1e5a3af1bd75307..8efae8a42e8e68ca114d6b76b1c221a750fa71a8 100644 --- a/test/test_octtree.py +++ b/test/test_octtree.py @@ -72,6 +72,16 @@ class TestRect(unittest.TestCase): ) 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): def test_divides(self): diff --git a/test/test_quadtree.py b/test/test_quadtree.py index e171b373a303af72ab5e22265fe685f16b744046..aa1507b48196a518713c2a7610aab9fb6889deec 100644 --- a/test/test_quadtree.py +++ b/test/test_quadtree.py @@ -47,6 +47,14 @@ class TestRect(unittest.TestCase): assert test_rect.east < rect.west 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): def test_divides(self):