Skip to content

Conversation

@LachlanConn
Copy link
Contributor

Floating point precision caused some errors in indexing and left some of the vertices in the array as 0 causing the arc to draw lines to origin.

Floating point precision caused some errors in indexing and left some of the vertices in the array as 0 causing the arc to draw lines to origin.
Copy link

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

This PR fixes a floating point precision issue in the HUD arc drawing functionality that was causing vertices to be incorrectly indexed, resulting in lines being drawn to the origin. The fix changes the loop iterator from a float to an integer to eliminate precision errors.

Key Changes

  • Changed loop variable from float i = start to int i = 0 to avoid floating point precision issues
  • Updated trigonometric calculations to add start offset to the integer loop variable
  • Simplified array indexing from (int)((i - start) * 2) to i * 2, eliminating casting and subtraction that could accumulate errors

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

float x = 0, y = 0;
int length = 0;
for (float i = start; i <= start + degrees; i++)
for (int i = 0; i <= degrees; i++)
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

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

The loop condition i <= degrees compares an integer with a float parameter. If degrees is a non-integer value (e.g., 45.5), the loop will iterate 45 times instead of covering the full arc span. Consider using i <= (int)degrees or better yet, change the logic to iterate based on the ceiling of degrees to ensure the full arc is drawn.

Copilot uses AI. Check for mistakes.
vertices[(int)((i - start) * 2 + 1)] = y;
vertices[i * 2] = x;
vertices[i * 2 + 1] = y;
length += 2;
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

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

The length variable is incremented in each iteration but could be calculated more simply as length = (i + 1) * 2 after the loop, or determined directly from the number of iterations. The incremental approach is redundant since the final length is deterministic based on the loop iterations.

Copilot uses AI. Check for mistakes.
@LachlanConn
Copy link
Contributor Author

For Testing I ran a sim and grabbed the tlog then ran that tlog on this PR vs Master.
Here is a side by side of a sort of synced up tlog give or take the speed it took me to press play.

PR3654_test.mp4

@meee1 meee1 merged commit 666e696 into ArduPilot:master Jan 14, 2026
9 of 12 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