Skip to content

Bugfix area calculations in the NavGenerator#7104

Merged
BlackYps merged 2 commits into
FAForever:developfrom
PreciseBump38:fix/navgen-area-calculations
May 17, 2026
Merged

Bugfix area calculations in the NavGenerator#7104
BlackYps merged 2 commits into
FAForever:developfrom
PreciseBump38:fix/navgen-area-calculations

Conversation

@PreciseBump38
Copy link
Copy Markdown
Contributor

@PreciseBump38 PreciseBump38 commented May 5, 2026

Patches two bugs in lua/sim/NavGenerator.lua affecting NavLabelMetadata Area calculations.

  • Incorrect conversion to KM meant 4x underestimation of area
  • Multiple counting of leaves meant roughly 4x overestimation of area
    These were combining to make plausibly correct but slightly wrong numbers.

This commit also changes some of the variable naming for Area calculations within the NavTree - these currently represent proportions of area covered (i.e. not absolute values). By doing the calculation on ogrid sizes we can also avoid all conversion to KM in that part of the code, which makes for a teeny-tiny performance gain.

Summary by CodeRabbit

  • Refactor
    • Overhauled navigation area calculations to use a consistent conversion and proportion-based sizing for labels and sections, improving accuracy.
  • Bug Fixes
    • Fixed incorrect area computation in the navigation mesh; results may differ from prior values by about ±15%.
  • Changelog
    • Added entry documenting the area computation fix (issue reference omitted).

Two fixes to label area calculations:
- Correct constant for converting ogrid units to KM
- Correct DFS algorithm for summing leaf sizes

Also renamed some functions and variables associated with tree and section area calculations - these are actually calculating area proportions not KM squared values.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 5, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 36c4204b-1fa9-4d83-9bed-f5668e7396b7

📥 Commits

Reviewing files that changed from the base of the PR and between 51c42c7 and 749621f.

📒 Files selected for processing (1)
  • changelog/snippets/fix.7104.md
✅ Files skipped from review due to trivial changes (1)
  • changelog/snippets/fix.7104.md

📝 Walkthrough

Walkthrough

Refactors nav-label area calculations in NavGenerator.lua: adds an oGrid²→km² constant, switches label/section Area to proportions based on raw size^2 ratios, updates neighbor-filtering to compare proportions, and renames/rewrites the area helper to ComputeLabelAreaProportion.

Changes

Nav-Label Area Calculation Refactoring

Layer / File(s) Summary
Constant Definition
lua/sim/NavGenerator.lua
Adds OGridSquaredToKMSquared = 0.02 * 0.02 conversion constant.
GenerateLabels Updates
lua/sim/NavGenerator.lua (lines 828–858, 879–894)
Replaces previous absolute area accumulation ((0.01*size)^2) with size * size * oGridSquaredToKMSquared when building label metadata during label generation.
Core Data Shape
lua/sim/NavGenerator.lua (lines 1607–1611)
Replaces precomputed absolute area with overallSizeSquared = size * size as the basis for later proportion calculations.
Core Calculation
lua/sim/NavGenerator.lua (lines 1742–1771)
Replaces ComputeLabelArea with ComputeLabelAreaProportion, computing tree.Labels[label] and section.Area as sum(leaf.Size^2) / overallSizeSquared.
Neighbor Filtering
lua/sim/NavGenerator.lua (lines 1774–1793)
Updates neighbor selection to use thresholdAreaProportion = 0.05 and compare neighborSection.Area > thresholdAreaProportion (proportional comparison).
Integration / Phase Call
lua/sim/NavGenerator.lua (lines 1811–1812)
Phase-1 invocation updated to call ComputeLabelAreaProportion(tree) instead of the old helper.
Changelog
changelog/snippets/fix.7104.md
Adds entry for issue #7104 noting area computation fix and that values may differ by ±15%.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 In grids of oGrid where small squares play,

I count each size² and tuck old units away.
Proportions hum softly, neighbors now true,
A tiny conversion — a clearer view.
Hop, label, hop — the nav fields renew.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: fixing area calculation bugs in the NavGenerator, which aligns with the primary intent of the PR.
Description check ✅ Passed The description provides a clear explanation of the bugs fixed and implementation changes, includes a changelog entry, and addresses reviewer feedback. All critical information is present.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
lua/sim/NavGenerator.lua (1)

1526-1526: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Cull threshold 0.16 may need recalibration after area-calculation corrections.

The two bugs previously cancelled non-uniformly (DFS double-counting is proportional to each leaf's neighbor count, not a flat 4×), so NavLabelMetadata.Area per label will shift by a connectivity-dependent factor after this fix. The 0.16 km² threshold was tuned against the old (imperfectly-cancelled) values — double-check that it remains the intended cutoff with the now-correct area values.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lua/sim/NavGenerator.lua` at line 1526, The hardcoded cull threshold 0.16 in
the conditional that checks metadata.Area (alongside metadata.NumberOfExtractors
and metadata.NumberOfHydrocarbons) was tuned against the old buggy area
calculation and may no longer be valid; re-evaluate and adjust this cutoff by
running area-distribution tests on NavLabelMetadata.Area after the
area-calculation fix, then replace the literal 0.16 in the if (metadata.Area <
0.16 and metadata.NumberOfExtractors == 0 and metadata.NumberOfHydrocarbons ==
0) check with an updated threshold or a configurable constant (e.g.,
cullAreaThreshold) and document the chosen value and test results.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@lua/sim/NavGenerator.lua`:
- Line 1526: The hardcoded cull threshold 0.16 in the conditional that checks
metadata.Area (alongside metadata.NumberOfExtractors and
metadata.NumberOfHydrocarbons) was tuned against the old buggy area calculation
and may no longer be valid; re-evaluate and adjust this cutoff by running
area-distribution tests on NavLabelMetadata.Area after the area-calculation fix,
then replace the literal 0.16 in the if (metadata.Area < 0.16 and
metadata.NumberOfExtractors == 0 and metadata.NumberOfHydrocarbons == 0) check
with an updated threshold or a configurable constant (e.g., cullAreaThreshold)
and document the chosen value and test results.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: fea86038-4c03-430c-8bbb-e8fc60a4369d

📥 Commits

Reviewing files that changed from the base of the PR and between 3868ca8 and 51c42c7.

📒 Files selected for processing (1)
  • lua/sim/NavGenerator.lua

@Garanas Garanas added the area: nav-mesh related to navigational mesh label May 5, 2026
@Garanas
Copy link
Copy Markdown
Member

Garanas commented May 5, 2026

It just needs a changelog snippet

@Garanas Garanas requested a review from BlackYps May 6, 2026 04:38
@BlackYps BlackYps merged commit 2d3c23e into FAForever:develop May 17, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: nav-mesh related to navigational mesh

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants