Skip to content

Rewrite of CPR algorithms#37

Merged
mrksngl merged 3 commits intomainfrom
cpr
Mar 17, 2026
Merged

Rewrite of CPR algorithms#37
mrksngl merged 3 commits intomainfrom
cpr

Conversation

@mrksngl
Copy link
Copy Markdown
Member

@mrksngl mrksngl commented Mar 15, 2026

Note: this is a API breaking change!

API

  • class CompactPositionReporting deleted. Its two static methods (local and global decoding) are now part of CPREncodedPosition
  • Constructor of CPREncodedPosition has a new flag

It would be possible to supply @Deprecated versions for those 3 changes, but I don't think that anyone used those methods directly. Also any broken calls can easily be ported to the new API.

Changes

Not altering behavior

  • CPR was rewritten using fixed point integer math arithmetic which gives provably the same results of the standard's algorithm (which operates on reals)
  • speedup of the NL function
  • speedup for surface positions
  • speedup of minor special cases

All changes are done by mathematical equivalences and do not change the algorithms, except for cases where the old implementation produced wrong results due to limited precision (if any).

All tests have been adapted (API wise) and pass.

Altering behavior

  • Tests on timestamps for global decoding is now already part of method decodeGlobal, because the constraints on timestamps is actually a prerequisite of the algorithm to produce correct results.
    It is still possible to disable those tests having timestamp = null but it is not encouraged (nor used by libadsb).
  • Maximum gaps on timestamps are refined and now follow the standard
  • Global decoding will no longer emit invalid positions (e.g. latittude > 90) but rather return null (i.e. global decoding fails then)

Final note

The decodePosition method has been left as-is (some tests moved but are still all in effect).
The reasonable tests are still not compliant with // see A.1.7.10.2 of DO-260B, so you might want to change that comment. The tests are rather inspired by the standard.

@fixje
Copy link
Copy Markdown
Contributor

fixje commented Mar 16, 2026

It would be possible to supply @deprecated versions for those 3 changes, but I don't think that anyone used those methods directly. Also any broken calls can easily be ported to the new API.

ACK. The next release will already have breaking API changes. No need to keep old cruft.

@fixje fixje self-assigned this Mar 16, 2026
@fixje fixje added this to the v5 milestone Mar 16, 2026
@fixje fixje assigned mrksngl and unassigned fixje Mar 16, 2026
@mrksngl
Copy link
Copy Markdown
Member Author

mrksngl commented Mar 16, 2026

Additional Changes

  • static factory methods
  • mandatory timestamps for CPR. Will tackle upstream timestamps in a future PR
  • additional unit tests on timestamp gaps

@mrksngl mrksngl requested a review from fixje March 16, 2026 09:54
Copy link
Copy Markdown
Contributor

@fixje fixje left a comment

Choose a reason for hiding this comment

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

LGTM now

@mrksngl mrksngl merged commit 3f5a8a3 into main Mar 17, 2026
2 checks passed
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