def test_contains(self):
     for rdggs in [WGS84_003, WGS84_003_RADIANS]:
         # A cell should contain its nucleus, but not my test point p.
         # Assume that nucleus() and vertices() work.
         for suid in [[N, 3, 1], [P, 5, 7, 5, 1, 3], [S, 0]]:
             c = Cell(rdggs, suid)
             w = c.width()
             for plane in [True, False]:
                 nucleus = c.nucleus(plane=plane)
                 vertices = c.vertices(plane=plane)
                 p = (max([v[0] for v in vertices]) + 1, vertices[3][1])
                 self.assertTrue(c.contains(nucleus, plane=plane))
                 self.assertFalse(c.contains(p, plane=plane))
def _get_finest_cell(polygon, suid):
    parent_cell = Cell(suid=suid)
    # get the children cells and polygons for these cells
    children_cells = [cell for cell in parent_cell.subcells()]
    children_poly = [
        Polygon(cell.vertices(plane=False)) for cell in children_cells
    ]
    # function and truth list for multipolygon / polygon (polygon) contained within multipolygon / polygon (cell)
    truth = [poly.contains(polygon) for poly in children_poly]
    # if we get something back, check the next level lower
    returned_cells = list(compress(children_cells, truth))
    if returned_cells:
        finest = _get_finest_cell(polygon, returned_cells[0].suid)
    else:
        parent_poly = Polygon(parent_cell.vertices(plane=False))
        if parent_poly.contains(polygon):
            finest = parent_cell
        else:
            finest = None
    return finest