refactor(association,viz): bring cluster_tracks and render_track_list under S3776 - #157
Conversation
… under S3776 SonarCloud rust:S3776 reported cognitive complexity 17 (limit 15) for jpda.rs::cluster_tracks and thresh-viz app.rs::render_track_list, the project's only two open Sonar issues. - cluster_tracks: hoist the nested find/union fns to module level (Sonar charges nested fns to the enclosing function at +1 nesting) and split the union / group-by-root / collect-detections phases into helpers. Loop bodies are moved verbatim: same iteration order, same union direction, no new allocation. cluster_tracks is now 0; the largest helper is 11. The function is union-find over a boolean gating matrix: no floating-point code is touched. - render_track_list: extract render_track_row for the per-row body (2 and 7). - Tests: pin the full output of cluster_tracks on a fixed case (added and passing before the refactor); a non-square case with a two-level forest, which is the only test that fails when the two counts are swapped or when grouping skips the root lookup; focused tests per helper; and a headless egui_kittest test for the row click-to-select toggle through a new ThreshVizApp::selected_track() accessor. No behaviour change: old and new cluster_tracks agree on 300,000 seeded random gating matrices (278,355 non-square). Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01C53cGKw2kFHBrY6cy4tRnP
|
Warning Review limit reachedNext included review available in 59 minutes. View limit detailsLimit details: You’ve used the included review currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (4)
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. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|



Why
SonarCloud has two open issues on the project, both
rust:S3776(cognitive complexity 17, limit 15):crates/thresh-association/src/jpda.rs::cluster_tracksandcrates/thresh-viz/src/app.rs::render_track_list. The quality gate is still OK, but these are the only two open issues, andopenspec/specs/cognitive-complexityand CONTRIBUTING both set 15 as the limit.What
Same phase-helper decomposition as #78, no suppressions, no threshold changes.
cluster_tracks(17 -> 0). The nestedfind/unionfunctions move to module level asfind_root/union_sets: Sonar charges a nested fn's body to the enclosing function at +1 nesting, which alone was 4 of the 17. The three phases becomeunion_tracks_sharing_detections(11),group_tracks_by_root(1) andcollect_cluster_detections(1). Loop bodies are moved verbatim: same iteration order, same union direction (parent[rb] = ra), sameHashMap, nothing cloned. This function is union-find over a boolean gating matrix, so no floating-point code is touched; the numerical JPDA functions in the file are unchanged.render_track_list(17 -> 2). The per-row body becomesrender_track_row(7), verbatim apart from takingidandconfirmedby value andclassasOption<&str>.The counting model was checked against SonarCloud's own per-line increments for both issues, which it reproduces exactly; Sonar's number for the new code appears when it analyses this PR.
Evidence that behaviour is unchanged
git show HEAD:) and newcluster_trackscompared on 300,000 seeded random gating matrices (0-13 tracks and detections, 1-70 % density, extra rows, 278,355 non-square): identical after normalising cluster order. Run twice, independently, by the agent that made the change (200,000) and the one that tried to refute it (300,000). The harness is not in the tree, since a copy of the old function would itself be flagged.n_tracksignored, and no tracks.n_tracks/n_detsat the call site, and grouping byparent[i]instead of the root. Every case was square with a flat forest.test_cluster_tracks_non_square_two_level_forest(3 tracks, 2 detections, forest[0, 0, 1]) now fails on both, and passes on the original function.egui_kittesttest,clicking_track_row_toggles_selection, through a newThreshVizApp::selected_track()accessor (same pattern asellipses_shown()and the other test accessors). It passed before the refactor and fails when the toggle is broken.Checks
cargo fmt --all -- --checkcargo clippy -p thresh-association -p thresh-viz --all-targets -- -D warnings, and again with-p thresh-viz --features gui, which is the run that actually compilesapp.rscargo test -p thresh-association: 55 passed.cargo test -p thresh-viz --features gui: 41 + 6 + 1 passed.RUSTDOCFLAGS=-Dwarnings cargo docfor both crates.cluster_trackshas no callers outside its own tests.For you to decide
cargo clippy --workspaceandcargo test --workspacerun without--features gui, soapp.rs,streaming.rs,theme.rsand all six kittest tests (the five existing ones too) are compiled out;viz-buildonly builds. The new click test therefore runs only locally. Acargo test -p thresh-viz --features guistep inviz-build, where Linux already installs the GUI packages, would close it. Not added here.let _ = status;). Moved verbatim; deleting it or drawing the icon is a UI decision.cluster_tracksreturns varies from run to run (HashMapwithRandomState), before and after. Contents are deterministic and now pinned. ABTreeMapwould make the order reproducible if a caller ever needs that.selected_track()is a small addition to the public API; it is in the CHANGELOG line.cognitive-complexityspec lists six functions by name and Fix all 19 SonarCloud cognitive complexity violations #78 fixed nineteen without adding to it. Say if you want these two named there.OpenSpec Validateis expected to be red until #155 merges.🤖 Generated with Claude Code
https://claude.ai/code/session_01C53cGKw2kFHBrY6cy4tRnP