diff --git a/Core/include/Acts/Geometry/Extent.hpp b/Core/include/Acts/Geometry/Extent.hpp index 698477744c0..8728728996b 100644 --- a/Core/include/Acts/Geometry/Extent.hpp +++ b/Core/include/Acts/Geometry/Extent.hpp @@ -52,12 +52,6 @@ struct ExtentEnvelope { } } - /// Constructor from an array of envelopes - /// @param values the array of envelopes - constexpr explicit ExtentEnvelope( - const std::array& values) - : m_values(values) {} - /// Static factory for a zero envelope /// @return the zero envelope constexpr static ExtentEnvelope Zero() { @@ -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 diff --git a/Tests/UnitTests/Core/Geometry/ExtentTests.cpp b/Tests/UnitTests/Core/Geometry/ExtentTests.cpp index 80513a1d80b..e0913e273eb 100644 --- a/Tests/UnitTests/Core/Geometry/ExtentTests.cpp +++ b/Tests/UnitTests/Core/Geometry/ExtentTests.cpp @@ -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