File indexing completed on 2025-01-18 09:12:58
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/Tests/CommonHelpers/FloatComparisons.hpp"
0013 #include "Acts/Utilities/Interpolation.hpp"
0014
0015 #include <array>
0016 #include <vector>
0017
0018 using namespace Acts::detail;
0019
0020 namespace Acts::Test {
0021
0022 BOOST_AUTO_TEST_CASE(interpolation_1d) {
0023 using Point = std::array<double, 1u>;
0024 using Values = std::array<double, 2u>;
0025
0026 Point low = {{1.}};
0027 Point high = {{2.}};
0028 Values v = {{10., 20.}};
0029
0030 CHECK_CLOSE_REL(interpolate(Point({{0.5}}), low, high, v), 5., 1e-6);
0031 CHECK_CLOSE_REL(interpolate(Point({{1.}}), low, high, v), 10., 1e-6);
0032 CHECK_CLOSE_REL(interpolate(Point({{1.3}}), low, high, v), 13., 1e-6);
0033 CHECK_CLOSE_REL(interpolate(Point({{1.5}}), low, high, v), 15., 1e-6);
0034 CHECK_CLOSE_REL(interpolate(Point({{1.8}}), low, high, v), 18., 1e-6);
0035 CHECK_CLOSE_REL(interpolate(Point({{2.}}), low, high, v), 20., 1e-6);
0036 CHECK_CLOSE_REL(interpolate(Point({{2.3}}), low, high, v), 23., 1e-6);
0037 }
0038
0039 BOOST_AUTO_TEST_CASE(interpolation_2d) {
0040 using Point = std::array<double, 2u>;
0041 using Values = std::array<double, 4u>;
0042
0043 Point low = {{1., 1.}};
0044 Point high = {{2., 3.}};
0045 Values v = {{10., 30., 20., 40.}};
0046
0047 CHECK_CLOSE_REL(interpolate(Point({{1., 1.}}), low, high, v), 10., 1e-6);
0048 CHECK_CLOSE_REL(interpolate(Point({{2., 1.}}), low, high, v), 20., 1e-6);
0049 CHECK_CLOSE_REL(interpolate(Point({{1., 3.}}), low, high, v), 30., 1e-6);
0050 CHECK_CLOSE_REL(interpolate(Point({{2., 3.}}), low, high, v), 40., 1e-6);
0051 CHECK_CLOSE_REL(interpolate(Point({{1.3, 1.}}), low, high, v), 13., 1e-6);
0052 CHECK_CLOSE_REL(interpolate(Point({{1.5, 1.}}), low, high, v), 15., 1e-6);
0053 CHECK_CLOSE_REL(interpolate(Point({{1.8, 1.}}), low, high, v), 18., 1e-6);
0054 CHECK_CLOSE_REL(interpolate(Point({{1.3, 3.}}), low, high, v), 33., 1e-6);
0055 CHECK_CLOSE_REL(interpolate(Point({{1.5, 3.}}), low, high, v), 35., 1e-6);
0056 CHECK_CLOSE_REL(interpolate(Point({{1.8, 3.}}), low, high, v), 38., 1e-6);
0057 CHECK_CLOSE_REL(interpolate(Point({{1., 1.7}}), low, high, v), 17., 1e-6);
0058 CHECK_CLOSE_REL(interpolate(Point({{1., 2.}}), low, high, v), 20., 1e-6);
0059 CHECK_CLOSE_REL(interpolate(Point({{1., 2.5}}), low, high, v), 25., 1e-6);
0060 CHECK_CLOSE_REL(interpolate(Point({{2., 1.7}}), low, high, v), 27., 1e-6);
0061 CHECK_CLOSE_REL(interpolate(Point({{2., 2.}}), low, high, v), 30., 1e-6);
0062 CHECK_CLOSE_REL(interpolate(Point({{2., 2.5}}), low, high, v), 35., 1e-6);
0063 CHECK_CLOSE_REL(interpolate(Point({{1.5, 2.}}), low, high, v), 25., 1e-6);
0064 CHECK_CLOSE_REL(interpolate(Point({{1.3, 1.7}}), low, high, v), 20., 1e-6);
0065 CHECK_CLOSE_REL(interpolate(Point({{1.3, 2.5}}), low, high, v), 28., 1e-6);
0066 CHECK_CLOSE_REL(interpolate(Point({{1.8, 1.7}}), low, high, v), 25., 1e-6);
0067 CHECK_CLOSE_REL(interpolate(Point({{1.8, 2.5}}), low, high, v), 33., 1e-6);
0068 }
0069
0070 BOOST_AUTO_TEST_CASE(interpolation_3d) {
0071 using Point = std::array<double, 3u>;
0072 using Values = std::array<double, 8u>;
0073
0074 Point low = {{1., 1., 1.}};
0075 Point high = {{2., 3., 4.}};
0076 Values v = {{10., 50., 30., 70., 20., 60., 40., 80.}};
0077
0078 CHECK_CLOSE_REL(interpolate(Point({{1., 1., 1.}}), low, high, v), 10., 1e-6);
0079 CHECK_CLOSE_REL(interpolate(Point({{2., 1., 1.}}), low, high, v), 20., 1e-6);
0080 CHECK_CLOSE_REL(interpolate(Point({{1., 3., 1.}}), low, high, v), 30., 1e-6);
0081 CHECK_CLOSE_REL(interpolate(Point({{2., 3., 1.}}), low, high, v), 40., 1e-6);
0082 CHECK_CLOSE_REL(interpolate(Point({{1., 1., 4.}}), low, high, v), 50., 1e-6);
0083 CHECK_CLOSE_REL(interpolate(Point({{2., 1., 4.}}), low, high, v), 60., 1e-6);
0084 CHECK_CLOSE_REL(interpolate(Point({{1., 3., 4.}}), low, high, v), 70., 1e-6);
0085 CHECK_CLOSE_REL(interpolate(Point({{2., 3., 4.}}), low, high, v), 80., 1e-6);
0086 CHECK_CLOSE_REL(interpolate(Point({{1.5, 1., 1.}}), low, high, v), 15., 1e-6);
0087 CHECK_CLOSE_REL(interpolate(Point({{1.5, 3., 1.}}), low, high, v), 35., 1e-6);
0088 CHECK_CLOSE_REL(interpolate(Point({{1., 2., 1.}}), low, high, v), 20., 1e-6);
0089 CHECK_CLOSE_REL(interpolate(Point({{2., 2., 1.}}), low, high, v), 30., 1e-6);
0090 CHECK_CLOSE_REL(interpolate(Point({{1.5, 1., 4.}}), low, high, v), 55., 1e-6);
0091 CHECK_CLOSE_REL(interpolate(Point({{1.5, 3., 4.}}), low, high, v), 75., 1e-6);
0092 CHECK_CLOSE_REL(interpolate(Point({{1., 2., 4.}}), low, high, v), 60., 1e-6);
0093 CHECK_CLOSE_REL(interpolate(Point({{2., 2., 4.}}), low, high, v), 70., 1e-6);
0094 CHECK_CLOSE_REL(interpolate(Point({{1., 1., 2.5}}), low, high, v), 30., 1e-6);
0095 CHECK_CLOSE_REL(interpolate(Point({{1., 3., 2.5}}), low, high, v), 50., 1e-6);
0096 CHECK_CLOSE_REL(interpolate(Point({{2., 1., 2.5}}), low, high, v), 40., 1e-6);
0097 CHECK_CLOSE_REL(interpolate(Point({{2., 3., 2.5}}), low, high, v), 60., 1e-6);
0098 CHECK_CLOSE_REL(interpolate(Point({{1.5, 2., 2.5}}), low, high, v), 360. / 8,
0099 1e-6);
0100 CHECK_CLOSE_REL(interpolate(Point({{1.3, 2.1, 1.6}}), low, high, v), 32.,
0101 1e-6);
0102 }
0103
0104 BOOST_AUTO_TEST_CASE(interpolation_mixed_point_values) {
0105 using Point1 = ActsVector<1>;
0106 using Point2 = std::array<double, 1u>;
0107 using Point3 = std::vector<double>;
0108 using Values = std::array<double, 2u>;
0109
0110 Point2 low = {{1.}};
0111 Point3 high = {2.};
0112 Values v = {{10., 20.}};
0113
0114 Point1 p;
0115 CHECK_CLOSE_REL(interpolate((p << 0.5).finished(), low, high, v), 5., 1e-6);
0116 CHECK_CLOSE_REL(interpolate((p << 1.).finished(), low, high, v), 10., 1e-6);
0117 CHECK_CLOSE_REL(interpolate((p << 1.3).finished(), low, high, v), 13., 1e-6);
0118 CHECK_CLOSE_REL(interpolate((p << 1.5).finished(), low, high, v), 15., 1e-6);
0119 CHECK_CLOSE_REL(interpolate((p << 1.8).finished(), low, high, v), 18., 1e-6);
0120 CHECK_CLOSE_REL(interpolate((p << 2.).finished(), low, high, v), 20., 1e-6);
0121 CHECK_CLOSE_REL(interpolate((p << 2.3).finished(), low, high, v), 23., 1e-6);
0122 }
0123
0124 }