File indexing completed on 2026-04-17 08:35:36
0001 #ifndef VECGEOM_CYLINDRICAL_IMPL_H
0002 #define VECGEOM_CYLINDRICAL_IMPL_H
0003
0004 #include <VecGeom/surfaces/surf/SurfaceHelper.h>
0005 #include <VecGeom/surfaces/base/Equations.h>
0006
0007 namespace vgbrep {
0008
0009 template <typename Real_t>
0010 struct SurfaceHelper<SurfaceType::kCylindrical, Real_t> {
0011
0012 VECGEOM_FORCE_INLINE
0013 VECCORE_ATT_HOST_DEVICE
0014 SurfaceHelper() {}
0015
0016 VECGEOM_FORCE_INLINE
0017 VECCORE_ATT_HOST_DEVICE
0018
0019
0020
0021
0022 bool Inside(Vector3D<Real_t> const &point, bool flip, Real_t radius, Real_t tol = vecgeom::kToleranceStrict<Real_t>)
0023 {
0024 int flipsign = (radius < 0) ? -1 : 1;
0025 int bool_flipsign = !flip ? 1 : -1;
0026 Real_t rho = point.Perp();
0027 return flipsign * (rho - Abs(radius)) < bool_flipsign * tol;
0028 }
0029
0030 VECGEOM_FORCE_INLINE
0031 VECCORE_ATT_HOST_DEVICE
0032
0033
0034
0035
0036
0037
0038
0039 bool Intersect(Vector3D<Real_t> const &point, Vector3D<Real_t> const &dir, bool left_side, Real_t &distance,
0040 bool &two_solutions, Real_t &safety, Real_t radius)
0041 {
0042 QuadraticCoef<Real_t> coef;
0043 Real_t roots[2];
0044 int numroots = 0;
0045 bool flip_exiting = left_side ^ (radius < 0);
0046 CylinderEq<Real_t>(point, dir, Abs(radius), coef);
0047 QuadraticSolver(coef, roots, numroots);
0048 two_solutions = (numroots == 2 && roots[0] > -vecgeom::kToleranceStrict<Real_t> &&
0049 roots[1] > -vecgeom::kToleranceStrict<Real_t>);
0050 for (auto i = 0; i < numroots; ++i) {
0051 distance = roots[i];
0052 Vector3D<Real_t> onsurf = point + distance * dir;
0053 Vector3D<Real_t> normal(onsurf[0], onsurf[1], 0);
0054 bool hit = flip_exiting ^ (dir.Dot(normal) < 0);
0055
0056 if (hit) {
0057 if (distance < -vecgeom::kToleranceStrict<Real_t> && distance < -Abs(radius)) {
0058 Real_t rho = point.Perp();
0059 safety = Abs(radius) - rho;
0060 }
0061 return true;
0062 }
0063 }
0064 return false;
0065 }
0066
0067 VECGEOM_FORCE_INLINE
0068 VECCORE_ATT_HOST_DEVICE
0069
0070
0071
0072
0073
0074
0075
0076 bool Safety(Vector3D<Real_t> const &point, bool left_side, Real_t &distance, Vector3D<Real_t> &onsurf,
0077 Real_t radius) const
0078 {
0079 Real_t rho = point.Perp();
0080 bool flip_exiting = left_side ^ (radius < 0);
0081 distance = flip_exiting ? Abs(radius) - rho : rho - Abs(radius);
0082 onsurf = point;
0083 return distance > -vecgeom::kToleranceDist<Real_t>;
0084 }
0085 };
0086
0087 }
0088
0089 #endif