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