From 6aa2f38e1f68771bc262e43d7f728132f673eab4 Mon Sep 17 00:00:00 2001 From: Paul Gessinger Date: Tue, 27 Aug 2024 18:09:36 +0200 Subject: [PATCH] feat(geo): Portal gets fill with trivial method The `fill` method accepts a volume and creates a trivial portal link on the link that is not filled yet in the portal (along or opposite). --- Core/include/Acts/Geometry/Portal.hpp | 4 +++ Core/src/Geometry/Portal.cpp | 17 +++++++++++ Tests/UnitTests/Core/Geometry/PortalTests.cpp | 28 +++++++++++++++++++ 3 files changed, 49 insertions(+) diff --git a/Core/include/Acts/Geometry/Portal.hpp b/Core/include/Acts/Geometry/Portal.hpp index d8e0135c4e7..929c527e952 100644 --- a/Core/include/Acts/Geometry/Portal.hpp +++ b/Core/include/Acts/Geometry/Portal.hpp @@ -208,6 +208,10 @@ class Portal { /// @return True if the portal is valid bool isValid() const; + /// Create and attach a trivial portal link to the empty slot of this portal + /// @param volume The target volume to connect to + void fill(TrackingVolume& volume); + /// Access the portal surface that is shared between the two links /// @return The portal surface const RegularSurface& surface() const; diff --git a/Core/src/Geometry/Portal.cpp b/Core/src/Geometry/Portal.cpp index ef53b72b216..3cc700148d2 100644 --- a/Core/src/Geometry/Portal.cpp +++ b/Core/src/Geometry/Portal.cpp @@ -303,4 +303,21 @@ bool Portal::isSameSurface(const GeometryContext& gctx, const Surface& a, return true; }; +void Portal::fill(TrackingVolume& volume) { + if (m_alongNormal != nullptr && m_oppositeNormal != nullptr) { + throw std::logic_error{"Portal is already filled"}; + } + + if (m_surface == nullptr) { + throw std::logic_error{"Portal has no existing link set, can't fill"}; + } + + if (m_alongNormal == nullptr) { + m_alongNormal = std::make_unique(m_surface, volume); + } else { + assert(m_oppositeNormal == nullptr); + m_oppositeNormal = std::make_unique(m_surface, volume); + } +} + } // namespace Acts diff --git a/Tests/UnitTests/Core/Geometry/PortalTests.cpp b/Tests/UnitTests/Core/Geometry/PortalTests.cpp index de13ecee286..b36086dc8c9 100644 --- a/Tests/UnitTests/Core/Geometry/PortalTests.cpp +++ b/Tests/UnitTests/Core/Geometry/PortalTests.cpp @@ -567,6 +567,34 @@ BOOST_AUTO_TEST_CASE(InvalidConstruction) { std::invalid_argument); } +BOOST_AUTO_TEST_CASE(PortalFill) { + auto vol1 = makeDummyVolume(); + auto vol2 = makeDummyVolume(); + + auto cyl1 = Surface::makeShared(Transform3::Identity(), + 50_mm, 100_mm); + + Portal portal1{gctx, {.oppositeNormal = {cyl1, *vol1}}}; + Portal portal2{gctx, {.alongNormal = {cyl1, *vol2}}}; + + // Fuse these to make portal 1 and 2 empty + Portal::fuse(gctx, portal1, portal2, *logger); + + BOOST_CHECK_THROW(portal1.fill(*vol2), std::logic_error); + + portal1 = Portal{gctx, {.oppositeNormal = {cyl1, *vol1}}}; + portal2 = Portal{gctx, {.alongNormal = {cyl1, *vol2}}}; + + BOOST_CHECK_EQUAL(portal1.getLink(Direction::AlongNormal), nullptr); + BOOST_CHECK_NE(portal1.getLink(Direction::OppositeNormal), nullptr); + + portal1.fill(*vol2); + BOOST_CHECK_NE(portal1.getLink(Direction::AlongNormal), nullptr); + BOOST_CHECK_NE(portal1.getLink(Direction::OppositeNormal), nullptr); + + BOOST_CHECK_THROW(portal1.fill(*vol2), std::logic_error); +} + BOOST_AUTO_TEST_SUITE_END() // Portals BOOST_AUTO_TEST_SUITE_END() // Geometry