File indexing completed on 2025-08-05 08:09:50
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <boost/test/tools/output_test_stream.hpp>
0010 #include <boost/test/unit_test.hpp>
0011
0012 #include "Acts/Definitions/Algebra.hpp"
0013 #include "Acts/Definitions/Units.hpp"
0014 #include "Acts/Surfaces/detail/LineHelper.hpp"
0015 #include "Acts/Surfaces/detail/PlanarHelper.hpp"
0016 #include "Acts/Utilities/UnitVectors.hpp"
0017
0018 #include <format>
0019 BOOST_AUTO_TEST_SUITE(LineInterSectionTests)
0020
0021 BOOST_AUTO_TEST_CASE(checkPlaneIsection) {
0022 using namespace Acts;
0023 using namespace Acts::PlanarHelper;
0024
0025 const Vector3 pointInPlane{561., 0., 0.};
0026 const Vector3 planeNormal{Vector3::UnitX()};
0027
0028 const Vector3 extPoint = pointInPlane + 50. * planeNormal;
0029 const Vector3 lineDir = Vector3{1., 5., 0.}.normalized();
0030
0031 const Vector3 crossPoint = intersectPlane(extPoint, lineDir, planeNormal,
0032 planeNormal.dot(pointInPlane))
0033 .position();
0034
0035 BOOST_CHECK_LE(std::abs(pointInPlane.x() - crossPoint.x()),
0036 std::numeric_limits<float>::epsilon());
0037 BOOST_CHECK_LE(std::abs(pointInPlane.y() - crossPoint.y() - 250.),
0038 std::numeric_limits<float>::epsilon());
0039 }
0040
0041 BOOST_AUTO_TEST_CASE(lineDistance) {
0042 using namespace Acts::detail::LineHelper;
0043 using namespace Acts;
0044 using namespace Acts::UnitLiterals;
0045 const Vector3 posA{100, 0., 0.};
0046 const Vector3 posB{100, 50, 0.};
0047 constexpr double tolerance = 1.e-12;
0048
0049 const double parallelTest =
0050 signedDistance(posA, Vector3::UnitZ(), posB, Vector3::UnitZ());
0051 BOOST_CHECK_LE(std::abs(parallelTest - 50), tolerance);
0052 std::cout << __FILE__ << ":" << __LINE__
0053 << " - Passed test between two parallel crossing lines: "
0054 << parallelTest << std::endl;
0055
0056 const double orthogonalTest =
0057 std::abs(signedDistance(posA, Vector3::UnitX(), posB, Vector3::UnitZ()));
0058 BOOST_CHECK_LE(std::abs(orthogonalTest - 50), tolerance);
0059 std::cout << __FILE__ << ":" << __LINE__
0060 << " - Passed test between two orthogonal lines: " << orthogonalTest
0061 << std::endl;
0062
0063 constexpr double angleXY = 36. * 1_degree;
0064 const Vector3 dirInXY{makeDirectionFromPhiTheta(0., angleXY)};
0065 const double planeXYTest = signedDistance(posA, dirInXY, posB, dirInXY);
0066 BOOST_CHECK_LE(std::abs(planeXYTest - 50.), tolerance);
0067 const double planeXYTest1 = signedDistance(posA, dirInXY, posB, dirInXY);
0068 BOOST_CHECK_LE(std::abs(std::abs(planeXYTest1) - 50.), tolerance);
0069 std::cout << __FILE__ << ":" << __LINE__
0070 << " - Passed test between two parallel lines in the x-y plane: "
0071 << planeXYTest << std::endl;
0072
0073 const Vector3 plumbDir{-dirInXY.z(), 0., dirInXY.x()};
0074
0075
0076 const Vector3 extDir =
0077 (5. * dirInXY + 21. * plumbDir.cross(dirInXY)).normalized();
0078
0079 BOOST_CHECK_LE(extDir.dot(plumbDir), tolerance);
0080 BOOST_CHECK_LE(plumbDir.dot(dirInXY), tolerance);
0081
0082
0083 const Vector3 extPoint =
0084 posA + 50. * dirInXY + 50. * plumbDir + 400. * extDir;
0085
0086 const Vector3 closePointExt =
0087 lineIntersect(posA, dirInXY, extPoint, extDir).position();
0088 BOOST_CHECK_LE((posA + 50. * dirInXY + 50. * plumbDir - closePointExt).norm(),
0089 tolerance);
0090
0091 const Vector3 closePointXY =
0092 lineIntersect(extPoint, extDir, posA, dirInXY).position();
0093 BOOST_CHECK_LE((posA + 50. * dirInXY - closePointXY).norm(), tolerance);
0094
0095 BOOST_CHECK_LE(std::abs((closePointXY - closePointExt).norm() - 50.),
0096 tolerance);
0097
0098 const double extLineDist = signedDistance(posA, dirInXY, extPoint, extDir);
0099 BOOST_CHECK_LE(std::abs(extLineDist - 50.), tolerance);
0100 const double extLineDist1 = signedDistance(posA, dirInXY, extPoint, extDir);
0101 BOOST_CHECK_LE(std::abs(extLineDist1 - 50.), tolerance);
0102
0103 const double crossLines =
0104 signedDistance(extPoint + 525. * dirInXY, dirInXY, extPoint, extDir);
0105
0106
0107
0108 BOOST_CHECK_LE(std::abs(crossLines), 1e-5);
0109 }
0110 BOOST_AUTO_TEST_SUITE_END()