utils: normalize AngleDiffDeg before folding about 180 - #6324
Merged
Nicolas Palpacuer (NickPPC) merged 2 commits intoSep 1, 2026
Conversation
AngleDiffDeg folded the raw separation, so any pair more than 360 apart produced a negative "difference": AngleDiffDeg(0, 370) returned -10 and AngleDiffDeg(720, 10) returned -350. An angular difference must lie in [0, 180]. Wrap the separation into [0, 360) before folding. Behaviour is unchanged for inputs already within one revolution of each other, which is why this went unnoticed. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Nicolas Palpacuer (NickPPC)
marked this pull request as ready for review
August 3, 2026 19:09
Nicolas Palpacuer (NickPPC)
requested a review
from Steve Briskin (stevebriskin)
August 3, 2026 19:09
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Nicolas Palpacuer (NickPPC)
requested a review
from Vijay Vuyyuru (vijayvuyyuru)
September 1, 2026 15:23
Vijay Vuyyuru (vijayvuyyuru)
approved these changes
Sep 1, 2026
Nicolas Palpacuer (NickPPC)
deleted the
fix-angle-diff-deg-normalization
branch
September 1, 2026 15:48
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
AngleDiffDegreturns negative values for angles more than one revolution apart. An angular difference must lie in[0, 180].From the audit that produced #6314–#6323.
Why this is fixed rather than deleted
It has no callers inside this repository, so under the delete-vs-fix rule it would be a removal candidate. But a code search across
viamrobotics,viam-modulesandviam-labsfound a real external consumer:viam-labs/stevebriskin-projects(rovie/go/rovie.go) calls it three times, on yaw and heading values:Heading and yaw are exactly the quantities that drift outside
[0, 360), so it gets repaired.The bug
Folding about 180 is only valid once the separation is inside one revolution.
|a1-a2|was used raw, so a separation of 370 folded to180 - |370-180| = -10.Now the separation is wrapped into
[0, 360)first, then folded. The function stays commutative, and behaviour is unchanged for inputs already within one revolution of each other — which is why this went unnoticed.Testing
go test ./...across the whole repo passes;golangci-lintclean.Extended the existing table with out-of-range inputs:
(0, 370),(720, 10),(400, 30),(-370, 0),(-180, 180),(1080, 0),(-1000, 1000), plus the commuted forms. Six of the new cases fail against the unpatched source, returning-10,-350and similar.Tickets
None
Claude Code Prompts Used
🤖 Generated with Claude Code