File indexing completed on 2025-01-18 09:12:50
0001
0002
0003
0004
0005
0006
0007
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/ConvexPolygonBounds.hpp"
0014 #include "Acts/Surfaces/RectangleBounds.hpp"
0015
0016 #include <algorithm>
0017 #include <array>
0018 #include <stdexcept>
0019 #include <vector>
0020
0021 using vec2 = Acts::Vector2;
0022 template <int N>
0023 using poly = Acts::ConvexPolygonBounds<N>;
0024
0025 namespace Acts::Test {
0026
0027 BOOST_AUTO_TEST_SUITE(Surfaces)
0028
0029 BOOST_AUTO_TEST_CASE(ConvexPolygonBoundsConvexity) {
0030 std::vector<vec2> vertices;
0031 vertices = {{0, 0}, {1, 0}, {0.2, 0.2}, {0, 1}};
0032 { BOOST_CHECK_THROW(poly<4> quad(vertices), std::logic_error); }
0033
0034 vertices = {{0, 0}, {1, 0}, {0.8, 0.8}, {0, 1}};
0035 {
0036
0037 BOOST_CHECK_THROW(poly<3> trip{vertices}, AssertionFailureException);
0038 }
0039 { poly<4> quad = {vertices}; }
0040
0041
0042 vertices = {{0, 0}, {1, 0}, {0.5, 1}, {0.9, 1.2}};
0043 { BOOST_CHECK_THROW(poly<4> quad{vertices}, std::logic_error); }
0044
0045
0046 vertices = {{0, 0}, {1, 0}, {0.9, 1.2}, {0.5, 1}};
0047 { poly<4> quad = {vertices}; }
0048
0049 vertices = {{0, 0}, {1, 0}, {0.8, 0.5}, {1, 1}, {0, 1}};
0050 { BOOST_CHECK_THROW(poly<5> pent(vertices), std::logic_error); }
0051
0052 vertices = {{0, 0}, {1, 0}, {1.1, 0.5}, {1, 1}, {0, 1}};
0053 { poly<5> pent{vertices}; }
0054 }
0055
0056 BOOST_AUTO_TEST_CASE(ConvexPolygonBoundsConstruction) {
0057 std::vector<vec2> vertices;
0058
0059
0060 vertices = {{0, 0}, {1, 0}, {0.5, 1}};
0061 poly<3> triangle(vertices);
0062
0063 RectangleBounds bb = triangle.boundingBox();
0064 BOOST_CHECK_EQUAL(bb.min(), Vector2(0, 0));
0065 BOOST_CHECK_EQUAL(bb.max(), Vector2(1., 1));
0066
0067 BoundaryTolerance tolerance = BoundaryTolerance::None();
0068
0069 BOOST_CHECK(triangle.inside({0.2, 0.2}, tolerance));
0070 BOOST_CHECK(!triangle.inside({0.4, 0.9}, tolerance));
0071 BOOST_CHECK(!triangle.inside({0.8, 0.8}, tolerance));
0072 BOOST_CHECK(!triangle.inside({0.3, -0.2}, tolerance));
0073
0074
0075 vertices = {{0, 0}, {1, 0}, {0.9, 1.2}, {0.5, 1}};
0076 poly<4> quad(vertices);
0077
0078 bb = quad.boundingBox();
0079 BOOST_CHECK_EQUAL(bb.min(), Vector2(0, 0));
0080 BOOST_CHECK_EQUAL(bb.max(), Vector2(1, 1.2));
0081
0082 BOOST_CHECK(quad.inside({0.2, 0.2}, tolerance));
0083 BOOST_CHECK(!quad.inside({0.4, 0.9}, tolerance));
0084 BOOST_CHECK(quad.inside({0.8, 0.8}, tolerance));
0085 BOOST_CHECK(!quad.inside({0.3, -0.2}, tolerance));
0086 }
0087
0088 BOOST_AUTO_TEST_CASE(ConvexPolygonBoundsRecreation) {
0089
0090 std::vector<vec2> vertices = {{0, 0}, {1, 0}, {0.9, 1.2}, {0.5, 1}};
0091 poly<4> original(vertices);
0092
0093 auto valvector = original.values();
0094 std::array<double, poly<4>::eSize> values{};
0095 std::copy_n(valvector.begin(), poly<4>::eSize, values.begin());
0096 poly<4> recreated(values);
0097 BOOST_CHECK_EQUAL(original, recreated);
0098
0099
0100 auto rvertices = original.vertices();
0101 BOOST_CHECK_EQUAL(rvertices.size(), 4u);
0102 }
0103
0104 BOOST_AUTO_TEST_CASE(ConvexPolygonBoundsDynamicTest) {
0105 using poly = ConvexPolygonBounds<PolygonDynamic>;
0106
0107 std::vector<vec2> vertices;
0108
0109
0110 vertices = {{0, 0}, {1, 0}, {0.5, 1}};
0111 poly triangle(vertices);
0112
0113 RectangleBounds bb = triangle.boundingBox();
0114 BOOST_CHECK_EQUAL(bb.min(), Vector2(0, 0));
0115 BOOST_CHECK_EQUAL(bb.max(), Vector2(1., 1));
0116
0117 BoundaryTolerance tolerance = BoundaryTolerance::None();
0118
0119 BOOST_CHECK(triangle.inside({0.2, 0.2}, tolerance));
0120 BOOST_CHECK(!triangle.inside({0.4, 0.9}, tolerance));
0121 BOOST_CHECK(!triangle.inside({0.8, 0.8}, tolerance));
0122 BOOST_CHECK(!triangle.inside({0.3, -0.2}, tolerance));
0123 }
0124
0125 BOOST_AUTO_TEST_SUITE_END()
0126
0127 }