Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(geo): Extent designated initialization #3680

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 27 additions & 6 deletions Core/include/Acts/Geometry/Extent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@ struct ExtentEnvelope {
}
}

/// Constructor from an array of envelopes
/// @param values the array of envelopes
constexpr explicit ExtentEnvelope(
const std::array<Envelope, numBinningValues()>& values)
: m_values(values) {}

/// Static factory for a zero envelope
/// @return the zero envelope
constexpr static ExtentEnvelope Zero() {
Expand All @@ -74,6 +68,33 @@ struct ExtentEnvelope {
}};
}

/// Helper struct for designated initializer construction
struct Arguments {
Envelope x = zeroEnvelope;
Envelope y = zeroEnvelope;
Envelope z = zeroEnvelope;
Envelope r = zeroEnvelope;
Envelope phi = zeroEnvelope;
Envelope rPhi = zeroEnvelope;
Envelope h = zeroEnvelope;
Envelope eta = zeroEnvelope;
Envelope mag = zeroEnvelope;
};

/// Constructor using a helper struct for designated initializaion
/// @param args the arguments
constexpr explicit ExtentEnvelope(Arguments&& args) {
using enum BinningValue;
m_values[toUnderlying(binX)] = args.x;
m_values[toUnderlying(binY)] = args.y;
m_values[toUnderlying(binZ)] = args.z;
m_values[toUnderlying(binR)] = args.r;
m_values[toUnderlying(binPhi)] = args.phi;
m_values[toUnderlying(binH)] = args.h;
m_values[toUnderlying(binEta)] = args.eta;
m_values[toUnderlying(binMag)] = args.mag;
}

/// Comparison operator between envelope sets
/// @param lhs the left hand side
/// @param rhs the right hand side
Expand Down
11 changes: 11 additions & 0 deletions Tests/UnitTests/Core/Geometry/ExtentTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,17 @@ BOOST_AUTO_TEST_CASE(ProtoSupportCaseTests) {
BOOST_CHECK(volumeExtent.constrains(BinningValue::binR));
}

BOOST_AUTO_TEST_CASE(DesignatedInitializers) {
using enum BinningValue;
ExtentEnvelope exp;
exp[binX] = {1., 2.};
exp[binEta] = {-1., 1.};

ExtentEnvelope act{{.x = {1., 2.}, .eta = {-1., 1.}}};

BOOST_CHECK(exp == act);
}

BOOST_AUTO_TEST_SUITE_END()

} // namespace Acts::Test
Loading