File indexing completed on 2025-09-18 08:14:27
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <boost/test/unit_test.hpp>
0010
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Surfaces/CurvilinearSurface.hpp"
0013 #include "Acts/Surfaces/PlaneSurface.hpp"
0014 #include "Acts/Utilities/Intersection.hpp"
0015
0016 #include <algorithm>
0017 #include <array>
0018 #include <cmath>
0019 #include <iterator>
0020 #include <memory>
0021 #include <sstream>
0022 #include <string>
0023 #include <vector>
0024
0025 namespace Acts::Test {
0026
0027 class Object {};
0028
0029
0030 BOOST_AUTO_TEST_CASE(IntersectionTest) {
0031
0032
0033 Intersection3D fIp(Vector3(0., 1., 0.), 1., IntersectionStatus::reachable);
0034 Intersection3D sIp(Vector3(0., 2., 0.), 2., IntersectionStatus::reachable);
0035 Intersection3D tIp(Vector3(0., 3., 0.), 3., IntersectionStatus::reachable);
0036 BOOST_CHECK(fIp.isValid());
0037 BOOST_CHECK(sIp.isValid());
0038 BOOST_CHECK(tIp.isValid());
0039
0040
0041 Intersection3D nIp(Vector3(3., 3., 0.), 3., IntersectionStatus::unreachable);
0042 BOOST_CHECK(!nIp.isValid());
0043
0044 std::vector<Intersection3D> fstpIntersections = {fIp, sIp, tIp};
0045 std::vector<Intersection3D> tsfpIntersections = {tIp, sIp, fIp};
0046
0047
0048 std::ranges::sort(tsfpIntersections, Intersection3D::pathLengthOrder);
0049 BOOST_CHECK_EQUAL(fstpIntersections[0].pathLength(),
0050 tsfpIntersections[0].pathLength());
0051 BOOST_CHECK_EQUAL(fstpIntersections[1].pathLength(),
0052 tsfpIntersections[1].pathLength());
0053 BOOST_CHECK_EQUAL(fstpIntersections[2].pathLength(),
0054 tsfpIntersections[2].pathLength());
0055
0056
0057
0058 std::vector<Intersection3D> ntfspIntersections = {nIp, tIp, fIp, sIp};
0059 std::vector<Intersection3D> tfnsnpIntersections = {tIp, fIp, nIp, sIp, nIp};
0060
0061
0062 std::ranges::sort(ntfspIntersections, Intersection3D::pathLengthOrder);
0063 BOOST_CHECK_EQUAL(fstpIntersections[0].pathLength(),
0064 ntfspIntersections[0].pathLength());
0065 BOOST_CHECK_EQUAL(fstpIntersections[1].pathLength(),
0066 ntfspIntersections[1].pathLength());
0067 BOOST_CHECK_EQUAL(fstpIntersections[2].pathLength(),
0068 ntfspIntersections[2].pathLength());
0069
0070 std::ranges::sort(tfnsnpIntersections, Intersection3D::pathLengthOrder);
0071 BOOST_CHECK_EQUAL(fstpIntersections[0].pathLength(),
0072 tfnsnpIntersections[0].pathLength());
0073 BOOST_CHECK_EQUAL(fstpIntersections[1].pathLength(),
0074 tfnsnpIntersections[1].pathLength());
0075 BOOST_CHECK_EQUAL(fstpIntersections[2].pathLength(),
0076 tfnsnpIntersections[2].pathLength());
0077
0078
0079 Intersection3D fIn(Vector3(0., -1., 0.), -1., IntersectionStatus::reachable);
0080 Intersection3D sIn(Vector3(0., -2., 0.), -2., IntersectionStatus::reachable);
0081 Intersection3D tIn(Vector3(0., -3., 0.), -3., IntersectionStatus::reachable);
0082
0083 std::vector<Intersection3D> tsfnIntersections = {tIn, sIn, fIn};
0084 std::vector<Intersection3D> fstnIntersections = {fIn, sIn, tIn};
0085
0086
0087 std::ranges::sort(fstnIntersections, Intersection3D::pathLengthOrder);
0088 BOOST_CHECK_EQUAL(fstnIntersections[0].pathLength(),
0089 tsfnIntersections[0].pathLength());
0090 BOOST_CHECK_EQUAL(fstnIntersections[1].pathLength(),
0091 tsfnIntersections[1].pathLength());
0092 BOOST_CHECK_EQUAL(fstnIntersections[2].pathLength(),
0093 tsfnIntersections[2].pathLength());
0094
0095
0096 std::vector<Intersection3D> pnsolutions = {tIp, sIn, sIp, fIn, tIn, fIp};
0097 std::ranges::sort(pnsolutions, Intersection3D::pathLengthOrder);
0098
0099 BOOST_CHECK_EQUAL(pnsolutions[0].pathLength(), -3.);
0100 BOOST_CHECK_EQUAL(pnsolutions[1].pathLength(), -2.);
0101 BOOST_CHECK_EQUAL(pnsolutions[2].pathLength(), -1.);
0102 BOOST_CHECK_EQUAL(pnsolutions[3].pathLength(), 1.);
0103 BOOST_CHECK_EQUAL(pnsolutions[4].pathLength(), 2.);
0104 BOOST_CHECK_EQUAL(pnsolutions[5].pathLength(), 3.);
0105
0106
0107 Intersection3D zI(Vector3(0., 0., 0.), 0., IntersectionStatus::onSurface);
0108 std::vector<Intersection3D> tszfpIntersections = {tIp, sIp, zI, fIp};
0109
0110 std::ranges::sort(tszfpIntersections, Intersection3D::pathLengthOrder);
0111 BOOST_CHECK_EQUAL(tszfpIntersections[0].pathLength(), 0.);
0112 BOOST_CHECK_EQUAL(tszfpIntersections[1].pathLength(), 1.);
0113 BOOST_CHECK_EQUAL(tszfpIntersections[2].pathLength(), 2.);
0114 BOOST_CHECK_EQUAL(tszfpIntersections[3].pathLength(), 3.);
0115
0116 std::vector<Intersection3D> tfsznIntersections = {tIn, fIn, sIn, zI};
0117 std::vector<Intersection3D> ztfsnIntersections = {zI, tIn, fIn, sIn};
0118
0119 std::ranges::sort(tfsznIntersections, Intersection3D::pathLengthOrder);
0120 BOOST_CHECK_EQUAL(tfsznIntersections[0].pathLength(), -3.);
0121 BOOST_CHECK_EQUAL(tfsznIntersections[1].pathLength(), -2.);
0122 BOOST_CHECK_EQUAL(tfsznIntersections[2].pathLength(), -1.);
0123 BOOST_CHECK_EQUAL(tfsznIntersections[3].pathLength(), 0.);
0124 }
0125
0126
0127 BOOST_AUTO_TEST_CASE(ObjectIntersectionTest) {
0128 std::shared_ptr<PlaneSurface> psf6 =
0129 CurvilinearSurface(Vector3(6., 0., 0.), Vector3(1., 0., 0.))
0130 .planeSurface();
0131 std::shared_ptr<PlaneSurface> psf7 =
0132 CurvilinearSurface(Vector3(7., 0., 0.), Vector3(1., 0., 0.))
0133 .planeSurface();
0134 std::shared_ptr<PlaneSurface> psf8 =
0135 CurvilinearSurface(Vector3(8., 0., 0.), Vector3(1., 0., 0.))
0136 .planeSurface();
0137 std::shared_ptr<PlaneSurface> psf9 =
0138 CurvilinearSurface(Vector3(9., 0., 0.), Vector3(1., 0., 0.))
0139 .planeSurface();
0140 std::shared_ptr<PlaneSurface> psf10 =
0141 CurvilinearSurface(Vector3(10., 0., 0.), Vector3(1., 0., 0.))
0142 .planeSurface();
0143
0144 SurfaceIntersection int6(
0145 Intersection3D(Vector3(6., 0., 0.), 6., IntersectionStatus::reachable),
0146 *psf6);
0147 SurfaceIntersection int7(
0148 Intersection3D(Vector3(7., 0., 0.), 7., IntersectionStatus::reachable),
0149 *psf7);
0150 SurfaceIntersection int8(
0151 Intersection3D(Vector3(8., 0., 0.), 8., IntersectionStatus::reachable),
0152 *psf8);
0153 SurfaceIntersection int9a(
0154 Intersection3D(Vector3(9., 0., 0.), 9., IntersectionStatus::reachable),
0155 *psf9);
0156 SurfaceIntersection int9b(
0157 Intersection3D(Vector3(9., 1., 0.), std::hypot(9., 1.),
0158 IntersectionStatus::reachable),
0159 *psf9);
0160 SurfaceIntersection int10(
0161 Intersection3D(Vector3(10., 0., 0.), 10., IntersectionStatus::reachable),
0162 *psf10);
0163
0164 std::vector<SurfaceIntersection> firstSet = {int6, int7, int9b, int10};
0165 std::vector<SurfaceIntersection> secondSet = {int8, int9a, int9b, int10};
0166
0167 std::vector<SurfaceIntersection> unionSetStd = {};
0168
0169 std::vector<SurfaceIntersection> unionSetCst = {};
0170
0171
0172 std::set_union(firstSet.begin(), firstSet.end(), secondSet.begin(),
0173 secondSet.end(), std::back_inserter(unionSetStd),
0174 SurfaceIntersection::pathLengthOrder);
0175 BOOST_CHECK_EQUAL(unionSetStd.size(), 6u);
0176 }
0177
0178 BOOST_AUTO_TEST_CASE(IntersectionStatusPrinting) {
0179 std::array<IntersectionStatus, 4> status_values = {
0180 {IntersectionStatus::unreachable, IntersectionStatus::unreachable,
0181 IntersectionStatus::reachable, IntersectionStatus::onSurface}};
0182 std::array<std::string, 4> expected_messages = {
0183 {"missed/unreachable", "missed/unreachable", "reachable", "onSurface"}};
0184
0185 for (int i = 0; i < 4; ++i) {
0186 std::stringstream ss;
0187 ss << status_values[i];
0188 BOOST_CHECK_EQUAL(ss.str(), expected_messages[i]);
0189 }
0190 }
0191
0192 }