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