Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-27 07:23:59

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 #pragma once
0010 
0011 // Project include(s)
0012 #include "detray/definitions/algebra.hpp"
0013 #include "detray/definitions/containers.hpp"
0014 #include "detray/definitions/detail/qualifiers.hpp"
0015 #include "detray/definitions/indexing.hpp"
0016 #include "detray/geometry/detail/shape_utils.hpp"
0017 #include "detray/utils/string_helpers.hpp"
0018 
0019 // System include(s)
0020 #include <limits>
0021 #include <ostream>
0022 #include <string>
0023 #include <string_view>
0024 
0025 namespace detray {
0026 
0027 /// @brief Wraps any shape, but does not enforce boundaries
0028 template <typename shape_t>
0029 class unbounded {
0030  public:
0031   using shape = shape_t;
0032   using boundaries = typename shape::boundaries;
0033 
0034   /// Container definition for the shape boundary values
0035   template <concepts::scalar scalar_t>
0036   using bounds_type = darray<scalar_t, boundaries::e_size>;
0037 
0038   /// Convenience member to construct the name
0039   static constexpr std::string_view name_prefix = "unbounded ";
0040 
0041   /// The name for this shape
0042   static constexpr utils::string_view_concat2 name{name_prefix, shape::name};
0043 
0044   /// Local coordinate frame for boundary checks
0045   template <concepts::algebra algebra_t>
0046   using local_frame_type = typename shape::template local_frame_type<algebra_t>;
0047 
0048   /// Result type of a boundary check
0049   template <typename bool_t>
0050   using result_type = detail::boundary_check_result<bool_t>;
0051 
0052   /// Dimension of the local coordinate system
0053   static constexpr std::size_t dim{shape_t::dim};
0054 
0055   /// @brief Find the minimum distance to any boundary.
0056   ///
0057   /// @note the point is expected to be given in local coordinates by the
0058   /// caller.
0059   ///
0060   /// @param bounds the boundary values for this shape
0061   /// @param loc_p the point to be checked in the local coordinate system
0062   ///
0063   /// @return the minimum distance.
0064   template <concepts::scalar scalar_t, concepts::point point_t>
0065   DETRAY_HOST_DEVICE constexpr scalar_t min_dist_to_boundary(
0066       const bounds_type<scalar_t>& /*bounds*/, const point_t& /*loc_p*/) const {
0067     return std::numeric_limits<scalar_t>::max();
0068   }
0069 
0070   /// @brief Check boundary values for a local point.
0071   ///
0072   /// @tparam bounds_t any type of boundary values
0073   ///
0074   /// @note the parameters are ignored
0075   ///
0076   /// @return always true
0077   /// @{
0078   template <concepts::algebra algebra_t>
0079   DETRAY_HOST_DEVICE constexpr result_type<dbool<algebra_t>> check_boundaries(
0080       const bounds_type<dscalar<algebra_t>>& /*bounds*/,
0081       const dtransform3D<algebra_t>& /*trf*/,
0082       const dpoint3D<algebra_t>& /*glob_p*/,
0083       const dscalar<algebra_t> /*tol*/ = 0.f,
0084       const dscalar<algebra_t> /*edge_tol*/ = 0.f) const {
0085     if constexpr (std::same_as<result_type<dbool<algebra_t>>,
0086                                dbool<algebra_t>>) {
0087       return true;
0088     } else {
0089       return {true, true};
0090     }
0091   }
0092 
0093   template <typename bounds_t, concepts::point point_t,
0094             concepts::scalar scalar_t>
0095   DETRAY_HOST_DEVICE constexpr auto check_boundaries(
0096       const bounds_t& /*bounds*/, const point_t& /*loc_p*/,
0097       const scalar_t tol = 0.f, const scalar_t edge_tol = 0.f) const {
0098     using bool_t = decltype(tol < edge_tol);
0099 
0100     if constexpr (std::same_as<result_type<bool_t>, bool_t>) {
0101       return bool_t{true};
0102     } else {
0103       return result_type<bool_t>{true, true};
0104     }
0105   }
0106   /// @}
0107 
0108   /// @brief Measure of the shape: Inf
0109   ///
0110   /// @param bounds the boundary values for this shape
0111   ///
0112   /// @returns Inf.
0113   template <concepts::scalar scalar_t>
0114   DETRAY_HOST_DEVICE constexpr scalar_t measure(
0115       const bounds_type<scalar_t>& bounds) const {
0116     if constexpr (dim == 2) {
0117       return area(bounds);
0118     } else {
0119       return volume(bounds);
0120     }
0121   }
0122 
0123   /// @brief The area of a the shape
0124   ///
0125   /// @param bounds the boundary values for this shape
0126   ///
0127   /// @returns Inf.
0128   template <concepts::scalar scalar_t>
0129   DETRAY_HOST_DEVICE constexpr scalar_t area(
0130       const bounds_type<scalar_t>& /*unused*/) const {
0131     return std::numeric_limits<scalar_t>::max();
0132   }
0133 
0134   /// @brief The volume of a the shape
0135   ///
0136   /// @param bounds the boundary values for this shape
0137   ///
0138   /// @returns Inf.
0139   template <concepts::scalar scalar_t>
0140   DETRAY_HOST_DEVICE constexpr scalar_t volume(
0141       const bounds_type<scalar_t>& /*unused*/) const {
0142     return std::numeric_limits<scalar_t>::max();
0143   }
0144 
0145   /// @brief Merge two unbounded shapes
0146   ///
0147   /// @param bounds the boundary values for this shape
0148   /// @param o_bounds the boundary values for the other shape
0149   ///
0150   /// @returns merged bound values
0151   template <concepts::scalar scalar_t>
0152   DETRAY_HOST_DEVICE constexpr bounds_type<scalar_t> merge(
0153       const bounds_type<scalar_t>& /*bounds*/,
0154       const bounds_type<scalar_t>& /*o_bounds*/) const {
0155     return {};
0156   }
0157 
0158   /// @brief Lower and upper point for minimal axis aligned bounding box.
0159   ///
0160   /// Computes the min and max vertices in a local cartesian frame of the
0161   /// shape it wraps.
0162   ///
0163   /// @note The @c check_boundaries method will return 'inside' for points
0164   /// that are outside the local min bounds! This results in the bounding box
0165   /// to behave reasonably in a BVH, but still be always intersected
0166   /// successfully when queried directly.
0167   ///
0168   /// @param bounds the boundary values for this shape
0169   /// @param env dynamic envelope around the shape
0170   ///
0171   /// @returns and array of coordinates that contains the lower point (first
0172   /// three values) and the upper point (latter three values).
0173   template <concepts::algebra algebra_t>
0174   DETRAY_HOST_DEVICE inline darray<dscalar<algebra_t>, 6> local_min_bounds(
0175       const bounds_type<dscalar<algebra_t>>& bounds,
0176       const dscalar<algebra_t> env =
0177           std::numeric_limits<dscalar<algebra_t>>::epsilon()) const {
0178     return shape{}.template local_min_bounds<algebra_t>(bounds, env);
0179   }
0180 
0181   /// @returns the shapes centroid in local cartesian coordinates
0182   template <concepts::algebra algebra_t>
0183   DETRAY_HOST_DEVICE auto centroid(
0184       const bounds_type<dscalar<algebra_t>>& bounds) const {
0185     return shape{}.template centroid<algebra_t>(bounds);
0186   }
0187 
0188   /// Generate vertices in local cartesian frame
0189   ///
0190   /// @param bounds the boundary values for the underlying shape
0191   /// @param ls is the number of line segments
0192   ///
0193   /// @return a generated list of vertices
0194   template <concepts::algebra algebra_t>
0195   DETRAY_HOST dvector<dpoint3D<algebra_t>> vertices(
0196       const bounds_type<dscalar<algebra_t>>& bounds, dindex n_seg) const {
0197     return shape{}.template vertices<algebra_t>(bounds, n_seg);
0198   }
0199 
0200   /// @brief Check consistency of boundary values.
0201   ///
0202   /// @param bounds the boundary values for this shape
0203   /// @param os output stream for error messages
0204   ///
0205   /// @return true if the bounds are consistent.
0206   template <concepts::scalar scalar_t>
0207   DETRAY_HOST constexpr bool check_consistency(
0208       const bounds_type<scalar_t>& /*bounds*/,
0209       const std::ostream& /*os*/) const {
0210     return true;
0211   }
0212 };
0213 
0214 }  // namespace detray