12#include "detray/definitions/algebra.hpp"
13#include "detray/definitions/containers.hpp"
14#include "detray/definitions/detail/qualifiers.hpp"
15#include "detray/definitions/indexing.hpp"
16#include "detray/definitions/math.hpp"
17#include "detray/geometry/coordinates/cartesian2D.hpp"
18#include "detray/geometry/detail/shape_utils.hpp"
33 static constexpr std::string_view
name =
"rectangle2D";
43 template <concepts::scalar scalar_t>
47 template <concepts::algebra algebra_t>
51 template <
typename bool_t>
55 static constexpr std::size_t
dim{2u};
66 template <concepts::scalar scalar_t, concepts::po
int po
int_t>
69 return math::min(math::fabs(math::fabs(loc_p[0]) - bounds[e_half_x]),
70 math::fabs(math::fabs(loc_p[1]) - bounds[e_half_y]));
82 template <concepts::algebra algebra_t>
106 template <concepts::scalar scalar_t, concepts::po
int po
int_t>
109 const scalar_t tol = std::numeric_limits<scalar_t>::epsilon(),
110 const scalar_t edge_tol = 0.f)
const {
111 const scalar_t loc_0{math::fabs(loc_p[0])};
112 const scalar_t loc_1{math::fabs(loc_p[1])};
114 auto inside_mask{(loc_0 <= (bounds[e_half_x] + tol) &&
115 loc_1 <= (bounds[e_half_y] + tol))};
117 decltype(inside_mask) inside_edge{
false};
118 if (detail::any_of(edge_tol > 0.f)) {
119 const scalar_t full_tol{tol + edge_tol};
121 inside_edge = (loc_0 <= (bounds[e_half_x] + full_tol) &&
122 loc_1 <= (bounds[e_half_y] + full_tol));
125 return result_type<
decltype(inside_mask)>{inside_mask, inside_edge};
134 template <concepts::scalar scalar_t>
135 DETRAY_HOST_DEVICE
constexpr scalar_t
measure(
145 template <concepts::scalar scalar_t>
146 DETRAY_HOST_DEVICE
constexpr scalar_t
area(
148 return 4.f * bounds[e_half_x] * bounds[e_half_y];
157 template <concepts::scalar scalar_t>
163 new_bounds[e_half_x] = math::max(bounds[e_half_x], o_bounds[e_half_x]);
164 new_bounds[e_half_y] = math::max(bounds[e_half_y], o_bounds[e_half_y]);
178 template <concepts::algebra algebra_t>
186 const scalar_t x_bound{bounds[e_half_x] + env};
187 const scalar_t y_bound{bounds[e_half_y] + env};
188 return {-x_bound, -y_bound, -env, x_bound, y_bound, env};
192 template <concepts::algebra algebra_t>
195 return {0.f, 0.f, 0.f};
205 template <concepts::algebra algebra_t>
211 point3_t lh_lc{-bounds[e_half_x], -bounds[e_half_y],
214 point3_t rh_lc{bounds[e_half_x], -bounds[e_half_y],
217 point3_t rh_uc{bounds[e_half_x], bounds[e_half_y],
220 point3_t lh_uc{-bounds[e_half_x], bounds[e_half_y],
224 return {lh_lc, rh_lc, rh_uc, lh_uc};
233 template <concepts::scalar scalar_t>
236 if (
constexpr auto tol{10.f * std::numeric_limits<scalar_t>::epsilon()};
237 bounds[e_half_x] < tol || bounds[e_half_y] < tol) {
238 os <<
"DETRAY ERROR (HOST): Half lengths must be in the range (0, "
Geometrical shape of a rectangle2D.
Definition rectangle2D.hpp:30
cartesian2D< algebra_t > local_frame_type
Local coordinate frame for boundary checks.
Definition rectangle2D.hpp:48
darray< scalar_t, boundaries::e_size > bounds_type
Container definition for the shape boundary values.
Definition rectangle2D.hpp:44
constexpr bool check_consistency(const bounds_type< scalar_t > &bounds, std::ostream &os) const
Check consistency of boundary values.
Definition rectangle2D.hpp:234
dvector< dpoint3D< algebra_t > > vertices(const bounds_type< dscalar< algebra_t > > &bounds, dindex) const
Generate vertices in local cartesian frame.
Definition rectangle2D.hpp:206
static constexpr std::string_view name
The name for this shape.
Definition rectangle2D.hpp:33
constexpr scalar_t area(const bounds_type< scalar_t > &bounds) const
The area of a the shape.
Definition rectangle2D.hpp:146
static constexpr std::size_t dim
Dimension of the local coordinate system.
Definition rectangle2D.hpp:55
dpoint3D< algebra_t > centroid(const bounds_type< dscalar< algebra_t > > &) const
Definition rectangle2D.hpp:193
boundaries
Indices describing the entries in the shape boundary array.
Definition rectangle2D.hpp:36
scalar_t min_dist_to_boundary(const bounds_type< scalar_t > &bounds, const point_t &loc_p) const
Find the minimum distance to any boundary.
Definition rectangle2D.hpp:67
constexpr auto check_boundaries(const bounds_type< scalar_t > &bounds, const point_t &loc_p, const scalar_t tol=std::numeric_limits< scalar_t >::epsilon(), const scalar_t edge_tol=0.f) const
Definition rectangle2D.hpp:107
detail::boundary_check_result< bool_t > result_type
Result type of a boundary check.
Definition rectangle2D.hpp:52
constexpr scalar_t measure(const bounds_type< scalar_t > &bounds) const
Measure of the shape: Area.
Definition rectangle2D.hpp:135
darray< dscalar< algebra_t >, 6 > local_min_bounds(const bounds_type< dscalar< algebra_t > > &bounds, const dscalar< algebra_t > env=std::numeric_limits< dscalar< algebra_t > >::epsilon()) const
Lower and upper point for minimal axis aligned bounding box.
Definition rectangle2D.hpp:179
constexpr result_type< dbool< algebra_t > > check_boundaries(const bounds_type< dscalar< algebra_t > > &bounds, const dtransform3D< algebra_t > &trf, const dpoint3D< algebra_t > &glob_p, const dscalar< algebra_t > tol=std::numeric_limits< dscalar< algebra_t > >::epsilon(), const dscalar< algebra_t > edge_tol=0.f) const
Check boundary values for a local point.
Definition rectangle2D.hpp:83
constexpr bounds_type< scalar_t > merge(const bounds_type< scalar_t > &bounds, const bounds_type< scalar_t > &o_bounds) const
Merge two rectangle shapes.
Definition rectangle2D.hpp:158
Detray include(s).
Definition array_operators.hpp:18
get_scalar_t< A, T > dscalar
Scalar type for algebra A and value type T.
Definition algebra.hpp:64
vecmem::vector< value_t > dvector
Vector container backed by vecmem.
Definition containers.hpp:34
unsigned int dindex
Default index type.
Definition indexing.hpp:18
std::array< value_t, kDIM > darray
Fixed-size array container.
Definition containers.hpp:30
get_transform3D_t< A, T > dtransform3D
Three-dimensional transform type for algebra A and value type T.
Definition algebra.hpp:84
get_point3D_t< A, T > dpoint3D
Three-dimensional point type for algebra A and value type T.
Definition algebra.hpp:72
get_point2D_t< A, T > dpoint2D
Two-dimensional point type for algebra A and value type T.
Definition algebra.hpp:68
Projection into a 2D cartesian coordinate frame.
Definition cartesian2D.hpp:19
static loc_point global_to_local(const transform3_type &trf, const point3_type &p, const vector3_type &)
This method transforms a point from a global cartesian 3D frame to a local 2D cartesian point.
Definition cartesian2D.hpp:54