bool cellBoundaryInsidePolygon()

in h3_polygon.c [108:143]


bool cellBoundaryInsidePolygon(const GeoPolygon *geoPolygon, const BBox *bboxes,
                               const CellBoundary *boundary,
                               const BBox *boundaryBBox) {
    // First test a single point. Note that this fails fast if point is outside
    // bounding box.
    if (!pointInsidePolygon(geoPolygon, &bboxes[0], &boundary->verts[0])) {
        return false;
    }

    // If a point is contained, check for any line intersections
    if (cellBoundaryCrossesGeoLoop(&(geoPolygon->geoloop), &bboxes[0], boundary,
                                   boundaryBBox)) {
        return false;
    }

    // Convert boundary to geoloop for point-inside check
    const GeoLoop boundaryLoop = {.numVerts = boundary->numVerts,
                                  // Without this cast, the compiler complains
                                  // that using const LatLng[] here discards
                                  // qualifiers. But this should be safe in
                                  // context, all downstream usage expects const
                                  .verts = (LatLng *)boundary->verts};

    // Check for line intersections with, or containment of, any hole
    for (int i = 0; i < geoPolygon->numHoles; i++) {
        // If the hole has no verts, it is not possible to intersect with it.
        if (geoPolygon->holes[i].numVerts > 0 &&
            (pointInsideGeoLoop(&boundaryLoop, boundaryBBox,
                                &geoPolygon->holes[i].verts[0]) ||
             cellBoundaryCrossesGeoLoop(&(geoPolygon->holes[i]), &bboxes[i + 1],
                                        boundary, boundaryBBox))) {
            return false;
        }
    }
    return true;
}