Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-16 08:04:22

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/tools/output_test_stream.hpp>
0010 #include <boost/test/unit_test.hpp>
0011 
0012 #include "Acts/Definitions/Algebra.hpp"
0013 #include "Acts/Surfaces/BoundaryTolerance.hpp"
0014 #include "Acts/Surfaces/DiamondBounds.hpp"
0015 #include "Acts/Surfaces/RectangleBounds.hpp"
0016 #include "Acts/Surfaces/SurfaceBounds.hpp"
0017 
0018 #include <iostream>
0019 #include <stdexcept>
0020 #include <vector>
0021 
0022 using namespace Acts;
0023 
0024 namespace ActsTests {
0025 
0026 BOOST_AUTO_TEST_SUITE(SurfacesSuite)
0027 
0028 /// Unit test for creating compliant/non-compliant DiamondBounds object
0029 BOOST_AUTO_TEST_CASE(DiamondBoundsConstruction) {
0030   /// Test default construction
0031   // default construction is deleted
0032 
0033   const double minHalfX = 10.;
0034   const double midHalfX = 20.;
0035   const double maxHalfX = 15.;
0036   const double halfY1 = 5.;
0037   const double halfY2 = 7.;
0038 
0039   /// Test construction with dimensions
0040   BOOST_CHECK_EQUAL(
0041       DiamondBounds(minHalfX, midHalfX, maxHalfX, halfY1, halfY2).type(),
0042       SurfaceBounds::eDiamond);
0043 
0044   /// Copy constructor
0045   DiamondBounds original(minHalfX, midHalfX, maxHalfX, halfY1, halfY2);
0046   DiamondBounds copied(original);
0047   BOOST_CHECK_EQUAL(copied.type(), SurfaceBounds::eDiamond);
0048 
0049   /// Test invalid inputs
0050   BOOST_CHECK_THROW(
0051       DiamondBounds db(midHalfX, minHalfX, maxHalfX, halfY1, halfY2),
0052       std::logic_error);
0053   BOOST_CHECK_THROW(
0054       DiamondBounds db(minHalfX, maxHalfX, midHalfX, halfY1, halfY2),
0055       std::logic_error);
0056 }
0057 
0058 /// Unit tests for DiamondBounds properties
0059 BOOST_AUTO_TEST_CASE(DiamondBoundsProperties) {
0060   const double minHalfX = 10.;
0061   const double midHalfX = 50.;  // != 20.
0062   const double maxHalfX = 30.;  // != 15.
0063   const double halfY1 = 10.;    // != 5.
0064   const double halfY2 = 20.;    // != 7.
0065 
0066   /// Test clone
0067   DiamondBounds diamondBoundsObject(minHalfX, midHalfX, maxHalfX, halfY1,
0068                                     halfY2);
0069 
0070   /// Test type() (redundant; already used in constructor confirmation)
0071   BOOST_CHECK_EQUAL(diamondBoundsObject.type(), SurfaceBounds::eDiamond);
0072 
0073   /// Test the half length at negative y
0074   BOOST_CHECK_EQUAL(diamondBoundsObject.get(DiamondBounds::eHalfLengthXnegY),
0075                     minHalfX);
0076 
0077   /// Test the half length at the x axis
0078   BOOST_CHECK_EQUAL(diamondBoundsObject.get(DiamondBounds::eHalfLengthXzeroY),
0079                     midHalfX);
0080 
0081   /// Test the half length at positive y
0082   BOOST_CHECK_EQUAL(diamondBoundsObject.get(DiamondBounds::eHalfLengthXposY),
0083                     maxHalfX);
0084 
0085   /// Test half length into the negative side
0086   BOOST_CHECK_EQUAL(diamondBoundsObject.get(DiamondBounds::eHalfLengthYneg),
0087                     halfY1);
0088 
0089   /// Test half length into the positive side
0090   BOOST_CHECK_EQUAL(diamondBoundsObject.get(DiamondBounds::eHalfLengthYpos),
0091                     halfY2);
0092 
0093   /// Test boundingBox
0094   BOOST_CHECK_EQUAL(diamondBoundsObject.boundingBox(),
0095                     RectangleBounds(Vector2{-50., -10.}, Vector2{50., 20.}));
0096 
0097   /// Test distanceToBoundary
0098   Vector2 origin(0., 0.);
0099   Vector2 outsideBy10(0., 30.);
0100   Vector2 inRectangle(15., 0.);
0101 
0102   /// Test dump
0103   diamondBoundsObject.toStream(std::cout);
0104   boost::test_tools::output_test_stream dumpOutput;
0105   diamondBoundsObject.toStream(dumpOutput);
0106   BOOST_CHECK(
0107       dumpOutput.is_equal("Acts::DiamondBounds: (halfXatYneg, halfXatYzero, "
0108                           "halfXatYpos, halfYneg, halfYpos) = (10.0000000, "
0109                           "50.0000000, 30.0000000, 10.0000000, 20.0000000)"));
0110 
0111   /// Test inside
0112   BOOST_CHECK(diamondBoundsObject.inside(origin, BoundaryTolerance::None()));
0113   // dont understand why this is so:
0114   BOOST_CHECK(
0115       !diamondBoundsObject.inside(outsideBy10, BoundaryTolerance::None()));
0116 
0117   /// Test vertices (does this need to be implemented in this class??
0118   // auto v=diamondBoundsObject.vertices();
0119   std::vector<Vector2> referenceVertices{
0120       {-minHalfX, -halfY1}, {minHalfX, -halfY1}, {midHalfX, 0.},
0121       {maxHalfX, halfY2},   {-maxHalfX, halfY2}, {-midHalfX, 0.}};
0122   const auto& actualVertices = diamondBoundsObject.vertices();
0123   BOOST_CHECK_EQUAL_COLLECTIONS(actualVertices.cbegin(), actualVertices.cend(),
0124                                 referenceVertices.cbegin(),
0125                                 referenceVertices.cend());
0126 }
0127 
0128 /// Unit test for testing DiamondBounds assignment
0129 BOOST_AUTO_TEST_CASE(DiamondBoundsAssignment) {
0130   const double minHalfX = 10.;
0131   const double midHalfX = 20.;
0132   const double maxHalfX = 15.;
0133   const double halfY1 = 5.;
0134   const double halfY2 = 7.;
0135 
0136   DiamondBounds diamondBoundsObject(minHalfX, midHalfX, maxHalfX, halfY1,
0137                                     halfY2);
0138   DiamondBounds similarlyConstructeDiamondBoundsObject(
0139       minHalfX, midHalfX, maxHalfX, halfY1, halfY2);
0140 
0141   /// Test operator ==
0142   BOOST_CHECK_EQUAL(diamondBoundsObject,
0143                     similarlyConstructeDiamondBoundsObject);
0144 
0145   /// Test assignment
0146   DiamondBounds assignedDiamondBoundsObject(
0147       2 * minHalfX, 2 * midHalfX, 2 * maxHalfX, 2 * halfY1, 2 * halfY2);
0148 
0149   // object, in some sense
0150   assignedDiamondBoundsObject = diamondBoundsObject;
0151   BOOST_CHECK_EQUAL(assignedDiamondBoundsObject, diamondBoundsObject);
0152 }
0153 
0154 BOOST_AUTO_TEST_CASE(DiamondBoundsCenter) {
0155   const double minHalfX = 10.;
0156   const double midHalfX = 20.;
0157   const double maxHalfX = 15.;
0158   const double halfY1 = 5.;
0159   const double halfY2 = 7.;
0160 
0161   DiamondBounds diamond(minHalfX, midHalfX, maxHalfX, halfY1, halfY2);
0162   Vector2 center = diamond.center();
0163 
0164   // Diamond is symmetric about both axes, so centroid should be at origin
0165   BOOST_CHECK_EQUAL(center.x(), 0.0);
0166   BOOST_CHECK_EQUAL(center.y(), 0.0);
0167 }
0168 
0169 BOOST_AUTO_TEST_SUITE_END()
0170 
0171 }  // namespace ActsTests