Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-17 08:35:33

0001 #ifndef VECGEOM_SURFACE_CONVHELPER_H_
0002 #define VECGEOM_SURFACE_CONVHELPER_H_
0003 
0004 #include <VecGeom/surfaces/conv/Builder.h>
0005 #include <VecGeom/surfaces/Model.h>
0006 
0007 namespace vgbrep {
0008 namespace conv {
0009 
0010 // using Vector3D = vecgeom::Vector3D<vecgeom::Precision>;
0011 
0012 /// @brief Helper function to check whether three vectors are right-sided
0013 /// @param v1 vector 1
0014 /// @param v2 vector 2
0015 /// @param v3 vector 3
0016 /// @return whether the three vectors are right-sided
0017 template <typename Real_t>
0018 bool IsRightSided(vecgeom::Vector3D<Real_t> const &v1, vecgeom::Vector3D<Real_t> const &v2,
0019                   vecgeom::Vector3D<Real_t> const &v3)
0020 {
0021   Real_t dot = (v1[0] - v2[0]) * (v3[1] - v2[1]) - (v1[1] - v2[1]) * (v3[0] - v2[0]);
0022   return (dot < -vecgeom::kToleranceDist<Real_t>) ? false : true;
0023 }
0024 
0025 /// @brief Helper function to check whether a section is convex or concave
0026 /// @tparam Container structure holding the data for z and r
0027 /// @param zArray Points in z for all sections
0028 /// @param rArray Points in r for all sections
0029 /// @param convex whether to check for convexity or concavity
0030 /// @param nsec number of section to be checked
0031 /// @return if the section is convex/concave depending on the convex input parameter
0032 template <typename Real_t, typename Container>
0033 bool IsConvexConcave(const int iSect, Container &zArray, Container &rArray, const bool convex, const int nsec)
0034 {
0035   if (nsec == 2) return true;
0036   // bottom section, need to check only in the upper direction
0037   if (iSect == 0) {
0038     int i = iSect;
0039     int j = (i + 1);
0040     int k = (i + 2);
0041     // if the top of the this section and the bottom of next section are the same, we need to check the next point
0042     if (rArray[j] == rArray[k]) k++;
0043     if (convex ^
0044         IsRightSided<Real_t>({rArray[i], zArray[i], 0.}, {rArray[j], zArray[j], 0.}, {rArray[k], zArray[k], 0.})) {
0045       return false;
0046     }
0047   }
0048 
0049   // mid section, need to check both in lower and in the upper direction
0050   if (iSect > 0 && iSect < nsec - 2) {
0051     int i = iSect - 1;
0052     int j = (i + 1);
0053     int k = (i + 2);
0054     // if the top of the previous section and the bottom of this section are the same, we need to check the previous
0055     // point
0056     if (rArray[i] == rArray[j] && i > 0) i--;
0057     if (convex ^
0058         IsRightSided<Real_t>({rArray[i], zArray[i], 0.}, {rArray[j], zArray[j], 0.}, {rArray[k], zArray[k], 0.})) {
0059       return false;
0060     }
0061     i = iSect;
0062     j = (i + 1);
0063     k = (i + 2);
0064     // if the top of the this section and the bottom of next section are the same, we need to check the next point
0065     if (rArray[j] == rArray[k]) k++;
0066     if (convex ^
0067         IsRightSided<Real_t>({rArray[i], zArray[i], 0.}, {rArray[j], zArray[j], 0.}, {rArray[k], zArray[k], 0.})) {
0068       return false;
0069     }
0070   }
0071 
0072   // top section, need to check only in the lower direction
0073   if (iSect == nsec - 2) {
0074     int i = iSect - 1;
0075     int j = (i + 1);
0076     int k = (i + 2);
0077     // if the top of the previous section and the bottom of this section are the same, we need to check the previous
0078     // point
0079     if (rArray[i] == rArray[j] && i > 0) i--;
0080     if (convex ^
0081         IsRightSided<Real_t>({rArray[i], zArray[i], 0.}, {rArray[j], zArray[j], 0.}, {rArray[k], zArray[k], 0.})) {
0082       return false;
0083     }
0084   }
0085 
0086   return true;
0087 };
0088 
0089 } // namespace conv
0090 } // namespace vgbrep
0091 #endif