Skip to content

fix: narrowing and implicit conversion fixes done by AI#5313

Open
asalzburger wants to merge 3 commits intoacts-project:mainfrom
asalzburger:fix-narrowing-implicit-conversion
Open

fix: narrowing and implicit conversion fixes done by AI#5313
asalzburger wants to merge 3 commits intoacts-project:mainfrom
asalzburger:fix-narrowing-implicit-conversion

Conversation

@asalzburger
Copy link
Copy Markdown
Contributor

Address Sonar implicit conversion and narrowing findings

*** This has been done using our SonarCloud output by cursor ***

Summary

This change set makes implicit numeric conversions explicit across Core, Alignment, and related headers/sources, targeting SonarCloud rules around implicit conversion and narrowing (integer precision loss, doublefloat, and std::size_t mixed with narrower index or arithmetic types). The intent is mechanical clarity for static analysis and alignment with strict floating-point warnings (for example -Wfloat-conversion), without altering algorithms.

Motivation

Sonar reported a large cluster of findings where:

  • std::size_t (or other wide integers) were used where API types expect int, trajectory index types, or float-backed binning.
  • Physical quantities expressed with UnitConstants (typically double) were assigned to float configuration fields without an explicit cast.
  • Arithmetic combined signed and unsigned index offsets in ways that are easy for analyzers to flag (for example std::size_t plus a negative int).

Making these conversions explicit documents intent and removes or reduces the corresponding static-analysis noise.

Approach

  • Prefer static_cast<T>(…) at boundaries (sizes to index types, integrals to double for division, double to float for stored parameters).
  • Use …f literals where a float is clearly intended.
  • For axis / neighborhood index math, use static_cast<int>(idx) before adding signed offsets, and static_cast<int>(getNBins()) where a narrow int range is required.
  • fastCathetus: promote hypotenuse to double before the difference/sum under sqrt so mixed-type call sites stay well defined.
  • hypotSquare was not changed to always return double; doing so altered deduced return types for fastHypot and broke a lambda that mixed fastHypot and scalar returns. Instead, BroadTripletSeedFilter’s getTopR lambda is explicitly -> float with static_cast<float>(fastHypot(…)).

Areas touched (high level)

Area Examples
Alignment χ² / ndf averaging: explicit double casts for counts.
Track fitting Kalman / GSF / smoother / updater: index types and float χ² assignment; fitter result indices aligned with TrackIndexType where applicable.
Event data Track/space-point containers, proxies: size() / distance → explicit index or uint32_t casts.
Propagator / material float paths: explicit casts from double or Eigen scalars.
Seeding / Seeding2 Config defaults with UnitConstants, GbTS filter literals, geometry numOfBins / numLayers, graph-seeder floats, triplet/doublet f suffixes.
Surfaces FacesHelper: anker and half-count geometry use explicit casts.
Track finding MeasurementSelector, TrackParamsLookupAccumulator: float χ₂ and double promotion for count-weighted parameters.
Utilities Axis, BinAdjustment (+ volume variant), BinningData, Polynomials (productdouble), MathHelpers (fastCathetus).
Vertexing GaussianGridTrackDensity config: binSize and literals.
Visualization EventDataView3D, Interpolation3D: loop indices promoted for double math.
Core sources Greedy ambiguity resolution ratios, ParticleData SEMF terms, seed/space-point reserve, VectorMultiTrajectory / VectorTrackContainer, geometry builders (Cuboid/Cylinder/LayerArray/CylinderVolumeHelper).

Verification

  • Local CMake (minimal preset-style) build with -Wfloat-conversion enabled in project flags: ActsCore and ActsAlignment link successfully.

Follow-up (optional)

  • Re-run Sonar and, if desired, mark matching issues Resolved in sc_issues.json (same housekeeping as for other rule batches).
  • narrowing_issues.tsv (~179 rows) was a one-off extract from an export; refresh or remove from the repo if it should not be tracked.

Related

  • Sonar rule families: implicit conversion, narrowing, floating-point precision in assignments.

--- END COMMIT MESSAGE ---

Any further description goes here, @-mentions are ok here!

  • Use a conventional commits prefix: quick summary
    • We mostly use feat, fix, refactor, docs, chore and build types.
  • A milestone will be assigned by one of the maintainers

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 3, 2026

📊: Physics performance monitoring for 70f10ca

Full contents

physmon summary

@paulgessinger
Copy link
Copy Markdown
Member

There's a number of new issues.

@asalzburger
Copy link
Copy Markdown
Contributor Author

There's a number of new issues.

Yeah, many of them are:

Replace the redundant type with "auto"

where SonarCloud is giving the opposite recommendation than Athena coding rules, as far as I remember.

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Apr 4, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants