Skip to content

Commit

Permalink
feat(geo): Portal gets fill with trivial method
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
paulgessinger committed Aug 27, 2024
1 parent cac7cf8 commit 6aa2f38
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Core/include/Acts/Geometry/Portal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 17 additions & 0 deletions Core/src/Geometry/Portal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<TrivialPortalLink>(m_surface, volume);
} else {
assert(m_oppositeNormal == nullptr);
m_oppositeNormal = std::make_unique<TrivialPortalLink>(m_surface, volume);
}
}

} // namespace Acts
28 changes: 28 additions & 0 deletions Tests/UnitTests/Core/Geometry/PortalTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CylinderSurface>(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
Expand Down

0 comments on commit 6aa2f38

Please sign in to comment.