From 64dcfb356c7336a68c2a5520939b87c909e9116b Mon Sep 17 00:00:00 2001 From: Paul Gessinger Date: Tue, 1 Oct 2024 10:11:08 +0200 Subject: [PATCH 1/2] feat(geo): Extent designated initialization --- Core/include/Acts/Geometry/Extent.hpp | 27 +++++++++++++++++++ Tests/UnitTests/Core/Geometry/ExtentTests.cpp | 11 ++++++++ 2 files changed, 38 insertions(+) diff --git a/Core/include/Acts/Geometry/Extent.hpp b/Core/include/Acts/Geometry/Extent.hpp index 698477744c0..9b9e00bc48b 100644 --- a/Core/include/Acts/Geometry/Extent.hpp +++ b/Core/include/Acts/Geometry/Extent.hpp @@ -74,6 +74,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 From 8014d8cbe64d37686a4a2db3208a82857c94c494 Mon Sep 17 00:00:00 2001 From: Paul Gessinger Date: Wed, 2 Oct 2024 10:39:52 +0200 Subject: [PATCH 2/2] fix ambiguity --- Core/include/Acts/Geometry/Extent.hpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Core/include/Acts/Geometry/Extent.hpp b/Core/include/Acts/Geometry/Extent.hpp index 9b9e00bc48b..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() {