h3 icon indicating copy to clipboard operation
h3 copied to clipboard

Two neighbor cells give error with "cellsToLinkedMultiPolygon"

Open benguild opened this issue 3 months ago • 6 comments

Hi, I was playing around with this, and noticed that there seems to be a bug with two neighboring cells in the ocean?

Minimal C Example

#include <stdio.h>
#include <h3api.h>

int main() {
    H3Index cells[2] = {
        0x8001fffffffffff,  // 577445914721910783 in decimal
        0x8003fffffffffff   // 577903311559065599 in decimal

        // This pair also fails:
        // 0x8037fffffffffff,
        // 0x8051fffffffffff
    };

    // VALID…
    for (int i = 0; i < 2; i++) {
        if (!isValidCell(cells[i])) {
            printf("Cell %d is invalid\n", i);
            return 1;
        }
        printf("Cell %d: Valid, Resolution %d\n", i, getResolution(cells[i]));
    }

    int areNeighbors = areNeighborCells(cells[0], cells[1]);
    printf("Cells are neighbors: %s\n", areNeighbors ? "Yes" : "No");

    // WORKS…
    for (int i = 0; i < 2; i++) {
        LinkedGeoPolygon polygon;
        H3Error error = cellsToLinkedMultiPolygon(&cells[i], 1, &polygon);

        if (error == E_SUCCESS) {
            printf("  Cell %d: ✓ Success\n", i);
            destroyLinkedMultiPolygon(&polygon);
        } else {
            printf("  Cell %d: ✗ Failed (error %d)\n", i, error);
        }
    }

    // FAILS…
    LinkedGeoPolygon polygon;
    H3Error error = cellsToLinkedMultiPolygon(cells, 2, &polygon);

    if (error == E_SUCCESS) {
        printf("  Both cells: ✓ Success\n");
        destroyLinkedMultiPolygon(&polygon);
    } else {
        printf("  Both cells: ✗ Failed (error %d)\n", error);
    }

    return 0;
}

benguild avatar Sep 29 '25 18:09 benguild

Note that these two cells are near the antimeridian, so it may be due to that.

benguild avatar Sep 30 '25 17:09 benguild

I also note these two cells seem to be polar: https://h3geo.org/#hex=8001fffffffffff+8003fffffffffff

isaacbrodsky avatar Sep 30 '25 21:09 isaacbrodsky

Possibly would be fixed by #922? We should add a test case there

isaacbrodsky avatar Sep 30 '25 23:09 isaacbrodsky

I updated my original post with an additional pair of cells specifically highlighting that ~antimeridian~ issue without being polar.

benguild avatar Oct 01 '25 04:10 benguild

Related: #1049

benguild avatar Oct 01 '25 06:10 benguild

This is a bug I'd like to fix sooner rather than later. I'm starting to take a look at #1049 and #922 to see if I can help out.

ajfriend avatar Oct 13 '25 15:10 ajfriend