Skip to content

Commit

Permalink
portal: resolveVolume returns Result
Browse files Browse the repository at this point in the history
  • Loading branch information
paulgessinger committed Aug 26, 2024
1 parent e7a4135 commit a1a6dc4
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 60 deletions.
7 changes: 4 additions & 3 deletions Core/include/Acts/Geometry/Portal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "Acts/Definitions/Direction.hpp"
#include "Acts/Utilities/BinningType.hpp"
#include "Acts/Utilities/Logger.hpp"
#include "Acts/Utilities/Result.hpp"

#include <memory>

Expand Down Expand Up @@ -96,9 +97,9 @@ class Portal {
Portal& bPortal, BinningValue direction,
const Logger& logger = getDummyLogger());

const TrackingVolume* resolveVolume(const GeometryContext& gctx,
const Vector3& position,
const Vector3& direction) const;
Result<const TrackingVolume*> resolveVolume(const GeometryContext& gctx,
const Vector3& position,
const Vector3& direction) const;

void setLink(const GeometryContext& gctx, Direction direction,
std::unique_ptr<PortalLinkBase> link);
Expand Down
12 changes: 8 additions & 4 deletions Core/src/Geometry/Portal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ const PortalLinkBase* Portal::getLink(Direction direction) const {
}
}

const TrackingVolume* Portal::resolveVolume(const GeometryContext& gctx,
const Vector3& position,
const Vector3& direction) const {
Result<const TrackingVolume*> Portal::resolveVolume(
const GeometryContext& gctx, const Vector3& position,
const Vector3& direction) const {
assert(m_surface != nullptr);
const Vector3 normal = m_surface->normal(gctx, position);
Direction side = Direction::fromScalar(normal.dot(direction));
Expand All @@ -137,7 +137,11 @@ const TrackingVolume* Portal::resolveVolume(const GeometryContext& gctx,
// we know it. (i feel fine)
return nullptr;
} else {
return link->resolveVolume(gctx, position);
auto res = link->resolveVolume(gctx, position);
if (!res.ok()) {
return res.error();
}
return *res;
}
}

Expand Down
137 changes: 84 additions & 53 deletions Tests/UnitTests/Core/Geometry/PortalTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,24 +74,32 @@ BOOST_AUTO_TEST_CASE(Cylinder) {
std::make_unique<TrivialPortalLink>(cyl1, *vol1)};
BOOST_CHECK(portal1.isValid());

BOOST_CHECK_EQUAL(portal1.resolveVolume(gctx, Vector3{50_mm, 0_mm, -100_mm},
Vector3::UnitX()),
vol1.get());
BOOST_CHECK_EQUAL(
portal1
.resolveVolume(gctx, Vector3{50_mm, 0_mm, -100_mm}, Vector3::UnitX())
.value(),
vol1.get());

BOOST_CHECK_EQUAL(portal1.resolveVolume(gctx, Vector3{50_mm, 0_mm, -100_mm},
-Vector3::UnitX()),
nullptr);
BOOST_CHECK_EQUAL(
portal1
.resolveVolume(gctx, Vector3{50_mm, 0_mm, -100_mm}, -Vector3::UnitX())
.value(),
nullptr);

Portal portal2{gctx, Direction::AlongNormal, cyl2, *vol2};
BOOST_CHECK(portal2.isValid());

BOOST_CHECK_EQUAL(portal2.resolveVolume(gctx, Vector3{50_mm, 0_mm, 100_mm},
-Vector3::UnitX()),
nullptr);
BOOST_CHECK_EQUAL(
portal2
.resolveVolume(gctx, Vector3{50_mm, 0_mm, 100_mm}, -Vector3::UnitX())
.value(),
nullptr);

BOOST_CHECK_EQUAL(portal2.resolveVolume(gctx, Vector3{50_mm, 0_mm, 100_mm},
Vector3::UnitX()),
vol2.get());
BOOST_CHECK_EQUAL(
portal2
.resolveVolume(gctx, Vector3{50_mm, 0_mm, 100_mm}, Vector3::UnitX())
.value(),
vol2.get());

Portal portal3{gctx, std::make_unique<TrivialPortalLink>(cyl2, *vol2),
nullptr};
Expand Down Expand Up @@ -126,13 +134,16 @@ BOOST_AUTO_TEST_CASE(Cylinder) {
BOOST_CHECK(portal1.isValid());
BOOST_CHECK(portal2.isValid());

BOOST_CHECK_EQUAL(portal2.resolveVolume(gctx, Vector3{50_mm, 0_mm, 50_mm},
Vector3::UnitX()),
vol2.get());
BOOST_CHECK_EQUAL(
portal2.resolveVolume(gctx, Vector3{50_mm, 0_mm, 50_mm}, Vector3::UnitX())
.value(),
vol2.get());

BOOST_CHECK_EQUAL(portal2.resolveVolume(gctx, Vector3{50_mm, 0_mm, 50_mm},
-Vector3::UnitX()),
nullptr);
BOOST_CHECK_EQUAL(
portal2
.resolveVolume(gctx, Vector3{50_mm, 0_mm, 50_mm}, -Vector3::UnitX())
.value(),
nullptr);

// Cannot merge in binRPhi
BOOST_CHECK_THROW(
Expand Down Expand Up @@ -165,21 +176,29 @@ BOOST_AUTO_TEST_CASE(Cylinder) {
BOOST_REQUIRE_NE(grid12, nullptr);
grid12->printContents(std::cout);

BOOST_CHECK_EQUAL(merged12.resolveVolume(gctx, Vector3{50_mm, 0_mm, -50_mm},
Vector3::UnitX()),
vol1.get());
BOOST_CHECK_EQUAL(
merged12
.resolveVolume(gctx, Vector3{50_mm, 0_mm, -50_mm}, Vector3::UnitX())
.value(),
vol1.get());

BOOST_CHECK_EQUAL(merged12.resolveVolume(gctx, Vector3{50_mm, 0_mm, 50_mm},
Vector3::UnitX()),
vol2.get());
BOOST_CHECK_EQUAL(
merged12
.resolveVolume(gctx, Vector3{50_mm, 0_mm, 50_mm}, Vector3::UnitX())
.value(),
vol2.get());

BOOST_CHECK_EQUAL(merged12.resolveVolume(gctx, Vector3{50_mm, 0_mm, -50_mm},
-Vector3::UnitX()),
nullptr);
BOOST_CHECK_EQUAL(
merged12
.resolveVolume(gctx, Vector3{50_mm, 0_mm, -50_mm}, -Vector3::UnitX())
.value(),
nullptr);

BOOST_CHECK_EQUAL(merged12.resolveVolume(gctx, Vector3{50_mm, 0_mm, 50_mm},
-Vector3::UnitX()),
nullptr);
BOOST_CHECK_EQUAL(
merged12
.resolveVolume(gctx, Vector3{50_mm, 0_mm, 50_mm}, -Vector3::UnitX())
.value(),
nullptr);

portal1 = Portal{gctx, {.alongNormal = {cyl1, *vol1}}};

Expand Down Expand Up @@ -232,18 +251,23 @@ BOOST_AUTO_TEST_CASE(Disc) {
BOOST_CHECK(portal2.isValid());

BOOST_CHECK_EQUAL(
portal1.resolveVolume(gctx, Vector3{55_mm, 0_mm, 0_mm}, Vector3::UnitZ()),
portal1.resolveVolume(gctx, Vector3{55_mm, 0_mm, 0_mm}, Vector3::UnitZ())
.value(),
vol1.get());
BOOST_CHECK_EQUAL(portal1.resolveVolume(gctx, Vector3{55_mm, 0_mm, 0_mm},
-Vector3::UnitZ()),
vol2.get());
BOOST_CHECK_EQUAL(
portal1.resolveVolume(gctx, Vector3{55_mm, 0_mm, 0_mm}, -Vector3::UnitZ())
.value(),
vol2.get());

BOOST_CHECK_EQUAL(portal2.resolveVolume(gctx, Vector3{105_mm, 0_mm, 0_mm},
Vector3::UnitZ()),
vol3.get());
BOOST_CHECK_EQUAL(portal2.resolveVolume(gctx, Vector3{105_mm, 0_mm, 0_mm},
-Vector3::UnitZ()),
vol4.get());
BOOST_CHECK_EQUAL(
portal2.resolveVolume(gctx, Vector3{105_mm, 0_mm, 0_mm}, Vector3::UnitZ())
.value(),
vol3.get());
BOOST_CHECK_EQUAL(
portal2
.resolveVolume(gctx, Vector3{105_mm, 0_mm, 0_mm}, -Vector3::UnitZ())
.value(),
vol4.get());

BOOST_CHECK_THROW(
Portal::merge(gctx, portal1, portal2, BinningValue::binZ, *logger),
Expand Down Expand Up @@ -280,19 +304,26 @@ BOOST_AUTO_TEST_CASE(Disc) {
Portal merged12 =
Portal::merge(gctx, portal1, portal2, BinningValue::binR, *logger);

BOOST_CHECK_EQUAL(merged12.resolveVolume(gctx, Vector3{55_mm, 0_mm, 0_mm},
Vector3::UnitZ()),
vol1.get());
BOOST_CHECK_EQUAL(merged12.resolveVolume(gctx, Vector3{55_mm, 0_mm, 0_mm},
-Vector3::UnitZ()),
vol2.get());

BOOST_CHECK_EQUAL(merged12.resolveVolume(gctx, Vector3{105_mm, 0_mm, 0_mm},
Vector3::UnitZ()),
vol3.get());
BOOST_CHECK_EQUAL(merged12.resolveVolume(gctx, Vector3{105_mm, 0_mm, 0_mm},
-Vector3::UnitZ()),
vol4.get());
BOOST_CHECK_EQUAL(
merged12.resolveVolume(gctx, Vector3{55_mm, 0_mm, 0_mm}, Vector3::UnitZ())
.value(),
vol1.get());
BOOST_CHECK_EQUAL(
merged12
.resolveVolume(gctx, Vector3{55_mm, 0_mm, 0_mm}, -Vector3::UnitZ())
.value(),
vol2.get());

BOOST_CHECK_EQUAL(
merged12
.resolveVolume(gctx, Vector3{105_mm, 0_mm, 0_mm}, Vector3::UnitZ())
.value(),
vol3.get());
BOOST_CHECK_EQUAL(
merged12
.resolveVolume(gctx, Vector3{105_mm, 0_mm, 0_mm}, -Vector3::UnitZ())
.value(),
vol4.get());

// Can't merge because surface has material
auto material =
Expand Down

0 comments on commit a1a6dc4

Please sign in to comment.