Back to home page

sPhenix code displayed by LXR

 
 

    


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

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