Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions h3_postgis/src/wkb_indexing.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,22 @@ void
void
boundary_split_180_polar(const CellBoundary * boundary, CellBoundary * res);

/* Adds one vertex while preserving the fixed CellBoundary capacity. */
static void
boundary_add_vert(CellBoundary * boundary, const LatLng * vert);

static void
boundary_add_vert(CellBoundary * boundary, const LatLng * vert)
{
const int maxVerts = sizeof(boundary->verts) / sizeof(boundary->verts[0]);

SPLIT_ASSERT(
boundary->numVerts < maxVerts,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Use a larger split buffer for seam vertices

When a valid H3 boundary already uses more than six of CellBoundary's fixed vertex slots, the polar splitter appends the original vertices plus four synthetic antimeridian/pole vertices; this new guard turns those cases into Cell boundary split exceeds CellBoundary vertex capacity errors for h3_cell_to_boundary_wkb/geometry instead of producing the boundary. The bounds check needs to be paired with a split representation sized for the extra seam vertices, otherwise high-resolution polar or distorted antimeridian cells remain unusable.

Useful? React with 👍 / 👎.

"Cell boundary split exceeds CellBoundary vertex capacity");

boundary->verts[boundary->numVerts++] = *vert;
}

/*
* Serialize one H3 cell boundary to WKB.
*
Expand Down Expand Up @@ -166,7 +182,7 @@ boundary_split_180(const CellBoundary * boundary, CellBoundary * part1, CellBoun
part = (lon < 0) ? part1 : part2;

/* Add current vertex */
part->verts[part->numVerts++] = verts[v];
boundary_add_vert(part, &verts[v]);

if (SIGN(lon) != SIGN(nextLon))
{
Expand All @@ -182,11 +198,11 @@ boundary_split_180(const CellBoundary * boundary, CellBoundary * part1, CellBoun

/* Add split point */
/* current part */
part->verts[part->numVerts++] = vert;
boundary_add_vert(part, &vert);
/* next part */
vert.lng = -vert.lng;
part = (part == part1) ? part2 : part1;
part->verts[part->numVerts++] = vert;
boundary_add_vert(part, &vert);
}
}
}
Expand All @@ -205,7 +221,7 @@ boundary_split_180_polar(const CellBoundary * boundary, CellBoundary * res)
double nextLon;

/* Add current vertex */
res->verts[res->numVerts++] = verts[v];
boundary_add_vert(res, &verts[v]);

lon = verts[v].lng;
nextLon = verts[next].lng;
Expand All @@ -225,17 +241,17 @@ boundary_split_180_polar(const CellBoundary * boundary, CellBoundary * res)
/* Add intersection point */
vert.lat = splitLat;
vert.lng = (lon < 0) ? -M_PI : M_PI;
res->verts[res->numVerts++] = vert;
boundary_add_vert(res, &vert);

/* Add points on antimeridian near the pole */
vert.lat = SIGN(vert.lat) * ABS_LAT_MAX;
res->verts[res->numVerts++] = vert;
boundary_add_vert(res, &vert);
vert.lng = -vert.lng;
res->verts[res->numVerts++] = vert;
boundary_add_vert(res, &vert);

/* Add intersection point */
vert.lat = splitLat;
res->verts[res->numVerts++] = vert;
boundary_add_vert(res, &vert);
}
}
}
Loading