File indexing completed on 2026-05-27 07:24:24
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include "detray/utils/quadratic_equation.hpp"
0011
0012 #include "detray/definitions/algebra.hpp"
0013 #include "detray/utils/tuple_helpers.hpp"
0014
0015
0016 #include "detray/test/framework/types.hpp"
0017
0018
0019 #include <gtest/gtest.h>
0020
0021 using namespace detray;
0022
0023 using scalar = test::scalar;
0024
0025
0026 GTEST_TEST(detray_utils, quadratic_equation) {
0027 static constexpr scalar epsilon{1e-5f};
0028
0029
0030 detail::quadratic_equation<scalar> qe1{1.5f, 0.f, 1.f};
0031
0032 ASSERT_EQ(qe1.solutions(), 0);
0033
0034
0035 detail::quadratic_equation<scalar> qe2{1.f, 0.f, 0.f};
0036
0037 ASSERT_EQ(qe2.solutions(), 1);
0038 EXPECT_NEAR(qe2.smaller(), 0.f, epsilon);
0039
0040 detail::quadratic_equation<scalar> qe3{0.f, 1.f, 2.f};
0041
0042 ASSERT_EQ(qe3.solutions(), 1);
0043 EXPECT_NEAR(qe3.smaller(), -2.f, epsilon);
0044
0045
0046 detail::quadratic_equation<scalar> qe4{2.f, 5.f, 3.f};
0047
0048 ASSERT_EQ(qe4.solutions(), 2);
0049 EXPECT_NEAR(qe4.smaller(), -1.5f, epsilon);
0050 EXPECT_NEAR(qe4.larger(), -1.f, epsilon);
0051
0052 detail::quadratic_equation<scalar> qe5{2.f, 5.f, -3.f};
0053
0054 ASSERT_EQ(qe5.solutions(), 2);
0055 EXPECT_NEAR(qe5.smaller(), -3.f, epsilon);
0056 EXPECT_NEAR(qe5.larger(), 0.5f, epsilon);
0057
0058 detail::quadratic_equation<scalar> qe6{2.f, -5.f, 3.f};
0059
0060 ASSERT_EQ(qe6.solutions(), 2);
0061 EXPECT_NEAR(qe6.smaller(), 1.f, epsilon);
0062 EXPECT_NEAR(qe6.larger(), 1.5f, epsilon);
0063
0064 detail::quadratic_equation<scalar> qe7{2.f, -5.f, -3.f};
0065
0066 ASSERT_EQ(qe7.solutions(), 2);
0067 EXPECT_NEAR(qe7.smaller(), -0.5f, epsilon);
0068 EXPECT_NEAR(qe7.larger(), 3.f, epsilon);
0069
0070 detail::quadratic_equation<scalar> qe8{2.f, -5.f, 0.f};
0071
0072 ASSERT_EQ(qe8.solutions(), 2);
0073 EXPECT_NEAR(qe8.smaller(), 0.f, epsilon);
0074 EXPECT_NEAR(qe8.larger(), 5.f / 2.f, epsilon);
0075 }