File indexing completed on 2026-05-27 07:24:21
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include "detray/geometry/shapes/unbounded.hpp"
0011
0012 #include "detray/definitions/units.hpp"
0013 #include "detray/geometry/concepts.hpp"
0014 #include "detray/geometry/mask.hpp"
0015 #include "detray/geometry/shapes/rectangle2D.hpp"
0016
0017
0018 #include "detray/test/framework/types.hpp"
0019
0020
0021 #include <gtest/gtest.h>
0022
0023
0024 #include <cassert>
0025 #include <type_traits>
0026
0027 using namespace detray;
0028
0029 using test_algebra = test::algebra;
0030 using scalar = test::scalar;
0031 using point3 = test::point3;
0032 using transform3 = test::transform3;
0033
0034 constexpr scalar tol{1e-7f};
0035
0036
0037 GTEST_TEST(detray_masks, unbounded) {
0038 using shape_t = rectangle2D;
0039 using unbounded_t = unbounded<shape_t>;
0040
0041 static_assert(concepts::shape<unbounded_t, test_algebra>);
0042 static_assert(concepts::planar_shape<unbounded_t, test_algebra>);
0043
0044 constexpr scalar h{20.f * unit<scalar>::mm};
0045
0046 mask<unbounded_t, test_algebra> u{0u, h, h};
0047
0048
0049 static_assert(std::is_same_v<unbounded_t::shape, shape_t>, "incorrect shape");
0050 static_assert(std::is_same_v<unbounded_t::boundaries, shape_t::boundaries>,
0051 "incorrect boundaries");
0052 static_assert(
0053 std::is_same_v<unbounded_t::template local_frame_type<test_algebra>,
0054 shape_t::template local_frame_type<test_algebra>>,
0055 "incorrect local frame");
0056
0057
0058 EXPECT_TRUE(std::string(unbounded_t::name) ==
0059 std::string("unbounded rectangle2D"));
0060
0061
0062 typename mask<unbounded_t, test_algebra>::point3_type p2 = {0.5f, -9.f, 0.f};
0063 ASSERT_TRUE(u.is_inside(p2, 0.f));
0064
0065
0066 constexpr scalar envelope{0.01f};
0067 const auto loc_bounds = u.local_min_bounds(envelope);
0068 ASSERT_NEAR(loc_bounds[cuboid3D::e_min_x], -(h + envelope), tol);
0069 ASSERT_NEAR(loc_bounds[cuboid3D::e_min_y], -(h + envelope), tol);
0070 ASSERT_NEAR(loc_bounds[cuboid3D::e_min_z], -envelope, tol);
0071 ASSERT_NEAR(loc_bounds[cuboid3D::e_max_x], (h + envelope), tol);
0072 ASSERT_NEAR(loc_bounds[cuboid3D::e_max_y], (h + envelope), tol);
0073 ASSERT_NEAR(loc_bounds[cuboid3D::e_max_z], envelope, tol);
0074
0075
0076 const scalar a{u.area()};
0077 EXPECT_NEAR(a, std::numeric_limits<scalar>::max(), tol);
0078 ASSERT_EQ(a, u.measure());
0079
0080 const auto centroid = u.centroid();
0081 ASSERT_NEAR(centroid[0], 0.f, tol);
0082 ASSERT_NEAR(centroid[1], 0.f, tol);
0083 ASSERT_NEAR(centroid[2], 0.f, tol);
0084 }