Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-11-06 09:19:07

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #include <boost/test/unit_test.hpp>
0010 
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Definitions/Tolerance.hpp"
0013 #include "Acts/Surfaces/detail/IntersectionHelper2D.hpp"
0014 #include "Acts/Utilities/Intersection.hpp"
0015 #include "ActsTests/CommonHelpers/FloatComparisons.hpp"
0016 
0017 #include <array>
0018 
0019 using namespace Acts;
0020 
0021 namespace ActsTests {
0022 
0023 BOOST_AUTO_TEST_SUITE(SurfacesSuite)
0024 
0025 void basicChecks(bool circleCase = false) {
0026   double rY = 10.;
0027   double rX = circleCase ? rY : 5.;
0028 
0029   // Line along x - not intersecting
0030   Vector2 start(12., 0.);
0031   Vector2 direction(0., -1.);
0032 
0033   auto nosol = circleCase ? detail::IntersectionHelper2D::intersectCircle(
0034                                 rY, start, direction)
0035                           : detail::IntersectionHelper2D::intersectEllipse(
0036                                 rX, rY, start, direction);
0037   BOOST_CHECK(!nosol[0].isValid());
0038   BOOST_CHECK(!nosol[1].isValid());
0039 
0040   start = Vector2(4., -4.);
0041   auto twosol = circleCase ? detail::IntersectionHelper2D::intersectCircle(
0042                                  rY, start, direction)
0043                            : detail::IntersectionHelper2D::intersectEllipse(
0044                                  rX, rY, start, direction);
0045 
0046   BOOST_CHECK(twosol[0].isValid());
0047   BOOST_CHECK(twosol[1].isValid());
0048 
0049   start = Vector2(-4., 10.);
0050   direction = Vector2(1., 0.);
0051 
0052   auto onesolY = circleCase ? detail::IntersectionHelper2D::intersectCircle(
0053                                   rY, start, direction)
0054                             : detail::IntersectionHelper2D::intersectEllipse(
0055                                   rX, rY, start, direction);
0056 
0057   BOOST_CHECK(onesolY[0].isValid());
0058   CHECK_CLOSE_ABS(onesolY[0].position().x(), 0., s_epsilon);
0059   BOOST_CHECK(!onesolY[1].isValid());
0060 
0061   start = Vector2(rX, -4);
0062   direction = Vector2(0., 1.);
0063 
0064   auto onesolX = circleCase ? detail::IntersectionHelper2D::intersectCircle(
0065                                   rY, start, direction)
0066                             : detail::IntersectionHelper2D::intersectEllipse(
0067                                   rX, rY, start, direction);
0068 
0069   BOOST_CHECK(onesolX[0].isValid());
0070   CHECK_CLOSE_ABS(onesolX[0].position().y(), 0., s_epsilon);
0071   BOOST_CHECK(!onesolX[1].isValid());
0072 }
0073 
0074 /// Unit test for creating Ellipse intersection
0075 BOOST_AUTO_TEST_CASE(LineLineIntersection) {
0076   Vector2 start(1., 1.);
0077   Vector2 dir(1., 1.);
0078 
0079   // Not possible
0080   auto solution = detail::IntersectionHelper2D::intersectSegment(
0081       Vector2(5., 3.), Vector2(6., 4), start, dir.normalized());
0082 
0083   BOOST_CHECK(!solution.isValid());
0084 
0085   // Possible
0086   solution = detail::IntersectionHelper2D::intersectSegment(
0087       Vector2(5., 3.), Vector2(3., -1.), start, dir.normalized());
0088 
0089   BOOST_CHECK(solution.isValid());
0090 
0091   // In principle possible, but out of bound
0092   start = Vector2(2, 3);
0093   dir = Vector2(2, 1).normalized();
0094 
0095   solution = detail::IntersectionHelper2D::intersectSegment(
0096       Vector2(-1., -2.5), Vector2(3., 2.5), start, dir);
0097 
0098   BOOST_CHECK(solution.isValid());
0099 
0100   solution = detail::IntersectionHelper2D::intersectSegment(
0101       Vector2(-1., -2.5), Vector2(3., 2.5), start, dir, true);
0102 
0103   BOOST_CHECK(!solution.isValid());
0104 }
0105 
0106 /// Unit test for creating Ellipse intersection
0107 BOOST_AUTO_TEST_CASE(EllipseIntersection) {
0108   // Basic checks for ellipse
0109   basicChecks();
0110 
0111   // Specific checks for ellipse
0112   double radiusX = 450.;
0113   double radiusY = 275.;
0114 
0115   Vector2 start(-500., -300.);
0116   Vector2 direction = Vector2(10., 4.).normalized();
0117 
0118   auto solution = detail::IntersectionHelper2D::intersectEllipse(
0119       radiusX, radiusY, start, direction);
0120 
0121   // Numerically checked / per hand calculated
0122   BOOST_CHECK(solution[0].isValid());
0123 
0124   CHECK_CLOSE_ABS(solution[0].position().x(), -283.68, 0.01);
0125   CHECK_CLOSE_ABS(solution[0].position().y(), -213.47, 0.01);
0126   BOOST_CHECK_GT(solution[0].pathLength(), 0.);
0127 
0128   BOOST_CHECK(solution[1].isValid());
0129 
0130   CHECK_CLOSE_ABS(solution[1].position().x(), 433.65, 0.01);
0131   CHECK_CLOSE_ABS(solution[1].position().y(), 73.46, 0.01);
0132   BOOST_CHECK_GT(solution[1].pathLength(), 0.);
0133 
0134   // Reverse checks will be done with circle (same code)
0135 }
0136 
0137 /// Unit test for creating Circle intersection
0138 BOOST_AUTO_TEST_CASE(CircleIntersection) {
0139   // Basic checks for circle
0140   basicChecks(true);
0141 
0142   // Specific checks for circle
0143   double radius = 275.;
0144 
0145   Vector2 start(-500., -300.);
0146   Vector2 direction = Vector2(1., 1.).normalized();
0147 
0148   auto solution =
0149       detail::IntersectionHelper2D::intersectCircle(radius, start, direction);
0150 
0151   // Numerically checked / per hand calculated
0152   BOOST_CHECK(solution[0].isValid());
0153 
0154   CHECK_CLOSE_ABS(solution[0].position().x(), -266.771, 0.001);
0155   CHECK_CLOSE_ABS(solution[0].position().y(), -66.771, 0.001);
0156   BOOST_CHECK_GT(solution[0].pathLength(), 0.);
0157 
0158   BOOST_CHECK(solution[1].isValid());
0159 
0160   CHECK_CLOSE_ABS(solution[1].position().x(), 66.771, 0.001);
0161   CHECK_CLOSE_ABS(solution[1].position().y(), 266.771, 0.001);
0162   BOOST_CHECK_GT(solution[1].pathLength(), 0.);
0163 
0164   // Reverse
0165   start = Vector2(1500., 1700.);
0166   direction = Vector2(1., 1.).normalized();
0167   solution =
0168       detail::IntersectionHelper2D::intersectCircle(radius, start, direction);
0169 
0170   BOOST_CHECK(solution[0].isValid());
0171   CHECK_CLOSE_ABS(solution[0].position().x(), 66.771, 0.001);
0172   CHECK_CLOSE_ABS(solution[0].position().y(), 266.771, 0.001);
0173   BOOST_CHECK_LT(solution[0].pathLength(), 0.);
0174 
0175   BOOST_CHECK(solution[1].isValid());
0176   CHECK_CLOSE_ABS(solution[1].position().x(), -266.771, 0.001);
0177   CHECK_CLOSE_ABS(solution[1].position().y(), -66.771, 0.001);
0178   BOOST_CHECK_LT(solution[1].pathLength(), 0.);
0179 
0180   // Reverse with reverse direction
0181   direction = Vector2(-1., -1.).normalized();
0182   solution =
0183       detail::IntersectionHelper2D::intersectCircle(radius, start, direction);
0184 
0185   BOOST_CHECK(solution[0].isValid());
0186   CHECK_CLOSE_ABS(solution[0].position().x(), 66.771, 0.001);
0187   CHECK_CLOSE_ABS(solution[0].position().y(), 266.771, 0.001);
0188   BOOST_CHECK_GT(solution[0].pathLength(), 0.);
0189 
0190   BOOST_CHECK(solution[1].isValid());
0191   CHECK_CLOSE_ABS(solution[1].position().x(), -266.771, 0.001);
0192   CHECK_CLOSE_ABS(solution[1].position().y(), -66.771, 0.001);
0193   BOOST_CHECK_GT(solution[1].pathLength(), 0.);
0194 }
0195 
0196 BOOST_AUTO_TEST_SUITE_END()
0197 
0198 }  // namespace ActsTests