Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:58:16

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 // Implementation of inline methods of G4ExtrudedSolid
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 }