File indexing completed on 2025-08-06 08:11:28
0001
0002
0003
0004
0005
0006
0007
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/CylinderBounds.hpp"
0016 #include "Acts/Surfaces/SurfaceBounds.hpp"
0017 #include "Acts/Tests/CommonHelpers/FloatComparisons.hpp"
0018
0019 #include <algorithm>
0020 #include <array>
0021 #include <cmath>
0022 #include <stdexcept>
0023 #include <vector>
0024
0025 namespace Acts {
0026
0027 namespace Test {
0028 BOOST_AUTO_TEST_SUITE(Surfaces)
0029
0030
0031 BOOST_AUTO_TEST_CASE(CylinderBoundsConstruction) {
0032
0033
0034 double radius(0.5), halfz(10.), halfphi(M_PI / 2.0), averagePhi(M_PI / 2.0),
0035 minBevelZ(-M_PI / 4), maxBevelZ(M_PI / 6);
0036 BOOST_CHECK_EQUAL(CylinderBounds(radius, halfz).type(),
0037 SurfaceBounds::eCylinder);
0038 BOOST_CHECK_EQUAL(CylinderBounds(radius, halfz, halfphi).type(),
0039 SurfaceBounds::eCylinder);
0040 BOOST_CHECK_EQUAL(CylinderBounds(radius, halfz, halfphi, averagePhi).type(),
0041 SurfaceBounds::eCylinder);
0042 BOOST_CHECK_EQUAL(
0043 CylinderBounds(radius, halfz, (double)M_PI, (double)0., minBevelZ).type(),
0044 SurfaceBounds::eCylinder);
0045 BOOST_CHECK_EQUAL(CylinderBounds(radius, halfz, (double)M_PI, (double)0.,
0046 minBevelZ, maxBevelZ)
0047 .type(),
0048 SurfaceBounds::eCylinder);
0049
0050
0051 CylinderBounds cylinderBounds(radius, halfz);
0052 CylinderBounds copyConstructedCylinderBounds(cylinderBounds);
0053 BOOST_CHECK_EQUAL(copyConstructedCylinderBounds, cylinderBounds);
0054 }
0055
0056 BOOST_AUTO_TEST_CASE(CylinderBoundsRecreation) {
0057
0058
0059 double radius(0.5), halfz(10.);
0060
0061 auto original = CylinderBounds(radius, halfz);
0062 auto valvector = original.values();
0063 std::array<double, CylinderBounds::eSize> values{};
0064 std::copy_n(valvector.begin(), CylinderBounds::eSize, values.begin());
0065 CylinderBounds recreated(values);
0066 BOOST_CHECK_EQUAL(original, recreated);
0067 }
0068
0069 BOOST_AUTO_TEST_CASE(CylinderBoundsException) {
0070 double radius(0.5), halfz(10.), halfphi(M_PI / 2.0), averagePhi(M_PI / 2.0);
0071
0072
0073 BOOST_CHECK_THROW(CylinderBounds(-radius, halfz, halfphi, averagePhi),
0074 std::logic_error);
0075
0076
0077 BOOST_CHECK_THROW(CylinderBounds(radius, -halfz, halfphi, averagePhi),
0078 std::logic_error);
0079
0080
0081 BOOST_CHECK_THROW(CylinderBounds(radius, halfz, -halfphi, averagePhi),
0082 std::logic_error);
0083
0084
0085 BOOST_CHECK_THROW(CylinderBounds(radius, halfz, 4., averagePhi),
0086 std::logic_error);
0087
0088
0089 BOOST_CHECK_THROW(CylinderBounds(radius, halfz, halfphi, 4.),
0090 std::logic_error);
0091 }
0092
0093
0094 BOOST_AUTO_TEST_CASE(CylinderBoundsProperties) {
0095
0096 double nominalRadius{0.5};
0097 double nominalHalfLength{20.};
0098 double halfphi(M_PI / 4.0);
0099 double averagePhi(0.0);
0100 double bevelMinZ(M_PI / 4);
0101 double bevelMaxZ(M_PI / 6);
0102 CylinderBounds cylinderBoundsObject(nominalRadius, nominalHalfLength);
0103 CylinderBounds cylinderBoundsSegment(nominalRadius, nominalHalfLength,
0104 halfphi, averagePhi);
0105 CylinderBounds cylinderBoundsBeveledObject(nominalRadius, nominalHalfLength,
0106 M_PI, 0., bevelMinZ, bevelMaxZ);
0107
0108
0109 BOOST_CHECK_EQUAL(cylinderBoundsObject.type(), SurfaceBounds::eCylinder);
0110
0111
0112 const Vector2 origin{0., 0.};
0113 const Vector2 atPiBy2{M_PI / 2., 0.0};
0114 const Vector2 atPi{M_PI, 0.0};
0115 const Vector2 beyondEnd{0, 30.0};
0116 const Vector2 unitZ{0.0, 1.0};
0117 const Vector2 unitPhi{1.0, 0.0};
0118 const Vector2 withinBevelMin{0.5, -20.012};
0119 const Vector2 outsideBevelMin{0.5, -40.};
0120 const BoundaryCheck trueBoundaryCheckWithTolerance(true, true, 0.1, 0.1);
0121 const BoundaryCheck trueBoundaryCheckWithLessTolerance(true, true, 0.01,
0122 0.01);
0123 BOOST_CHECK(
0124 cylinderBoundsObject.inside(atPiBy2, trueBoundaryCheckWithTolerance));
0125 BOOST_CHECK(
0126 !cylinderBoundsSegment.inside(unitPhi, trueBoundaryCheckWithTolerance));
0127 BOOST_CHECK(
0128 cylinderBoundsObject.inside(origin, trueBoundaryCheckWithTolerance));
0129
0130 BOOST_CHECK(!cylinderBoundsObject.inside(withinBevelMin,
0131 trueBoundaryCheckWithLessTolerance));
0132 BOOST_CHECK(cylinderBoundsBeveledObject.inside(
0133 withinBevelMin, trueBoundaryCheckWithLessTolerance));
0134 BOOST_CHECK(!cylinderBoundsBeveledObject.inside(
0135 outsideBevelMin, trueBoundaryCheckWithLessTolerance));
0136
0137
0138 const Vector3 origin3D{0., 0., 0.};
0139 BOOST_CHECK(
0140 !cylinderBoundsObject.inside3D(origin3D, trueBoundaryCheckWithTolerance));
0141
0142
0143 CHECK_CLOSE_REL(cylinderBoundsObject.get(CylinderBounds::eR), nominalRadius,
0144 1e-6);
0145
0146
0147 CHECK_CLOSE_OR_SMALL(cylinderBoundsObject.get(CylinderBounds::eAveragePhi),
0148 averagePhi, 1e-6, 1e-6);
0149
0150
0151 CHECK_CLOSE_REL(cylinderBoundsSegment.get(CylinderBounds::eHalfPhiSector),
0152 halfphi,
0153 1e-6);
0154
0155
0156 CHECK_CLOSE_REL(cylinderBoundsObject.get(CylinderBounds::eHalfLengthZ),
0157 nominalHalfLength, 1e-6);
0158
0159
0160 CHECK_CLOSE_REL(cylinderBoundsBeveledObject.get(CylinderBounds::eBevelMinZ),
0161 bevelMinZ, 1e-6);
0162 CHECK_CLOSE_REL(cylinderBoundsBeveledObject.get(CylinderBounds::eBevelMaxZ),
0163 bevelMaxZ, 1e-6);
0164
0165
0166 boost::test_tools::output_test_stream dumpOuput;
0167 cylinderBoundsObject.toStream(dumpOuput);
0168 BOOST_CHECK(dumpOuput.is_equal(
0169 "Acts::CylinderBounds: (radius, halfLengthZ, halfPhiSector, "
0170 "averagePhi, bevelMinZ, bevelMaxZ) = (0.5000000, 20.0000000, 3.1415927, "
0171 "0.0000000, 0.0000000, 0.0000000)"));
0172 }
0173
0174 BOOST_AUTO_TEST_CASE(CylinderBoundsAssignment) {
0175 double nominalRadius{0.5};
0176 double nominalHalfLength{20.};
0177 CylinderBounds cylinderBoundsObject(nominalRadius, nominalHalfLength);
0178 CylinderBounds assignedCylinderBounds(10.5, 6.6);
0179 assignedCylinderBounds = cylinderBoundsObject;
0180 BOOST_CHECK_EQUAL(assignedCylinderBounds.get(CylinderBounds::eR),
0181 cylinderBoundsObject.get(CylinderBounds::eR));
0182 BOOST_CHECK_EQUAL(assignedCylinderBounds, cylinderBoundsObject);
0183 }
0184
0185 BOOST_AUTO_TEST_SUITE_END()
0186
0187 }
0188
0189 }