Skip to content

Use Eriksson's formula for acute triangle areas - #670

Open
jagrutipatilp wants to merge 1 commit into
google:masterfrom
jagrutipatilp:area-eriksson-fast-path
Open

Use Eriksson's formula for acute triangle areas#670
jagrutipatilp wants to merge 1 commit into
google:masterfrom
jagrutipatilp:area-eriksson-fast-path

Conversation

@jagrutipatilp

Copy link
Copy Markdown

Addresses #190.

Summary

  • Use Eriksson's one-atan2 spherical excess formula when all three triangle edges are at most 90 degrees.
  • Compute the determinant from (b - a) x (c - a) to retain relative accuracy for small triangles.
  • Keep the existing l'Huilier/Girard implementation for triangles with an obtuse or near-antipodal edge, where Eriksson's denominator can become ill-conditioned.
  • Update the existing near-degenerate regression to check its 100-digit reference area rather than accepting zero.
  • Add acute and fallback-path microbenchmarks.

Numerical validation

A 100,000-triangle comparison against a 100-decimal-digit oracle covered well-shaped, tiny, randomly rotated skinny, and near-90-degree triangles. The largest observed absolute candidate error was 8.88e-16, below the documented 5e-15 maximum error.

An unguarded formula was also tested on near-antipodal inputs and produced errors as large as 0.65 steradians. The pairwise non-negative dot-product guard avoids that unstable region and leaves those triangles on the existing implementation.

Benchmark results

Release build, LLVM 23.1.0, x86-64 Windows; five repetitions:

Input Existing median CPU This change median CPU Ratio
Small acute 140 ns 27.6 ns 5.1x faster
Large acute 160 ns 43.6 ns 3.7x faster
Obtuse fallback 267 ns 302 ns 1.13x slower

The fallback overhead is the cost of the three pairwise dot-product checks.

Tests

  • s2measures_test
  • s2loop_measures_test
  • s2shape_measures_test
  • s2shape_index_measures_test
  • Full project compilation
  • 122 of 123 test executables passed locally. The remaining unrelated ExactFloatTest.frexp case expects glibc's NaN/Infinity exponent behavior and fails with the Windows MinGW C runtime.

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.

1 participant