Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /acts/Tests/UnitTests/Core/Surfaces/RectangleBoundsTests.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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 "ActsTests/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 using namespace Acts;
0026 
0027 namespace ActsTests {
0028 
0029 BOOST_AUTO_TEST_SUITE(SurfacesSuite)
0030 
0031 /// Unit test for creating compliant/non-compliant RectangleBounds object
0032 BOOST_AUTO_TEST_CASE(RectangleBoundsConstruction) {
0033   const double halfX = 10.;
0034   const double 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.;
0041   const double zeroHalfY = 0.;
0042   const double infHalfX = inf;
0043   const double infHalfY = inf;
0044 
0045   // Initialise with zero dimensions
0046   RectangleBounds zeroDimensionsRectangle(zeroHalfX, zeroHalfY);
0047   BOOST_CHECK_EQUAL(zeroDimensionsRectangle.type(),
0048                     Acts::SurfaceBounds::eRectangle);
0049 
0050   // Initialise with infinite dimensions
0051   RectangleBounds infinite(infHalfX, infHalfY);
0052   BOOST_CHECK_EQUAL(infinite.type(), Acts::SurfaceBounds::eRectangle);
0053 }
0054 
0055 /// Recreation
0056 BOOST_AUTO_TEST_CASE(RectangleBoundsRecreation) {
0057   const double halfX = 10.;
0058   const double halfY = 2.;  // != 5.
0059 
0060   RectangleBounds original(halfX, halfY);
0061 
0062   auto valvector = original.values();
0063   std::array<double, RectangleBounds::eSize> values{};
0064   std::copy_n(valvector.begin(), RectangleBounds::eSize, values.begin());
0065   RectangleBounds recreated(values);
0066   BOOST_CHECK_EQUAL(original, recreated);
0067 }
0068 
0069 // Exception tests
0070 BOOST_AUTO_TEST_CASE(RadialBoundsException) {
0071   const double halfX = 10.;
0072   const double halfY = 2.;  // != 5.
0073 
0074   // Negative x half length
0075   BOOST_CHECK_THROW(RectangleBounds(-halfX, halfY), std::logic_error);
0076 
0077   // Negative y half length
0078   BOOST_CHECK_THROW(RectangleBounds(halfX, -halfY), std::logic_error);
0079 }
0080 
0081 /// Unit test for testing RectangleBounds properties
0082 BOOST_TEST_DECORATOR(*boost::unit_test::tolerance(1e-10))
0083 BOOST_AUTO_TEST_CASE(RectangleBoundsProperties) {
0084   const double halfX = 10.;
0085   const double halfY = 5.;
0086 
0087   RectangleBounds rect(halfX, halfY);
0088   BOOST_CHECK_EQUAL(rect.halfLengthX(), halfX);
0089   BOOST_CHECK_EQUAL(rect.halfLengthY(), halfY);
0090 
0091   CHECK_CLOSE_ABS(rect.min(), Vector2(-halfX, -halfY), 1e-6);
0092   CHECK_CLOSE_ABS(rect.max(), Vector2(halfX, halfY), 1e-6);
0093 
0094   const std::vector<Vector2> coords = {
0095       {-halfX, -halfY}, {halfX, -halfY}, {halfX, halfY}, {-halfX, halfY}};
0096   // equality, ensure ordering is ok
0097   const auto& rectVertices = rect.vertices();
0098   BOOST_CHECK_EQUAL_COLLECTIONS(coords.cbegin(), coords.cend(),
0099                                 rectVertices.cbegin(), rectVertices.cend());
0100   const Vector2 pointA{1., 1.};
0101   // distance is signed, from boundary to point. (doesn't seem right, given
0102   BoundaryTolerance tolerance = BoundaryTolerance::None();
0103   BOOST_CHECK(rect.inside(pointA, tolerance));
0104 }
0105 BOOST_AUTO_TEST_CASE(RectangleBoundsAssignment) {
0106   const double halfX = 10.;
0107   const double halfY = 2.;  // != 5.
0108 
0109   RectangleBounds rectA(halfX, halfY);
0110   RectangleBounds rectB(0., 0.);
0111   rectB = rectA;
0112   const auto originalVertices = rectA.vertices();
0113   const auto assignedVertices = rectB.vertices();
0114   BOOST_CHECK_EQUAL_COLLECTIONS(
0115       originalVertices.cbegin(), originalVertices.cend(),
0116       assignedVertices.cbegin(), assignedVertices.cend());
0117 }
0118 
0119 BOOST_AUTO_TEST_CASE(RectangleBoundsCenter) {
0120   // Test symmetric rectangle
0121   const double halfX = 10.;
0122   const double halfY = 5.;
0123   RectangleBounds rect(halfX, halfY);
0124   Vector2 center = rect.center();
0125   CHECK_CLOSE_ABS(center, Vector2(0., 0.), 1e-6);
0126 
0127   // Test asymmetric rectangle
0128   Vector2 min(-3., -2.);
0129   Vector2 max(7., 4.);
0130   RectangleBounds rectAsym(min, max);
0131   Vector2 centerAsym = rectAsym.center();
0132   Vector2 expected = 0.5 * (min + max);
0133   CHECK_CLOSE_ABS(centerAsym, expected, 1e-6);
0134 }
0135 
0136 BOOST_AUTO_TEST_SUITE_END()
0137 
0138 }  // namespace ActsTests