File indexing completed on 2026-05-27 07:24:22
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include "detray/geometry/mask.hpp"
0011 #include "detray/geometry/shapes/rectangle2D.hpp"
0012 #include "detray/geometry/shapes/unmasked.hpp"
0013 #include "detray/geometry/surface_descriptor.hpp"
0014 #include "detray/navigation/intersection/ray_intersector.hpp"
0015 #include "detray/tracks/ray.hpp"
0016
0017
0018 #include "detray/test/framework/types.hpp"
0019
0020
0021 #include <gtest/gtest.h>
0022
0023
0024 #include <limits>
0025
0026 using namespace detray;
0027
0028
0029 using test_algebra = test::algebra;
0030 using vector3 = test::vector3;
0031 using point3 = test::point3;
0032 using scalar = test::scalar;
0033 using transform3 = test::transform3;
0034
0035 constexpr scalar tol{std::numeric_limits<scalar>::epsilon()};
0036
0037
0038 GTEST_TEST(detray_intersection, translated_plane_ray) {
0039
0040 const transform3 shifted(vector3{3.f, 2.f, 10.f});
0041
0042
0043 const point3 pos{2.f, 1.f, 0.f};
0044 const vector3 mom{0.f, 0.f, 1.f};
0045 const detail::ray<test_algebra> r(pos, 0.f, mom, 0.f);
0046
0047
0048 ray_intersector<unmasked<2>, test_algebra, true> pi;
0049 mask<unmasked<2>, test_algebra> unmasked_bound{};
0050 const auto hit_bound = pi(r, surface_descriptor<>{}, unmasked_bound, shifted);
0051
0052 ASSERT_TRUE(hit_bound.is_inside());
0053
0054 const auto global0 =
0055 unmasked_bound.to_global_frame(shifted, hit_bound.local());
0056 ASSERT_NEAR(global0[0], 2.f, tol);
0057 ASSERT_NEAR(global0[1], 1.f, tol);
0058 ASSERT_NEAR(global0[2], 10.f, tol);
0059
0060 ASSERT_NEAR(hit_bound.local()[0], -1.f, tol);
0061 ASSERT_NEAR(hit_bound.local()[1], -1.f, tol);
0062
0063
0064 mask<rectangle2D, test_algebra> rect_for_inside{0u, 3.f, 3.f};
0065 const auto hit_bound_inside =
0066 pi(r, surface_descriptor<>{}, rect_for_inside, shifted, tol);
0067
0068 ASSERT_TRUE(hit_bound_inside.is_inside());
0069
0070 const auto global1 =
0071 rect_for_inside.to_global_frame(shifted, hit_bound_inside.local());
0072 ASSERT_NEAR(global1[0], 2.f, tol);
0073 ASSERT_NEAR(global1[1], 1.f, tol);
0074 ASSERT_NEAR(global1[2], 10.f, tol);
0075
0076 ASSERT_NEAR(hit_bound_inside.local()[0], -1.f, tol);
0077 ASSERT_NEAR(hit_bound_inside.local()[1], -1.f, tol);
0078
0079
0080 mask<rectangle2D, test_algebra> rect_for_outside{0u, 0.5f, 3.5f};
0081 const auto hit_bound_outside =
0082 pi(r, surface_descriptor<>{}, rect_for_outside, shifted, tol);
0083 ASSERT_FALSE(hit_bound_outside.is_inside());
0084
0085 const auto global2 =
0086 rect_for_outside.to_global_frame(shifted, hit_bound_outside.local());
0087 ASSERT_NEAR(global2[0], 2.f, tol);
0088 ASSERT_NEAR(global2[1], 1.f, tol);
0089 ASSERT_NEAR(global2[2], 10.f, tol);
0090
0091 ASSERT_NEAR(hit_bound_outside.local()[0], -1.f, tol);
0092 ASSERT_NEAR(hit_bound_outside.local()[1], -1.f, tol);
0093 }