File indexing completed on 2025-07-11 07:51:17
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <boost/test/unit_test.hpp>
0010
0011 #include "Acts/Definitions/Units.hpp"
0012 #include "Acts/Geometry/CylinderVolumeBounds.hpp"
0013 #include "Acts/Geometry/Portal.hpp"
0014 #include "Acts/Geometry/PortalLinkBase.hpp"
0015 #include "Acts/Geometry/TrackingGeometryVisitor.hpp"
0016 #include "Acts/Geometry/TrackingVolume.hpp"
0017 #include "Acts/Surfaces/PlaneSurface.hpp"
0018 #include "Acts/Surfaces/RectangleBounds.hpp"
0019 #include "Acts/Utilities/Helpers.hpp"
0020
0021 #include "LayerStub.hpp"
0022
0023 using namespace Acts::UnitLiterals;
0024
0025 namespace Acts::Test {
0026
0027 BOOST_AUTO_TEST_SUITE(Geometry)
0028 BOOST_AUTO_TEST_SUITE(TrackingVolumeTests)
0029
0030 std::size_t countVolumes(const TrackingVolume& tv) {
0031 std::size_t count = 0;
0032 tv.visitVolumes([&count](const auto&) { ++count; });
0033 return count;
0034 }
0035
0036 BOOST_AUTO_TEST_CASE(TrackigVolumeChildren) {
0037 auto cylBounds =
0038 std::make_shared<Acts::CylinderVolumeBounds>(10_mm, 20_mm, 100_mm);
0039
0040 TrackingVolume tv{Transform3::Identity(), cylBounds};
0041
0042 BOOST_CHECK(tv.volumes().empty());
0043 BOOST_CHECK_EQUAL(countVolumes(tv), 1);
0044
0045 auto& child1 = tv.addVolume(
0046 std::make_unique<TrackingVolume>(Transform3::Identity(), cylBounds));
0047
0048 BOOST_CHECK_EQUAL(tv.volumes().size(), 1);
0049
0050 auto it = tv.volumes().begin();
0051 static_assert(std::is_same_v<decltype(*it), TrackingVolume&>);
0052
0053 const auto& tvConst = tv;
0054 auto cit = tvConst.volumes().begin();
0055 static_assert(std::is_same_v<decltype(*cit), const TrackingVolume&>);
0056
0057 BOOST_CHECK_EQUAL(&*it, &child1);
0058
0059 BOOST_CHECK_EQUAL(countVolumes(tv), 2);
0060
0061 tv.addVolume(
0062 std::make_unique<TrackingVolume>(Transform3::Identity(), cylBounds));
0063
0064 BOOST_CHECK_EQUAL(countVolumes(tv), 3);
0065 }
0066
0067 namespace {
0068 void testVisitor(auto visitor) {
0069 BOOST_CHECK(!visitor.m_surfaceCalled);
0070 BOOST_CHECK(!visitor.m_volumeCalled);
0071 BOOST_CHECK(!visitor.m_boundaryCalled);
0072 BOOST_CHECK(!visitor.m_layerCalled);
0073 BOOST_CHECK(!visitor.m_portalCalled);
0074
0075 auto surface = Surface::makeShared<PlaneSurface>(
0076 Transform3::Identity(), std::make_shared<RectangleBounds>(10_mm, 10_mm));
0077
0078 visitor.visitSurface(*surface);
0079 BOOST_CHECK(visitor.m_surfaceCalled);
0080
0081 auto cylBounds =
0082 std::make_shared<Acts::CylinderVolumeBounds>(10_mm, 20_mm, 100_mm);
0083
0084 TrackingVolume tv{Transform3::Identity(), cylBounds};
0085 visitor.visitVolume(tv);
0086
0087 BOOST_CHECK(visitor.m_volumeCalled);
0088
0089 BoundarySurfaceT<TrackingVolume> boundary{surface, &tv, nullptr};
0090 visitor.visitBoundarySurface(boundary);
0091 BOOST_CHECK(visitor.m_boundaryCalled);
0092
0093 LayerStub layer{nullptr};
0094 visitor.visitLayer(layer);
0095 BOOST_CHECK(visitor.m_layerCalled);
0096
0097 Portal portal{Direction::AlongNormal(), surface, tv};
0098 visitor.visitPortal(portal);
0099 BOOST_CHECK(visitor.m_portalCalled);
0100
0101 visitor.m_volumeCalled = false;
0102 tv.apply(visitor);
0103 BOOST_CHECK(visitor.m_volumeCalled);
0104 }
0105 }
0106
0107 BOOST_AUTO_TEST_CASE(Visit) {
0108 struct Visitor : public TrackingGeometryVisitor {
0109 void visitSurface(const Surface& ) override {
0110 m_surfaceCalled = true;
0111 }
0112
0113 void visitVolume(const TrackingVolume& ) override {
0114 m_volumeCalled = true;
0115 }
0116
0117 void visitBoundarySurface(
0118 const BoundarySurfaceT<TrackingVolume>& ) override {
0119 m_boundaryCalled = true;
0120 }
0121
0122 void visitLayer(const Layer& ) override { m_layerCalled = true; }
0123
0124 void visitPortal(const Portal& ) override {
0125 m_portalCalled = true;
0126 }
0127
0128 bool m_surfaceCalled = false;
0129 bool m_volumeCalled = false;
0130 bool m_boundaryCalled = false;
0131 bool m_layerCalled = false;
0132 bool m_portalCalled = false;
0133 };
0134
0135 testVisitor(Visitor{});
0136 }
0137
0138 BOOST_AUTO_TEST_CASE(VisitMutable) {
0139 struct MutableVisitor : public TrackingGeometryMutableVisitor {
0140 void visitSurface(Surface& ) override { m_surfaceCalled = true; }
0141
0142 void visitVolume(TrackingVolume& ) override {
0143 m_volumeCalled = true;
0144 }
0145
0146 void visitBoundarySurface(
0147 BoundarySurfaceT<TrackingVolume>& ) override {
0148 m_boundaryCalled = true;
0149 }
0150
0151 void visitLayer(Layer& ) override { m_layerCalled = true; }
0152
0153 void visitPortal(Portal& ) override { m_portalCalled = true; }
0154
0155 bool m_surfaceCalled = false;
0156 bool m_volumeCalled = false;
0157 bool m_boundaryCalled = false;
0158 bool m_layerCalled = false;
0159 bool m_portalCalled = false;
0160 };
0161
0162 testVisitor(MutableVisitor{});
0163 }
0164
0165 BOOST_AUTO_TEST_CASE(VisitLambda) {
0166 bool surfaceCalled = false;
0167 bool volumeCalled = false;
0168 bool boundaryCalled = false;
0169 bool layerCalled = false;
0170 bool portalCalled = false;
0171
0172 auto visitor = detail::TrackingGeometryLambdaVisitor{overloaded{
0173 [&](const Surface& ) { surfaceCalled = true; },
0174 [&](const TrackingVolume& ) { volumeCalled = true; },
0175 [&](const BoundarySurfaceT<TrackingVolume>& ) {
0176 boundaryCalled = true;
0177 },
0178 [&](const Layer& ) { layerCalled = true; },
0179 [&](const Portal& ) { portalCalled = true; },
0180 }};
0181
0182 auto surface = Surface::makeShared<PlaneSurface>(
0183 Transform3::Identity(), std::make_shared<RectangleBounds>(10_mm, 10_mm));
0184
0185 visitor.visitSurface(*surface);
0186 BOOST_CHECK(surfaceCalled);
0187
0188 auto cylBounds =
0189 std::make_shared<Acts::CylinderVolumeBounds>(10_mm, 20_mm, 100_mm);
0190
0191 TrackingVolume tv{Transform3::Identity(), cylBounds};
0192 visitor.visitVolume(tv);
0193
0194 BOOST_CHECK(volumeCalled);
0195
0196 BoundarySurfaceT<TrackingVolume> boundary{surface, &tv, nullptr};
0197 visitor.visitBoundarySurface(boundary);
0198 BOOST_CHECK(boundaryCalled);
0199
0200 LayerStub layer{nullptr};
0201 visitor.visitLayer(layer);
0202 BOOST_CHECK(layerCalled);
0203
0204 Portal portal{Direction::AlongNormal(), surface, tv};
0205 visitor.visitPortal(portal);
0206 BOOST_CHECK(portalCalled);
0207
0208 volumeCalled = false;
0209 tv.apply(visitor);
0210 BOOST_CHECK(volumeCalled);
0211 }
0212
0213 BOOST_AUTO_TEST_CASE(VisitLambdaMutable) {
0214 bool surfaceCalled = false;
0215 bool volumeCalled = false;
0216 bool boundaryCalled = false;
0217 bool layerCalled = false;
0218 bool portalCalled = false;
0219
0220 auto overload = overloaded{
0221 [&](Surface& ) { surfaceCalled = true; },
0222 [&](TrackingVolume& ) { volumeCalled = true; },
0223 [&](BoundarySurfaceT<TrackingVolume>& ) {
0224 boundaryCalled = true;
0225 },
0226 [&](Layer& ) { layerCalled = true; },
0227 [&](Portal& ) { portalCalled = true; },
0228 };
0229
0230 auto visitor = detail::TrackingGeometryLambdaMutableVisitor{overload};
0231
0232 auto surface = Surface::makeShared<PlaneSurface>(
0233 Transform3::Identity(), std::make_shared<RectangleBounds>(10_mm, 10_mm));
0234
0235 visitor.visitSurface(*surface);
0236 BOOST_CHECK(surfaceCalled);
0237
0238 auto cylBounds =
0239 std::make_shared<Acts::CylinderVolumeBounds>(10_mm, 20_mm, 100_mm);
0240
0241 TrackingVolume tv{Transform3::Identity(), cylBounds};
0242 visitor.visitVolume(tv);
0243
0244 BOOST_CHECK(volumeCalled);
0245
0246 BoundarySurfaceT<TrackingVolume> boundary{surface, &tv, nullptr};
0247 visitor.visitBoundarySurface(boundary);
0248 BOOST_CHECK(boundaryCalled);
0249
0250 LayerStub layer{nullptr};
0251 visitor.visitLayer(layer);
0252 BOOST_CHECK(layerCalled);
0253
0254 Portal portal{Direction::AlongNormal(), surface, tv};
0255 visitor.visitPortal(portal);
0256 BOOST_CHECK(portalCalled);
0257
0258 volumeCalled = false;
0259 tv.apply(overload);
0260 BOOST_CHECK(volumeCalled);
0261
0262 volumeCalled = false;
0263 tv.apply([&](Volume& ) { volumeCalled = true; });
0264 BOOST_CHECK(volumeCalled);
0265 }
0266
0267 BOOST_AUTO_TEST_CASE(CallableWithAny) {
0268
0269 static_assert(
0270 detail::callableWithAny<decltype([](Surface& ) {})>());
0271 static_assert(
0272 detail::callableWithAny<decltype([](const Surface& ) {})>());
0273 static_assert(detail::callableWithAny<decltype([](Portal& ) {})>());
0274 static_assert(
0275 detail::callableWithAny<decltype([](const Portal& ) {})>());
0276 static_assert(
0277 detail::callableWithAny<decltype([](TrackingVolume& ) {})>());
0278 static_assert(!detail::callableWithAny<decltype([](int ) {})>());
0279 static_assert(!detail::callableWithAny<decltype([](void* ) {})>());
0280
0281
0282 static_assert(detail::callableWithAnyConst<
0283 decltype([](const Surface& ) {})>());
0284 static_assert(detail::callableWithAnyConst<
0285 decltype([](const TrackingVolume& ) {})>());
0286 static_assert(
0287 detail::callableWithAnyConst<decltype([](const Layer& ) {})>());
0288 static_assert(!detail::callableWithAnyConst<decltype([](int ) {})>());
0289 static_assert(
0290 !detail::callableWithAnyConst<decltype([](void* ) {})>());
0291
0292
0293 static_assert(
0294 detail::callableWithAnyMutable<decltype([](Surface& ) {})>());
0295 static_assert(detail::callableWithAnyMutable<
0296 decltype([](TrackingVolume& ) {})>());
0297 static_assert(
0298 detail::callableWithAnyMutable<decltype([](Layer& ) {})>());
0299 static_assert(!detail::callableWithAnyMutable<decltype([](int ) {})>());
0300 static_assert(
0301 !detail::callableWithAnyMutable<decltype([](void* ) {})>());
0302
0303
0304 static_assert(detail::callableWithAny<decltype(overloaded{
0305 [](Surface& ) {},
0306 [](const TrackingVolume& ) {},
0307 })>());
0308
0309
0310 static_assert(!detail::callableWithAny<decltype(overloaded{
0311 [](int ) {},
0312 [](double ) {},
0313 [](const std::string& ) {},
0314 })>());
0315
0316
0317 static_assert(detail::callableWithAny<decltype(overloaded{
0318 [](int ) {},
0319 [](Surface& ) {},
0320 [](const std::string& ) {},
0321 })>());
0322
0323 static_assert(detail::callableWithAny<decltype(overloaded{
0324 [](void* ) {},
0325 [](const Portal& ) {},
0326 [](double ) {},
0327 })>());
0328 }
0329
0330 BOOST_AUTO_TEST_SUITE_END()
0331
0332 BOOST_AUTO_TEST_SUITE_END()
0333
0334 }