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 b7cee97a5296d34f7cf3bdb617936f242e8ae077..cf41cc69639831d183fc144c603f03e359bb5f90 100644 --- a/GeoSpatialTools/quadtree.py +++ b/GeoSpatialTools/quadtree.py @@ -188,8 +188,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 1accca44cdd1aa9665f0bd06a1c0d37e4f91aa80..223c892aa0d3cb44e94344f9684f7153012cb507 100644 --- a/test/test_quadtree.py +++ b/test/test_quadtree.py @@ -46,6 +46,14 @@ class TestRect(unittest.TestCase): test_rect = Rectangle(-140, -60, 20, 60) 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):