File indexing completed on 2025-01-18 09:12:51
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/Definitions/Tolerance.hpp"
0013 #include "Acts/Surfaces/detail/IntersectionHelper2D.hpp"
0014 #include "Acts/Tests/CommonHelpers/FloatComparisons.hpp"
0015 #include "Acts/Utilities/Intersection.hpp"
0016
0017 #include <array>
0018
0019 namespace Acts::Test {
0020
0021 BOOST_AUTO_TEST_SUITE(Surfaces)
0022
0023 void basicChecks(bool circleCase = false) {
0024 double rY = 10.;
0025 double rX = circleCase ? rY : 5.;
0026
0027
0028 Vector2 start(12., 0.);
0029 Vector2 direction(0., -1.);
0030
0031 auto nosol = circleCase ? detail::IntersectionHelper2D::intersectCircle(
0032 rY, start, direction)
0033 : detail::IntersectionHelper2D::intersectEllipse(
0034 rX, rY, start, direction);
0035 BOOST_CHECK(!nosol[0].isValid());
0036 BOOST_CHECK(!nosol[1].isValid());
0037
0038 start = Vector2(4., -4.);
0039 auto twosol = circleCase ? detail::IntersectionHelper2D::intersectCircle(
0040 rY, start, direction)
0041 : detail::IntersectionHelper2D::intersectEllipse(
0042 rX, rY, start, direction);
0043
0044 BOOST_CHECK(twosol[0].isValid());
0045 BOOST_CHECK(twosol[1].isValid());
0046
0047 start = Vector2(-4., 10.);
0048 direction = Vector2(1., 0.);
0049
0050 auto onesolY = circleCase ? detail::IntersectionHelper2D::intersectCircle(
0051 rY, start, direction)
0052 : detail::IntersectionHelper2D::intersectEllipse(
0053 rX, rY, start, direction);
0054
0055 BOOST_CHECK(onesolY[0].isValid());
0056 CHECK_CLOSE_ABS(onesolY[0].position().x(), 0., s_epsilon);
0057 BOOST_CHECK(!onesolY[1].isValid());
0058
0059 start = Vector2(rX, -4);
0060 direction = Vector2(0., 1.);
0061
0062 auto onesolX = circleCase ? detail::IntersectionHelper2D::intersectCircle(
0063 rY, start, direction)
0064 : detail::IntersectionHelper2D::intersectEllipse(
0065 rX, rY, start, direction);
0066
0067 BOOST_CHECK(onesolX[0].isValid());
0068 CHECK_CLOSE_ABS(onesolX[0].position().y(), 0., s_epsilon);
0069 BOOST_CHECK(!onesolX[1].isValid());
0070 }
0071
0072
0073 BOOST_AUTO_TEST_CASE(LineLineIntersection) {
0074 Vector2 start(1., 1.);
0075 Vector2 dir(1., 1.);
0076
0077
0078 auto solution = detail::IntersectionHelper2D::intersectSegment(
0079 Vector2(5., 3.), Vector2(6., 4), start, dir.normalized());
0080
0081 BOOST_CHECK(!solution.isValid());
0082
0083
0084 solution = detail::IntersectionHelper2D::intersectSegment(
0085 Vector2(5., 3.), Vector2(3., -1.), start, dir.normalized());
0086
0087 BOOST_CHECK(solution.isValid());
0088
0089
0090 start = Vector2(2, 3);
0091 dir = Vector2(2, 1).normalized();
0092
0093 solution = detail::IntersectionHelper2D::intersectSegment(
0094 Vector2(-1., -2.5), Vector2(3., 2.5), start, dir);
0095
0096 BOOST_CHECK(solution.isValid());
0097
0098 solution = detail::IntersectionHelper2D::intersectSegment(
0099 Vector2(-1., -2.5), Vector2(3., 2.5), start, dir, true);
0100
0101 BOOST_CHECK(!solution.isValid());
0102 }
0103
0104
0105 BOOST_AUTO_TEST_CASE(EllipseIntersection) {
0106
0107 basicChecks();
0108
0109
0110 double radiusX = 450.;
0111 double radiusY = 275.;
0112
0113 Vector2 start(-500., -300.);
0114 Vector2 direction = Vector2(10., 4.).normalized();
0115
0116 auto solution = detail::IntersectionHelper2D::intersectEllipse(
0117 radiusX, radiusY, start, direction);
0118
0119
0120 BOOST_CHECK(solution[0].isValid());
0121
0122 CHECK_CLOSE_ABS(solution[0].position().x(), -283.68, 0.01);
0123 CHECK_CLOSE_ABS(solution[0].position().y(), -213.47, 0.01);
0124 BOOST_CHECK_GT(solution[0].pathLength(), 0.);
0125
0126 BOOST_CHECK(solution[1].isValid());
0127
0128 CHECK_CLOSE_ABS(solution[1].position().x(), 433.65, 0.01);
0129 CHECK_CLOSE_ABS(solution[1].position().y(), 73.46, 0.01);
0130 BOOST_CHECK_GT(solution[1].pathLength(), 0.);
0131
0132
0133 }
0134
0135
0136 BOOST_AUTO_TEST_CASE(CircleIntersection) {
0137
0138 basicChecks(true);
0139
0140
0141 double radius = 275.;
0142
0143 Vector2 start(-500., -300.);
0144 Vector2 direction = Vector2(1., 1.).normalized();
0145
0146 auto solution =
0147 detail::IntersectionHelper2D::intersectCircle(radius, start, direction);
0148
0149
0150 BOOST_CHECK(solution[0].isValid());
0151
0152 CHECK_CLOSE_ABS(solution[0].position().x(), -266.771, 0.001);
0153 CHECK_CLOSE_ABS(solution[0].position().y(), -66.771, 0.001);
0154 BOOST_CHECK_GT(solution[0].pathLength(), 0.);
0155
0156 BOOST_CHECK(solution[1].isValid());
0157
0158 CHECK_CLOSE_ABS(solution[1].position().x(), 66.771, 0.001);
0159 CHECK_CLOSE_ABS(solution[1].position().y(), 266.771, 0.001);
0160 BOOST_CHECK_GT(solution[1].pathLength(), 0.);
0161
0162
0163 start = Vector2(1500., 1700.);
0164 direction = Vector2(1., 1.).normalized();
0165 solution =
0166 detail::IntersectionHelper2D::intersectCircle(radius, start, direction);
0167
0168 BOOST_CHECK(solution[0].isValid());
0169 CHECK_CLOSE_ABS(solution[0].position().x(), 66.771, 0.001);
0170 CHECK_CLOSE_ABS(solution[0].position().y(), 266.771, 0.001);
0171 BOOST_CHECK_LT(solution[0].pathLength(), 0.);
0172
0173 BOOST_CHECK(solution[1].isValid());
0174 CHECK_CLOSE_ABS(solution[1].position().x(), -266.771, 0.001);
0175 CHECK_CLOSE_ABS(solution[1].position().y(), -66.771, 0.001);
0176 BOOST_CHECK_LT(solution[1].pathLength(), 0.);
0177
0178
0179 direction = Vector2(-1., -1.).normalized();
0180 solution =
0181 detail::IntersectionHelper2D::intersectCircle(radius, start, direction);
0182
0183 BOOST_CHECK(solution[0].isValid());
0184 CHECK_CLOSE_ABS(solution[0].position().x(), 66.771, 0.001);
0185 CHECK_CLOSE_ABS(solution[0].position().y(), 266.771, 0.001);
0186 BOOST_CHECK_GT(solution[0].pathLength(), 0.);
0187
0188 BOOST_CHECK(solution[1].isValid());
0189 CHECK_CLOSE_ABS(solution[1].position().x(), -266.771, 0.001);
0190 CHECK_CLOSE_ABS(solution[1].position().y(), -66.771, 0.001);
0191 BOOST_CHECK_GT(solution[1].pathLength(), 0.);
0192 }
0193
0194 BOOST_AUTO_TEST_SUITE_END()
0195
0196 }