Skip to content

Commit

Permalink
removing most of the SonarCloud issues
Browse files Browse the repository at this point in the history
  • Loading branch information
asalzburger committed Aug 29, 2024
1 parent 586ed6a commit a40b6de
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 38 deletions.
6 changes: 3 additions & 3 deletions Core/include/Acts/Navigation/NavigationStream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,14 @@ class NavigationStream {
/// @param surface the surface to be filled
/// @param bTolerance the boundary tolerance used for the intersection
void addSurfaceCandidate(const Surface* surface,
BoundaryTolerance bTolerance);
const BoundaryTolerance& bTolerance);

/// Fill n surfaces into the candidate vector
///
/// @param surfaces the surfaces that are filled in
/// @param bTolerance the boundary tolerance used for the intersection
void addSurfaceCandidates(const std::vector<const Surface*>& surfaces,
BoundaryTolerance bTolerance);
const BoundaryTolerance& bTolerance);

/// Fill one portal into the candidate vector
///
Expand All @@ -151,7 +151,7 @@ class NavigationStream {
/// @return true if the stream is active, false indicates that there are no valid candidates
bool initialize(const GeometryContext& gctx,
const NavigationStream::QueryPoint& queryPoint,
BoundaryTolerance cTolerance,
const BoundaryTolerance& cTolerance,
ActsScalar onSurfaceTolerance = s_onSurfaceTolerance);

/// Convenience method to update a stream from a new query point,
Expand Down
69 changes: 34 additions & 35 deletions Core/src/Navigation/NavigationStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,31 @@
#include "Acts/Detector/Portal.hpp"
#include "Acts/Surfaces/Surface.hpp"

bool Acts::NavigationStream::initialize(
const GeometryContext& gctx, const NavigationStream::QueryPoint& queryPoint,
BoundaryTolerance cTolerance, ActsScalar onSurfaceTolerance) {
#include <algorithm>

bool Acts::NavigationStream::initialize(const GeometryContext& gctx,
const QueryPoint& queryPoint,
const BoundaryTolerance& cTolerance,
ActsScalar onSurfaceTolerance) {
// Position and direction from the query point
const Vector3& position = queryPoint.position;
const Vector3& direction = queryPoint.direction;

// De-duplicate first (necessary to deal correctly with multiple
// intersections) - sort them by surface pointer
std::sort(m_candidates.begin(), m_candidates.end(),
[](const NavigationStream::Candidate& a,
const NavigationStream::Candidate& b) {
return (&a.surface()) < (&b.surface());
});
std::ranges::sort(m_candidates, [](const Candidate& a, const Candidate& b) {
return (&a.surface()) < (&b.surface());
});
// Remove duplicates on basis of the surface pointer
m_candidates.erase(std::unique(m_candidates.begin(), m_candidates.end(),
[](const NavigationStream::Candidate& a,
const NavigationStream::Candidate& b) {
[](const Candidate& a, const Candidate& b) {
return (&a.surface()) == (&b.surface());
}),
m_candidates.end());

// A container collecting additional candidates from multiple
// valid interseciton
std::vector<NavigationStream::Candidate> additionalCandidates = {};
std::vector<Candidate> additionalCandidates = {};
for (auto& [sIntersection, portal, bTolerance] : m_candidates) {
// Get the surface from the object intersection
const Surface* surface = sIntersection.object();
Expand All @@ -46,7 +46,7 @@ bool Acts::NavigationStream::initialize(
// Split them into valid intersections, keep track of potentially
// additional candidates
bool originalCandidateUpdated = false;
for (auto& rsIntersection : multiIntersection.split()) {
for (const auto& rsIntersection : multiIntersection.split()) {
// Skip negative solutions, respecting the on surface tolerance
if (rsIntersection.pathLength() < -onSurfaceTolerance) {
continue;
Expand All @@ -57,8 +57,8 @@ bool Acts::NavigationStream::initialize(
sIntersection = rsIntersection;
originalCandidateUpdated = true;
} else {
additionalCandidates.push_back(
NavigationStream::Candidate{rsIntersection, portal, bTolerance});
additionalCandidates.emplace_back(
Candidate{rsIntersection, portal, bTolerance});
}
}
}
Expand All @@ -69,16 +69,14 @@ bool Acts::NavigationStream::initialize(
additionalCandidates.end());

// Sort the candidates by path length
std::sort(m_candidates.begin(), m_candidates.end(),
NavigationStream::Candidate::pathLengthOrder);
std::ranges::sort(m_candidates, Candidate::pathLengthOrder);

// The we find the first invalid candidate
auto firstInvalid =
std::find_if(m_candidates.begin(), m_candidates.end(),
[](const NavigationStream::Candidate& a) {
const auto& [aIntersection, aPortal, aTolerance] = a;
return !aIntersection.isValid();
});
std::ranges::find_if(m_candidates, [](const Candidate& a) {
const auto& [aIntersection, aPortal, aTolerance] = a;
return !aIntersection.isValid();
});

// Set the range and initialize
m_candidates.resize(std::distance(m_candidates.begin(), firstInvalid));
Expand All @@ -90,25 +88,25 @@ bool Acts::NavigationStream::initialize(
return true;
}

bool Acts::NavigationStream::update(
const GeometryContext& gctx, const NavigationStream::QueryPoint& queryPoint,
ActsScalar onSurfaceTolerance) {
bool Acts::NavigationStream::update(const GeometryContext& gctx,
const QueryPoint& queryPoint,
ActsScalar onSurfaceTolerance) {
// Position and direction from the query point
const Vector3& position = queryPoint.position;
const Vector3& direction = queryPoint.direction;

// Loop over the (currently valid) candidates and update
for (; m_currentIndex < m_candidates.size(); ++m_currentIndex) {
// Get the candidate, and resolve the tuple
NavigationStream::Candidate& candidate = currentCandidate();
Candidate& candidate = currentCandidate();
auto& [sIntersection, portal, bTolerance] = candidate;
// Get the surface from the object intersection
const Surface* surface = sIntersection.object();
// (re-)Intersect the surface
auto multiIntersection = surface->intersect(gctx, position, direction,
bTolerance, onSurfaceTolerance);
// Split them into valid intersections
for (auto& rsIntersection : multiIntersection.split()) {
for (const auto& rsIntersection : multiIntersection.split()) {
// Skip wrong index solution
if (rsIntersection.index() != sIntersection.index()) {
continue;
Expand All @@ -124,30 +122,31 @@ bool Acts::NavigationStream::update(
return false;
}

void Acts::NavigationStream::addSurfaceCandidate(const Surface* surface,
BoundaryTolerance bTolerance) {
m_candidates.push_back(Candidate{
void Acts::NavigationStream::addSurfaceCandidate(
const Surface* surface, const BoundaryTolerance& bTolerance) {
m_candidates.emplace_back(Candidate{
ObjectIntersection<Surface>::invalid(surface), nullptr, bTolerance});
}

void Acts::NavigationStream::addSurfaceCandidates(
const std::vector<const Surface*>& surfaces, BoundaryTolerance bTolerance) {
std::for_each(surfaces.begin(), surfaces.end(), [&](const auto* surface) {
m_candidates.push_back(Candidate{
const std::vector<const Surface*>& surfaces,
const BoundaryTolerance& bTolerance) {
std::ranges::for_each(surfaces, [&](const auto* surface) {
m_candidates.emplace_back(Candidate{
ObjectIntersection<Surface>::invalid(surface), nullptr, bTolerance});
});
}

void Acts::NavigationStream::addPortalCandidate(const Portal* portal) {
m_candidates.push_back(
m_candidates.emplace_back(
Candidate{ObjectIntersection<Surface>::invalid(&(portal->surface())),
portal, BoundaryTolerance::None()});
}

void Acts::NavigationStream::addPortalCandidates(
const std::vector<const Portal*>& portals) {
std::for_each(portals.begin(), portals.end(), [&](const auto& portal) {
m_candidates.push_back(
std::ranges::for_each(portals, [&](const auto& portal) {
m_candidates.emplace_back(
Candidate{ObjectIntersection<Surface>::invalid(&(portal->surface())),
portal, BoundaryTolerance::None()});
});
Expand Down

0 comments on commit a40b6de

Please sign in to comment.