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