Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:11:27

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2017-2018 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 http://mozilla.org/MPL/2.0/.
0008 
0009 #include <boost/test/data/test_case.hpp>
0010 #include <boost/test/tools/output_test_stream.hpp>
0011 #include <boost/test/unit_test.hpp>
0012 
0013 #include "Acts/Definitions/Algebra.hpp"
0014 #include "Acts/Surfaces/BoundaryCheck.hpp"
0015 #include "Acts/Tests/CommonHelpers/FloatComparisons.hpp"
0016 
0017 #include <algorithm>
0018 #include <cstddef>
0019 #include <vector>
0020 
0021 #include "BoundaryCheckTestsRefs.hpp"
0022 
0023 namespace Acts {
0024 namespace Test {
0025 BOOST_AUTO_TEST_SUITE(Surfaces)
0026 // See: https://en.wikipedia.org/wiki/Bounding_volume
0027 //
0028 // Aligned box w/ simple check
0029 BOOST_AUTO_TEST_CASE(BoundaryCheckBoxSimple) {
0030   BoundaryCheck check(true);
0031   Vector2 ll(-1, -1);
0032   Vector2 ur(1, 1);
0033   BOOST_CHECK(check.isInside({0, 0}, ll, ur));
0034   BOOST_CHECK(!check.isInside({2, 2}, ll, ur));
0035   BOOST_CHECK(!check.isInside({0, 2}, ll, ur));
0036   BOOST_CHECK(!check.isInside({2, 0}, ll, ur));
0037 }
0038 // Aligned box w/ tolerance check along first axis
0039 BOOST_AUTO_TEST_CASE(BoundaryCheckBoxToleranceLoc0) {
0040   BoundaryCheck check(true, false, 1.5, 0.0);
0041   Vector2 ll(-1, -1);
0042   Vector2 ur(1, 1);
0043   BOOST_CHECK(check.isInside({0, 0}, ll, ur));
0044   BOOST_CHECK(check.isInside({2, 2}, ll, ur));
0045   BOOST_CHECK(!check.isInside({4, 4}, ll, ur));
0046   BOOST_CHECK(check.isInside({0, 2}, ll, ur));
0047   BOOST_CHECK(check.isInside({2, 0}, ll, ur));
0048 }
0049 
0050 BOOST_AUTO_TEST_CASE(BoundaryCheckBoxDistance) {
0051   BoundaryCheck bcheck(true);
0052 
0053   for (std::size_t i = 0; i < rectTestPoints.size(); i++) {
0054     const Vector2& testPoint = rectTestPoints.at(i);
0055     double refDistance = rectDistances.at(i);
0056     Vector2 ll(rectDimensions.xmin, rectDimensions.ymin);
0057     Vector2 ur(rectDimensions.xmax, rectDimensions.ymax);
0058     double distance = bcheck.distance(testPoint, ll, ur);
0059     CHECK_CLOSE_REL(refDistance, distance, 1e-6);
0060   }
0061 
0062   for (std::size_t i = 0; i < rectShiftedTestPoints.size(); i++) {
0063     const Vector2& testPoint = rectShiftedTestPoints.at(i);
0064     double refDistance = rectShiftedDistances.at(i);
0065     Vector2 ll(rectShiftedDimensions.xmin, rectShiftedDimensions.ymin);
0066     Vector2 ur(rectShiftedDimensions.xmax, rectShiftedDimensions.ymax);
0067     double distance = bcheck.distance(testPoint, ll, ur);
0068     CHECK_CLOSE_REL(refDistance, distance, 1e-6);
0069   }
0070 }
0071 
0072 // Aligned box w/ covariance check
0073 BOOST_AUTO_TEST_CASE(BoundaryCheckBoxCovariance) {
0074   SquareMatrix2 cov;
0075   cov << 1, 0.5, 0.5, 2;
0076   BoundaryCheck check(cov, 3.0);
0077   Vector2 ll(-1, -1);
0078   Vector2 ur(1, 1);
0079   BOOST_CHECK(check.isInside({0, 0}, ll, ur));
0080   BOOST_CHECK(check.isInside({2, 2}, ll, ur));
0081   BOOST_CHECK(!check.isInside({4, 4}, ll, ur));
0082   BOOST_CHECK(check.isInside({0, 3}, ll, ur));
0083   BOOST_CHECK(check.isInside({3, 0}, ll, ur));
0084 }
0085 
0086 BOOST_AUTO_TEST_CASE(BoundaryCheckPolyDistance) {
0087   // we check a box again, but this time described as a poly
0088 
0089   BoundaryCheck bcheck(true);
0090 
0091   for (std::size_t i = 0; i < rectTestPoints.size(); i++) {
0092     const Vector2& testPoint = rectTestPoints.at(i);
0093     double refDistance = rectDistances.at(i);
0094     double distance = bcheck.distance(testPoint, rectVertices);
0095     CHECK_CLOSE_REL(refDistance, distance, 1e-6);
0096   }
0097 
0098   for (std::size_t i = 0; i < rectShiftedTestPoints.size(); i++) {
0099     const Vector2& testPoint = rectShiftedTestPoints.at(i);
0100     double refDistance = rectShiftedDistances.at(i);
0101     double distance = bcheck.distance(testPoint, rectShiftedVertices);
0102     CHECK_CLOSE_REL(refDistance, distance, 1e-6);
0103   }
0104 }
0105 
0106 // Triangle w/ simple check
0107 BOOST_AUTO_TEST_CASE(BoundaryCheckTriangleSimple) {
0108   Vector2 vertices[] = {{-2, 0}, {2, 0}, {0, 2}};
0109   BoundaryCheck check(true);
0110   BOOST_CHECK(check.isInside({0, 0}, vertices));
0111   BOOST_CHECK(check.isInside({0, 1}, vertices));
0112   BOOST_CHECK(!check.isInside({2, 2}, vertices));
0113   BOOST_CHECK(!check.isInside({0, -1}, vertices));
0114 }
0115 // Triangle w/ covariance check
0116 BOOST_AUTO_TEST_CASE(BoundaryCheckTriangleCovariance) {
0117   Vector2 vertices[] = {{-2, 0}, {2, 0}, {0, 2}};
0118   SquareMatrix2 cov;
0119   cov << 0.5, 0, 0, 0.5;
0120   BoundaryCheck check(cov, 4.1);
0121   BOOST_CHECK(check.isInside({0, 0}, vertices));
0122   BOOST_CHECK(check.isInside({0, 1}, vertices));
0123   BOOST_CHECK(check.isInside({0, 2}, vertices));
0124   BOOST_CHECK(check.isInside({0, 3}, vertices));
0125   BOOST_CHECK(check.isInside({0, 4}, vertices));
0126   BOOST_CHECK(!check.isInside({0, 5}, vertices));
0127 }
0128 BOOST_AUTO_TEST_SUITE_END()
0129 }  // namespace Test
0130 }  // namespace Acts