Skip to content

Add GeographicLib v2.4 parity for trig accuracy, Hypot3, and Jacobi amplitude#2

Draft
Copilot wants to merge 3 commits intomasterfrom
copilot/update-library-to-v2-4-feature-parity
Draft

Add GeographicLib v2.4 parity for trig accuracy, Hypot3, and Jacobi amplitude#2
Copilot wants to merge 3 commits intomasterfrom
copilot/update-library-to-v2-4-feature-parity

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 30, 2026

This updates the C# port to cover the user-visible GeographicLib v2.4 library delta from the upstream C++ release. The parity work focuses on the new math APIs and the exact-angle trigonometric behavior changes introduced in v2.4.

  • v2.4 math parity

    • Added MathEx.Hypot3(double x, double y, double z).
    • Added EllipticFunction.Am(double x) and EllipticFunction.Am(double x, out double sn, out double cn, out double dn).
  • Exact-angle trig behavior

    • Updated MathEx.Sind, MathEx.Cosd, MathEx.SinCosd, and MathEx.SinCosde to return the upstream v2.4 exact reduced-angle values for multiples of 30°, 45°, and 60°.
    • Centralized the special-case handling to keep the implementation consistent across all degree-based trig entry points.
  • Regression coverage

    • Added focused tests for:
      • exact-angle Sind/Cosd/SinCosd/SinCosde results,
      • Hypot3,
      • EllipticFunction.Am special cases and consistency with Sncndn / inverse F.
    • Updated the rhumb near-pole golden value affected by the more accurate trig reduction.
  • Version documentation

    • Added a 2.4.0 changelog entry in README.md summarizing the parity additions.

Example of the new v2.4 surface:

MathEx.SinCosd(45, out var s, out var c);
// s == 0.7071067811865476
// c == 0.7071067811865476

var h = MathEx.Hypot3(3, 4, 12);
// h == 13

var ell = new EllipticFunction(0.5);
var phi = ell.Am(1.25, out var sn, out var cn, out var dn);

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • geographiclib.sourceforge.io
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node /home/REDACTED/work/_temp/ghcca-node/node/bin/node --enable-source-maps /home/REDACTED/work/_temp/copilot-developer-action-main/dist/index.js (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI linked an issue Mar 30, 2026 that may be closed by this pull request
Copilot AI and others added 2 commits March 30, 2026 13:48
Agent-Logs-Url: https://github.com/habizdev/GeographicLib.NET/sessions/c8e70dc3-399a-43d9-9694-d0cb700f65bb

Co-authored-by: AgileJoshua <564800+AgileJoshua@users.noreply.github.com>
Agent-Logs-Url: https://github.com/habizdev/GeographicLib.NET/sessions/c8e70dc3-399a-43d9-9694-d0cb700f65bb

Co-authored-by: AgileJoshua <564800+AgileJoshua@users.noreply.github.com>
Copilot AI changed the title [WIP] Update library to v2.4 feature parity Add GeographicLib v2.4 parity for trig accuracy, Hypot3, and Jacobi amplitude Mar 30, 2026
Copilot AI requested a review from AgileJoshua March 30, 2026 13:54
@AgileJoshua AgileJoshua requested a review from Copilot March 30, 2026 17:27
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates the C# GeographicLib port to align with upstream GeographicLib v2.4 math surface and exact-angle degree-based trig behavior.

Changes:

  • Added MathEx.Hypot3 and EllipticFunction.Am (Jacobi amplitude) APIs.
  • Updated degree-based trig entry points (Sind, Cosd, SinCosd, SinCosde) to return upstream v2.4 exact reduced-angle results for special angles.
  • Added/updated regression tests and README changelog entry reflecting the v2.4 parity work.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
README.md Adds a 2.4.0 (unreleased) changelog entry describing new APIs and trig behavior fix.
GeographicLib/MathEx.cs Introduces Hypot3 and centralized special-angle handling for degree trig functions.
GeographicLib/EllipticFunction.cs Exposes new public Am overloads forwarding to the private implementation.
GeographicLib/EllipticFunction.Priv.cs Implements Jacobi amplitude Am and Am(..., out sn, out cn, out dn).
GeographicLibTests/MathExTests.cs Adds exact-angle trig assertions and Hypot3 tests.
GeographicLibTests/EllipticFunctionTests.cs Adds tests for Am special cases and consistency with Sncndn / inverse F.
GeographicLibTests/RhumbSolveTests.cs Updates a near-pole golden value impacted by the trig changes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

if (!(c[l] > tol * a[l]))
break;
}

Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

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

In Am, the AGM loop can exit because l reaches num_ (when GEOGRAPHICLIB_PANIC is false and the convergence test never triggers). In that case l == num_ and the subsequent a[l]/c[l] indexing will throw IndexOutOfRangeException. Please clamp l to num_ - 1 (or decrement when the loop ends via the iteration limit), or allocate a/c with length num_ + 1 to make the indexing safe on non-convergence paths.

Suggested change
if (l >= num_)
l = num_ - 1;

Copilot uses AI. Check for mistakes.
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.

Update library to v2.4 feature parity

3 participants