File indexing completed on 2025-01-18 09:12:45
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <boost/test/unit_test.hpp>
0010
0011 #include "Acts/Navigation/NavigationStream.hpp"
0012 #include "Acts/Surfaces/CylinderSurface.hpp"
0013 #include "Acts/Surfaces/PlaneSurface.hpp"
0014 #include "Acts/Surfaces/RectangleBounds.hpp"
0015 #include "Acts/Tests/CommonHelpers/FloatComparisons.hpp"
0016
0017 namespace {
0018
0019
0020 std::vector<std::shared_ptr<Acts::Surface>> createPlaneSurfaces() {
0021 auto rectangle = std::make_shared<Acts::RectangleBounds>(10., 10.);
0022
0023
0024 Acts::Transform3 aTransform = Acts::Transform3::Identity();
0025 aTransform.pretranslate(Acts::Vector3(0., 0., -20.));
0026 auto surfaceA =
0027 Acts::Surface::makeShared<Acts::PlaneSurface>(aTransform, rectangle);
0028
0029
0030
0031 Acts::Transform3 bTransform = Acts::Transform3::Identity();
0032 bTransform.pretranslate(Acts::Vector3(50., 50., 100.));
0033 auto surfaceB =
0034 Acts::Surface::makeShared<Acts::PlaneSurface>(bTransform, rectangle);
0035
0036 Acts::Transform3 cTransform = Acts::Transform3::Identity();
0037 cTransform.pretranslate(Acts::Vector3(0., 0., 200.));
0038 auto surfaceC =
0039 Acts::Surface::makeShared<Acts::PlaneSurface>(cTransform, rectangle);
0040
0041 Acts::Transform3 dTransform = Acts::Transform3::Identity();
0042 dTransform.pretranslate(Acts::Vector3(0., 0., 400.));
0043 auto surfaceD =
0044 Acts::Surface::makeShared<Acts::PlaneSurface>(dTransform, rectangle);
0045
0046
0047 return {surfaceC, surfaceA, surfaceD, surfaceB};
0048 }
0049
0050
0051 std::vector<std::shared_ptr<Acts::Surface>> createCylinders() {
0052
0053
0054 Acts::Transform3 aTransform = Acts::Transform3::Identity();
0055 auto surfaceA =
0056 Acts::Surface::makeShared<Acts::CylinderSurface>(aTransform, 10., 20);
0057
0058
0059
0060 Acts::Transform3 bTransform = Acts::Transform3::Identity();
0061 bTransform.pretranslate(Acts::Vector3(20., 20., 0.));
0062 auto surfaceB =
0063 Acts::Surface::makeShared<Acts::CylinderSurface>(bTransform, 2., 10);
0064
0065
0066
0067 Acts::Transform3 cTransform = Acts::Transform3::Identity();
0068 auto surfaceC =
0069 Acts::Surface::makeShared<Acts::CylinderSurface>(cTransform, 40., 20);
0070
0071
0072
0073
0074 Acts::Transform3 dTransform = Acts::Transform3::Identity();
0075 dTransform.pretranslate(Acts::Vector3(0., 0., 10.));
0076 auto surfaceD =
0077 Acts::Surface::makeShared<Acts::CylinderSurface>(dTransform, 50., 5.);
0078
0079
0080 return {surfaceC, surfaceB, surfaceA, surfaceD};
0081 }
0082
0083 }
0084
0085 using namespace Acts;
0086
0087 auto gContext = GeometryContext();
0088
0089 BOOST_AUTO_TEST_SUITE(Navigation)
0090
0091 BOOST_AUTO_TEST_CASE(NavigationStream_InitializePlanes) {
0092
0093 auto surfaces = createPlaneSurfaces();
0094
0095 NavigationStream nStreamTemplate;
0096 for (const auto& surface : surfaces) {
0097 nStreamTemplate.addSurfaceCandidate(*surface,
0098 Acts::BoundaryTolerance::None());
0099 }
0100 BOOST_CHECK_EQUAL(nStreamTemplate.remainingCandidates(), 4u);
0101
0102
0103
0104
0105 NavigationStream nStream = nStreamTemplate;
0106 BOOST_CHECK(nStream.initialize(gContext,
0107 {Vector3(0., 0., -30.), Vector3(0., 0., 1.)},
0108 BoundaryTolerance::Infinite()));
0109
0110 BOOST_CHECK_EQUAL(nStream.remainingCandidates(), 4u);
0111 BOOST_CHECK_EQUAL(&nStream.currentCandidate().surface(), surfaces[1u].get());
0112
0113
0114
0115
0116 nStream = nStreamTemplate;
0117 BOOST_CHECK(nStream.initialize(gContext,
0118 {Vector3(0., 0., 0.), Vector3(0., 0., 1.)},
0119 BoundaryTolerance::Infinite()));
0120 BOOST_CHECK_EQUAL(nStream.remainingCandidates(), 3u);
0121 BOOST_CHECK_EQUAL(&nStream.currentCandidate().surface(), surfaces[3u].get());
0122
0123
0124
0125
0126 nStream = nStreamTemplate;
0127 BOOST_CHECK(nStream.initialize(gContext,
0128 {Vector3(0., 0., -100.), Vector3(0., 0., 1.)},
0129 BoundaryTolerance::None()));
0130 BOOST_CHECK_EQUAL(nStream.remainingCandidates(), 3u);
0131
0132
0133
0134 nStream = nStreamTemplate;
0135 BOOST_CHECK(!nStream.initialize(gContext,
0136 {Vector3(0., 0., 0.), Vector3(1., 0., 0.)},
0137 BoundaryTolerance::Infinite()));
0138 BOOST_CHECK_EQUAL(nStream.remainingCandidates(), 0u);
0139 BOOST_CHECK_THROW(nStream.currentCandidate(), std::out_of_range);
0140
0141
0142 nStream = nStreamTemplate;
0143 nStreamTemplate.addSurfaceCandidate(*surfaces.at(0),
0144 Acts::BoundaryTolerance::None());
0145
0146 BOOST_CHECK_EQUAL(nStreamTemplate.remainingCandidates(), 5u);
0147
0148 BOOST_CHECK(nStream.initialize(gContext,
0149 {Vector3(0., 0., -100.), Vector3(0., 0., 1.)},
0150 BoundaryTolerance::Infinite()));
0151 BOOST_CHECK_EQUAL(nStream.remainingCandidates(), 4u);
0152 }
0153
0154 BOOST_AUTO_TEST_CASE(NavigationStream_UpdatePlanes) {
0155
0156 auto surfaces = createPlaneSurfaces();
0157
0158
0159
0160 NavigationStream nStreamTemplate;
0161 for (const auto& surface : surfaces) {
0162 nStreamTemplate.addSurfaceCandidate(*surface,
0163 Acts::BoundaryTolerance::None());
0164 }
0165 BOOST_CHECK_EQUAL(nStreamTemplate.remainingCandidates(), 4u);
0166
0167
0168
0169
0170 NavigationStream::QueryPoint qPoint = {Vector3(0., 0., -30.),
0171 Vector3(0., 0., 1.)};
0172
0173 NavigationStream nStream = nStreamTemplate;
0174 BOOST_CHECK(
0175 nStream.initialize(gContext, qPoint, BoundaryTolerance::Infinite()));
0176 BOOST_CHECK_EQUAL(nStream.remainingCandidates(), 4u);
0177 BOOST_CHECK_EQUAL(&nStream.currentCandidate().surface(), surfaces[1u].get());
0178 CHECK_CLOSE_ABS(nStream.currentCandidate().pathLength(), 10.,
0179 std::numeric_limits<double>::epsilon());
0180
0181
0182 qPoint.position = Vector3(0., 0., -22.);
0183 BOOST_CHECK(nStream.update(gContext, qPoint));
0184
0185 BOOST_CHECK_EQUAL(&nStream.currentCandidate().surface(), surfaces[1u].get());
0186 CHECK_CLOSE_ABS(nStream.currentCandidate().pathLength(), 2.,
0187 std::numeric_limits<double>::epsilon());
0188
0189
0190 qPoint.position = Vector3(0., 0., -19.5);
0191 BOOST_CHECK(nStream.update(gContext, qPoint));
0192
0193 BOOST_CHECK_EQUAL(&nStream.currentCandidate().surface(), surfaces[1u].get());
0194 CHECK_CLOSE_ABS(nStream.currentCandidate().pathLength(), -0.5,
0195 std::numeric_limits<double>::epsilon());
0196
0197
0198 qPoint.position = Vector3(0., 0., -20.);
0199 BOOST_CHECK(nStream.update(gContext, qPoint));
0200
0201
0202 BOOST_CHECK_EQUAL(&nStream.currentCandidate().surface(), surfaces[1u].get());
0203 CHECK_CLOSE_ABS(
0204 nStream.currentCandidate().pathLength(), s_onSurfaceTolerance,
0205 std::numeric_limits<double>::epsilon() + s_onSurfaceTolerance);
0206 BOOST_CHECK_EQUAL(nStream.currentCandidate().intersection.status(),
0207 IntersectionStatus::onSurface);
0208
0209 BOOST_CHECK(nStream.switchToNextCandidate());
0210
0211 BOOST_CHECK_EQUAL(&nStream.currentCandidate().surface(), surfaces[3u].get());
0212
0213 CHECK_CLOSE_ABS(nStream.currentCandidate().pathLength(), 130.,
0214 std::numeric_limits<double>::epsilon());
0215
0216
0217
0218 BOOST_CHECK(nStream.update(gContext, qPoint));
0219 CHECK_CLOSE_ABS(nStream.currentCandidate().pathLength(), 220.,
0220 std::numeric_limits<double>::epsilon());
0221
0222 qPoint.direction = Vector3(0., 1., 1.).normalized();
0223
0224 BOOST_CHECK(!nStream.update(gContext, qPoint));
0225 }
0226
0227 BOOST_AUTO_TEST_CASE(NavigationStream_InitializeCylinders) {
0228
0229 auto surfaces = createCylinders();
0230
0231
0232 NavigationStream nStreamTemplate;
0233 for (const auto& surface : surfaces) {
0234 const Surface* pointer = surface.get();
0235 nStreamTemplate.addSurfaceCandidates({&pointer, 1},
0236 Acts::BoundaryTolerance::None());
0237 }
0238 BOOST_CHECK_EQUAL(nStreamTemplate.remainingCandidates(), 4u);
0239
0240
0241
0242
0243 NavigationStream nStream = nStreamTemplate;
0244 BOOST_CHECK(nStream.initialize(
0245 gContext, {Vector3(0., 0., 0.), Vector3(1., 1., 0.).normalized()},
0246 BoundaryTolerance::Infinite()));
0247
0248 BOOST_CHECK_EQUAL(nStream.remainingCandidates(), 5u);
0249
0250 BOOST_CHECK_EQUAL(&nStream.currentCandidate().surface(), surfaces[2].get());
0251
0252 BOOST_CHECK_EQUAL(&nStream.candidates()[1u].surface(), surfaces[1].get());
0253 BOOST_CHECK_EQUAL(&nStream.candidates()[2u].surface(), surfaces[1].get());
0254
0255
0256
0257
0258 nStream = nStreamTemplate;
0259 BOOST_CHECK(nStream.initialize(gContext,
0260 {Vector3(0., 0., 0.), Vector3(1., 0., 0.)},
0261 BoundaryTolerance::Infinite()));
0262
0263 BOOST_CHECK_EQUAL(nStream.remainingCandidates(), 3u);
0264
0265
0266
0267 nStream = nStreamTemplate;
0268 BOOST_CHECK(nStream.initialize(gContext,
0269 {Vector3(0., 0., 0.), Vector3(1., 0., 0.)},
0270 BoundaryTolerance::None()));
0271
0272 BOOST_CHECK_EQUAL(nStream.remainingCandidates(), 2u);
0273
0274
0275
0276
0277 nStream = nStreamTemplate;
0278 BOOST_CHECK(!nStream.initialize(gContext,
0279 {Vector3(0., 0., 0.), Vector3(0., 0., 1.)},
0280 BoundaryTolerance::None()));
0281
0282 BOOST_CHECK_EQUAL(nStream.remainingCandidates(), 0u);
0283 BOOST_CHECK_THROW(nStream.currentCandidate(), std::out_of_range);
0284 }
0285
0286 BOOST_AUTO_TEST_SUITE_END()