File indexing completed on 2025-01-18 09:58:16
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 inline
0030 G4int G4ExtrudedSolid::GetNofVertices() const
0031 {
0032 return (G4int)fNv;
0033 }
0034
0035 inline G4TwoVector G4ExtrudedSolid::GetVertex(G4int index) const
0036 {
0037 if ( index<0 || index >= (G4int)fNv )
0038 {
0039 G4Exception ("G4ExtrudedSolid::GetVertex()", "GeomSolids0003",
0040 FatalException, "Index outside range.");
0041 return {};
0042 }
0043 return fPolygon[index];
0044 }
0045
0046 inline
0047 std::vector<G4TwoVector> G4ExtrudedSolid::GetPolygon() const
0048 {
0049 return fPolygon;
0050 }
0051
0052 inline
0053 G4int G4ExtrudedSolid::GetNofZSections() const
0054 {
0055 return (G4int)fNz;
0056 }
0057
0058 inline
0059 G4ExtrudedSolid::ZSection G4ExtrudedSolid::GetZSection(G4int index) const
0060 {
0061 if ( index<0 || index >= (G4int)fNz )
0062 {
0063 G4Exception ("G4ExtrudedSolid::GetZSection()", "GeomSolids0003",
0064 FatalException, "Index outside range.");
0065 return ZSection(0.0, G4TwoVector(), 0.0);
0066 }
0067 return fZSections[index];
0068 }
0069
0070 inline
0071 std::vector<G4ExtrudedSolid::ZSection> G4ExtrudedSolid::GetZSections() const
0072 {
0073 return fZSections;
0074 }
0075
0076 inline
0077 G4bool G4ExtrudedSolid::PointInPolygon(const G4ThreeVector& p) const
0078 {
0079 G4bool in = false;
0080 G4int icur = (fPolygon[fNv-1].y() > p.y()), iprev = 0;
0081 for (std::size_t i = 0; i < fNv; ++i)
0082 {
0083 iprev = icur;
0084 if ((icur = (fPolygon[i].y() > p.y())) != iprev)
0085 {
0086 in ^= (p.y()*fLines[i].k + fLines[i].m < p.x());
0087 }
0088 }
0089 return in;
0090 }
0091
0092 inline
0093 G4double G4ExtrudedSolid::DistanceToPolygonSqr(const G4ThreeVector& p) const
0094 {
0095 G4double dd = DBL_MAX;
0096 for (std::size_t i=0, k=fNv-1; i<fNv; k=i++)
0097 {
0098 G4double ix = p.x() - fPolygon[i].x();
0099 G4double iy = p.y() - fPolygon[i].y();
0100 G4double u = fPlanes[i].a*iy - fPlanes[i].b*ix;
0101 if (u < 0)
0102 {
0103 G4double tmp = ix*ix + iy*iy;
0104 if (tmp < dd) dd = tmp;
0105 }
0106 else if (u > fLengths[i])
0107 {
0108 G4double kx = p.x() - fPolygon[k].x();
0109 G4double ky = p.y() - fPolygon[k].y();
0110 G4double tmp = kx*kx + ky*ky;
0111 if (tmp < dd) dd = tmp;
0112 }
0113 else
0114 {
0115 G4double tmp = fPlanes[i].a*p.x() + fPlanes[i].b*p.y() + fPlanes[i].d;
0116 tmp *= tmp;
0117 if (tmp < dd) dd = tmp;
0118 }
0119 }
0120 return dd;
0121 }