Skip to content

Fix precision loss in cagnoli for edges crossing the antimeridian - #13

Merged
thevar1able merged 1 commit into
ClickHouse/v4.5.0from
antimeridian-cell-area
Oct 8, 2026
Merged

thevar1able merged 1 commit into
ClickHouse/v4.5.0from
antimeridian-cell-area

Conversation

@thevar1able

Copy link
Copy Markdown
Member

For an edge whose endpoints lie on opposite sides of ±180° the raw longitude difference in cagnoli is close to ±2π, and the true tiny step between the vertices is lost to the ulp of 2π before sin and cos are applied. Nothing cancels the error, so cells straddling the antimeridian at resolutions 12 and above come out too small: 0.07% at res 13, 0.4% at res 14, 2.5% at res 15 (cellAreaRads2 of the straddling cell vs. its neighbour).

The fix shifts both longitudes to the same side of the antimeridian before subtracting, so the difference is between two nearby values. sin and cos are 2π-periodic, so the result is unchanged mathematically. Global area sums at res 0–3 still equal 4π to within 5e-13. Of the cells used by the ClickHouse area tests only two antimeridian cells at res 0/1 change, in the 15th digit.

Adds a cell_area_antimeridian test with three straddling/neighbour cell pairs; it fails on the unpatched code and passes with the fix. testH3CellArea and testH3CellAreaExhaustive pass.

Regression from v4.5.0 (uber#1101), not present in v4.4.1 which used a different formula. To be reported upstream.

Closes: ClickHouse/ClickHouse#124447
Related: uber#1101
Related: uber#1108

🤖 Generated with Claude Code

For an edge whose endpoints lie on opposite sides of +-180 degrees the
raw longitude difference is close to +-2*pi, and the true tiny step
between the vertices is lost to the ulp of 2*pi before sin and cos are
applied. Nothing cancels the error, so cells straddling the antimeridian
at resolutions 12 and above come out up to 7.8% too small (res 15).

Shift both longitudes to the same side of the antimeridian before
subtracting, so the difference is between two nearby values. sin and cos
are 2*pi-periodic, so the result is unchanged mathematically. Global area
sums at res 0-3 still equal 4*pi to within 5e-13.

Regression from v4.5.0 (uber#1101), reported in
ClickHouse/ClickHouse#124447

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Konstantin Bogdanov seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@thevar1able
thevar1able merged commit d906e00 into ClickHouse/v4.5.0 Oct 8, 2026
1 check passed
clickgapai pushed a commit to clickgapai/ClickHouse that referenced this pull request Oct 19, 2026
Bump the h3 fork to pick up ClickHouse/h3#13: in h3 4.5.0 cellAreaRads2 sums
Cagnoli terms over the cell edges, and for an edge crossing the antimeridian
the raw longitude difference is close to 2*pi, losing the tiny true step to
its ulp. Cells straddling the antimeridian at resolutions >= 12 came out up
to 7.8% smaller than their neighbours at res 15.

Closes: ClickHouse#124447

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants