Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-27 07:24:22

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 // Project include(s)
0010 #include "detray/definitions/indexing.hpp"
0011 #include "detray/geometry/surface_descriptor.hpp"
0012 #include "detray/navigation/intersection/intersection.hpp"
0013 #include "detray/utils/invalid_values.hpp"
0014 
0015 // Detray test include(s)
0016 #include "detray/test/framework/types.hpp"
0017 
0018 // Google test include(s)
0019 #include <gtest/gtest.h>
0020 
0021 // System include(s)
0022 #include <limits>
0023 
0024 using namespace detray;
0025 
0026 using scalar = test::scalar;
0027 
0028 namespace {
0029 
0030 /// Define mask types
0031 enum class mask_id : unsigned int {
0032   e_unmasked = 0u,
0033 };
0034 
0035 /// Define material types
0036 enum class material_id : unsigned int {
0037   e_material_slab = 0u,
0038 };
0039 
0040 constexpr scalar tol{std::numeric_limits<scalar>::epsilon()};
0041 
0042 }  // namespace
0043 
0044 using test_algebra = test::algebra;
0045 using scalar_t = dscalar<test_algebra>;
0046 using point2 = test::point2;
0047 using vector3 = test::vector3;
0048 using point3 = test::point3;
0049 
0050 using mask_link_t = dtyped_index<mask_id, dindex>;
0051 using material_link_t = dtyped_index<material_id, dindex>;
0052 using surface_t =
0053     surface_descriptor<mask_link_t, material_link_t, test_algebra>;
0054 
0055 // This tests the construction of a intresection
0056 GTEST_TEST(detray_intersection, intersection2D) {
0057   using enum detray::intersection::status;
0058 
0059   using intersection_t =
0060       intersection2D<surface_t, test_algebra, intersection::contains_pos>;
0061   using nominal_inters_t =
0062       intersection2D<surface_t, test_algebra, !intersection::contains_pos>;
0063 
0064   // Check memory layout of intersection struct (uncomment for debugging)
0065   /*static_assert(offsetof(nominal_inters_t, m_surface) == 0);
0066   static_assert(offsetof(nominal_inters_t, m_ip) == 16);
0067   // Depends on floating point precision of 'path' member variable
0068   static_assert((offsetof(nominal_inters_t, m_volume_link) == 20) ||
0069                 (offsetof(nominal_inters_t, m_volume_link) == 24));
0070   static_assert((offsetof(nominal_inters_t, m_status) == 22) ||
0071                 (offsetof(nominal_inters_t, m_status) == 26));
0072   static_assert((offsetof(nominal_inters_t, m_direction) == 23) ||
0073                 (offsetof(nominal_inters_t, m_direction) == 27));*/
0074 
0075   // 24 bytes for single precision, 32 bytes for double
0076   static_assert((sizeof(nominal_inters_t) == 24) ||
0077                 (sizeof(nominal_inters_t) == 32));
0078 
0079   const surface_t sf{};
0080   const point3 test_pt{0.2f, 0.4f, 0.f};
0081 
0082   intersection_t i0{sf, 2.f, test_pt, 1u, e_outside, true};
0083   intersection_t i1{sf, 1.7f, test_pt, 0u, e_inside, false};
0084 
0085   intersection_t invalid{};
0086   ASSERT_FALSE(invalid.is_inside());
0087 
0088   dvector<intersection_t> intersections = {invalid, i0, i1};
0089   std::ranges::sort(intersections);
0090 
0091   ASSERT_NEAR(intersections[0].path(), 1.7f, tol);
0092   ASSERT_NEAR(intersections[1].path(), 2.f, tol);
0093   ASSERT_TRUE(detail::is_invalid_value(intersections[2].path()));
0094 }