Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:12:52

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/Surfaces/BoundaryTolerance.hpp"
0013 #include "Acts/Surfaces/RectangleBounds.hpp"
0014 #include "Acts/Surfaces/SurfaceBounds.hpp"
0015 #include "Acts/Tests/CommonHelpers/FloatComparisons.hpp"
0016 
0017 #include <algorithm>
0018 #include <array>
0019 #include <limits>
0020 #include <stdexcept>
0021 #include <vector>
0022 
0023 const double inf = std::numeric_limits<double>::infinity();
0024 
0025 namespace Acts::Test {
0026 
0027 BOOST_AUTO_TEST_SUITE(Surfaces)
0028 
0029 /// Unit test for creating compliant/non-compliant RectangleBounds object
0030 BOOST_AUTO_TEST_CASE(RectangleBoundsConstruction) {
0031   const double halfX = 10.;
0032   const double halfY = 5.;
0033   RectangleBounds twentyByTenRectangle(halfX, halfY);
0034   BOOST_CHECK_EQUAL(twentyByTenRectangle.type(),
0035                     Acts::SurfaceBounds::eRectangle);
0036 
0037   // nonsensical bounds are also permitted, but maybe should not be
0038   const double zeroHalfX = 0.;
0039   const double zeroHalfY = 0.;
0040   const double infHalfX = inf;
0041   const double infHalfY = inf;
0042 
0043   // Initialise with zero dimensions
0044   RectangleBounds zeroDimensionsRectangle(zeroHalfX, zeroHalfY);
0045   BOOST_CHECK_EQUAL(zeroDimensionsRectangle.type(),
0046                     Acts::SurfaceBounds::eRectangle);
0047 
0048   // Initialise with infinite dimensions
0049   RectangleBounds infinite(infHalfX, infHalfY);
0050   BOOST_CHECK_EQUAL(infinite.type(), Acts::SurfaceBounds::eRectangle);
0051 }
0052 
0053 /// Recreation
0054 BOOST_AUTO_TEST_CASE(RectangleBoundsRecreation) {
0055   const double halfX = 10.;
0056   const double halfY = 2.;  // != 5.
0057 
0058   RectangleBounds original(halfX, halfY);
0059 
0060   auto valvector = original.values();
0061   std::array<double, RectangleBounds::eSize> values{};
0062   std::copy_n(valvector.begin(), RectangleBounds::eSize, values.begin());
0063   RectangleBounds recreated(values);
0064   BOOST_CHECK_EQUAL(original, recreated);
0065 }
0066 
0067 // Exception tests
0068 BOOST_AUTO_TEST_CASE(RadialBoundsException) {
0069   const double halfX = 10.;
0070   const double halfY = 2.;  // != 5.
0071 
0072   // Negative x half length
0073   BOOST_CHECK_THROW(RectangleBounds(-halfX, halfY), std::logic_error);
0074 
0075   // Negative y half length
0076   BOOST_CHECK_THROW(RectangleBounds(halfX, -halfY), std::logic_error);
0077 }
0078 
0079 /// Unit test for testing RectangleBounds properties
0080 BOOST_TEST_DECORATOR(*boost::unit_test::tolerance(1e-10))
0081 BOOST_AUTO_TEST_CASE(RectangleBoundsProperties) {
0082   const double halfX = 10.;
0083   const double halfY = 5.;
0084 
0085   RectangleBounds rect(halfX, halfY);
0086   BOOST_CHECK_EQUAL(rect.halfLengthX(), halfX);
0087   BOOST_CHECK_EQUAL(rect.halfLengthY(), halfY);
0088 
0089   CHECK_CLOSE_ABS(rect.min(), Vector2(-halfX, -halfY), 1e-6);
0090   CHECK_CLOSE_ABS(rect.max(), Vector2(halfX, halfY), 1e-6);
0091 
0092   const std::vector<Vector2> coords = {
0093       {-halfX, -halfY}, {halfX, -halfY}, {halfX, halfY}, {-halfX, halfY}};
0094   // equality, ensure ordering is ok
0095   const auto& rectVertices = rect.vertices();
0096   BOOST_CHECK_EQUAL_COLLECTIONS(coords.cbegin(), coords.cend(),
0097                                 rectVertices.cbegin(), rectVertices.cend());
0098   const Vector2 pointA{1., 1.};
0099   // distance is signed, from boundary to point. (doesn't seem right, given
0100   BoundaryTolerance tolerance = BoundaryTolerance::None();
0101   BOOST_CHECK(rect.inside(pointA, tolerance));
0102 }
0103 BOOST_AUTO_TEST_CASE(RectangleBoundsAssignment) {
0104   const double halfX = 10.;
0105   const double halfY = 2.;  // != 5.
0106 
0107   RectangleBounds rectA(halfX, halfY);
0108   RectangleBounds rectB(0., 0.);
0109   rectB = rectA;
0110   const auto originalVertices = rectA.vertices();
0111   const auto assignedVertices = rectB.vertices();
0112   BOOST_CHECK_EQUAL_COLLECTIONS(
0113       originalVertices.cbegin(), originalVertices.cend(),
0114       assignedVertices.cbegin(), assignedVertices.cend());
0115 }
0116 
0117 BOOST_AUTO_TEST_SUITE_END()
0118 
0119 }  // namespace Acts::Test