File indexing completed on 2025-01-18 09:12:53
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/BoundaryTolerance.hpp"
0015 #include "Acts/Surfaces/RectangleBounds.hpp"
0016 #include "Acts/Surfaces/SurfaceBounds.hpp"
0017 #include "Acts/Surfaces/TrapezoidBounds.hpp"
0018 #include "Acts/Surfaces/detail/BoundaryCheckHelper.hpp"
0019
0020 #include <algorithm>
0021 #include <array>
0022 #include <optional>
0023 #include <random>
0024 #include <stdexcept>
0025 #include <vector>
0026
0027 namespace bdata = boost::unit_test::data;
0028
0029 namespace Acts::Test {
0030
0031 BOOST_AUTO_TEST_SUITE(Surfaces)
0032
0033 const double minHalfX = 1.;
0034 const double maxHalfX = 6.;
0035 const double halfY = 2.;
0036
0037
0038 BOOST_AUTO_TEST_CASE(TrapezoidBoundsConstruction) {
0039
0040
0041
0042
0043 BOOST_CHECK_EQUAL(TrapezoidBounds(minHalfX, maxHalfX, halfY).type(),
0044 SurfaceBounds::eTrapezoid);
0045
0046 TrapezoidBounds original(minHalfX, maxHalfX, halfY);
0047 TrapezoidBounds copied(original);
0048 BOOST_CHECK_EQUAL(copied, original);
0049 }
0050
0051
0052 BOOST_AUTO_TEST_CASE(TrapezoidBoundsRecreated) {
0053
0054 TrapezoidBounds original(minHalfX, maxHalfX, halfY);
0055
0056 auto valvector = original.values();
0057 std::array<double, TrapezoidBounds::eSize> values{};
0058 std::copy_n(valvector.begin(), TrapezoidBounds::eSize, values.begin());
0059 TrapezoidBounds recreated(values);
0060 BOOST_CHECK_EQUAL(original, recreated);
0061 }
0062
0063
0064 BOOST_AUTO_TEST_CASE(TrapezoidBoundsException) {
0065
0066 BOOST_CHECK_THROW(TrapezoidBounds(-minHalfX, maxHalfX, halfY),
0067 std::logic_error);
0068
0069
0070 BOOST_CHECK_THROW(TrapezoidBounds(minHalfX, -maxHalfX, halfY),
0071 std::logic_error);
0072
0073
0074 BOOST_CHECK_THROW(TrapezoidBounds(-minHalfX, -maxHalfX, halfY),
0075 std::logic_error);
0076
0077
0078 BOOST_CHECK_THROW(TrapezoidBounds(minHalfX, maxHalfX, -halfY),
0079 std::logic_error);
0080 }
0081
0082
0083 BOOST_AUTO_TEST_CASE(TrapezoidBoundsProperties) {
0084 TrapezoidBounds trapezoidBoundsObject(minHalfX, maxHalfX, halfY);
0085
0086
0087 BOOST_CHECK_EQUAL(trapezoidBoundsObject.type(), SurfaceBounds::eTrapezoid);
0088
0089
0090 BOOST_CHECK_EQUAL(
0091 trapezoidBoundsObject.get(TrapezoidBounds::eHalfLengthXnegY), minHalfX);
0092
0093
0094 BOOST_CHECK_EQUAL(
0095 trapezoidBoundsObject.get(TrapezoidBounds::eHalfLengthXposY), maxHalfX);
0096
0097
0098 BOOST_CHECK_EQUAL(trapezoidBoundsObject.get(TrapezoidBounds::eHalfLengthY),
0099 halfY);
0100
0101
0102 Vector2 outside(30., 0.);
0103 Vector2 inRectangle(2., 0.5);
0104
0105
0106 std::vector<Vector2> expectedVertices{
0107 {-1., -2.}, {1., -2.}, {6., 2.}, {-6., 2.}};
0108 const auto& actualVertices = trapezoidBoundsObject.vertices();
0109 BOOST_CHECK_EQUAL_COLLECTIONS(actualVertices.cbegin(), actualVertices.cend(),
0110 expectedVertices.cbegin(),
0111 expectedVertices.cend());
0112
0113
0114 BOOST_CHECK_EQUAL(trapezoidBoundsObject.boundingBox(),
0115 RectangleBounds(6., 2.));
0116
0117
0118 boost::test_tools::output_test_stream dumpOutput;
0119 trapezoidBoundsObject.toStream(dumpOutput);
0120 BOOST_CHECK(dumpOutput.is_equal(
0121 "Acts::TrapezoidBounds: (halfXnegY, halfXposY, halfY, rotAngle) = "
0122 "(1.0000000, 6.0000000, 2.0000000, 0.0000000)"));
0123
0124
0125 BOOST_CHECK(
0126 trapezoidBoundsObject.inside(inRectangle, BoundaryTolerance::None()));
0127 BOOST_CHECK(
0128 !trapezoidBoundsObject.inside(outside, BoundaryTolerance::None()));
0129
0130 const auto vertices = trapezoidBoundsObject.vertices();
0131 BoundaryTolerance tolerance = BoundaryTolerance::None();
0132
0133 std::vector<Vector2> testPoints = {
0134
0135 {0, 1},
0136 {0, -1},
0137 {2, 0.5},
0138 {2, 0},
0139 {-2, 0},
0140 {-2, 0.5},
0141 {3, 1},
0142 {-3, 1},
0143 {4, 1},
0144 {-4, 1},
0145 {-6, 2},
0146
0147
0148 {0, 2.5},
0149 {0, -2.5},
0150 {2, 2.5},
0151 {-2, 2.5},
0152 {2, -2.5},
0153 {-2, -2.5},
0154 {4, -1},
0155 {-4, -1},
0156 {-7, 0},
0157 {7, 0},
0158 {5, -3},
0159 {5, 3},
0160 {-5, -3},
0161 {-5, 3},
0162 {6, 2},
0163 };
0164
0165 for (const auto& p : testPoints) {
0166 BOOST_TEST_CONTEXT("p=" << p.transpose()) {
0167 BOOST_CHECK_EQUAL(
0168 detail::insidePolygon(vertices, tolerance, p, std::nullopt),
0169 trapezoidBoundsObject.inside(p, tolerance));
0170 }
0171 }
0172 }
0173
0174 BOOST_DATA_TEST_CASE(
0175 TrapezoidInsideCheck,
0176 bdata::random(
0177 (bdata::engine = std::mt19937(), bdata::seed = 21,
0178 bdata::distribution = std::uniform_real_distribution<double>(-7, 7))) ^
0179 bdata::random((bdata::engine = std::mt19937(), bdata::seed = 22,
0180 bdata::distribution =
0181 std::uniform_real_distribution<double>(-3, 3))) ^
0182 bdata::xrange(1000) * bdata::make({0., 0.1, 0.2, 0.3}),
0183 x, y, index, tol) {
0184 (void)index;
0185
0186 static const TrapezoidBounds trapezoidBoundsObject(minHalfX, maxHalfX, halfY);
0187 static const auto vertices = trapezoidBoundsObject.vertices();
0188
0189 BoundaryTolerance tolerance = BoundaryTolerance::None();
0190
0191 if (tol != 0.) {
0192 tolerance = BoundaryTolerance::AbsoluteBound(tol, tol);
0193 }
0194
0195 BOOST_CHECK_EQUAL(
0196 detail::insidePolygon(vertices, tolerance, {x, y}, std::nullopt),
0197 trapezoidBoundsObject.inside({x, y}, tolerance));
0198 }
0199
0200
0201 BOOST_AUTO_TEST_CASE(TrapezoidBoundsAssignment) {
0202 TrapezoidBounds trapezoidBoundsObject(minHalfX, maxHalfX, halfY);
0203
0204
0205
0206
0207
0208 TrapezoidBounds assignedTrapezoidBoundsObject(10., 20., 14.2);
0209 assignedTrapezoidBoundsObject = trapezoidBoundsObject;
0210 BOOST_CHECK_EQUAL(assignedTrapezoidBoundsObject, trapezoidBoundsObject);
0211 }
0212
0213 BOOST_AUTO_TEST_SUITE_END()
0214
0215 }