122 lines
3.8 KiB
Plaintext
122 lines
3.8 KiB
Plaintext
//
|
|
// ********************************************************************
|
|
// * License and Disclaimer *
|
|
// * *
|
|
// * The Geant4 software is copyright of the Copyright Holders of *
|
|
// * the Geant4 Collaboration. It is provided under the terms and *
|
|
// * conditions of the Geant4 Software License, included in the file *
|
|
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
|
// * include a list of copyright holders. *
|
|
// * *
|
|
// * Neither the authors of this software system, nor their employing *
|
|
// * institutes,nor the agencies providing financial support for this *
|
|
// * work make any representation or warranty, express or implied, *
|
|
// * regarding this software system or assume any liability for its *
|
|
// * use. Please see the license in the file LICENSE and URL above *
|
|
// * for the full disclaimer and the limitation of liability. *
|
|
// * *
|
|
// * This code implementation is the result of the scientific and *
|
|
// * technical work of the GEANT4 collaboration. *
|
|
// * By using, copying, modifying or distributing the software (or *
|
|
// * any work based on the software) you agree to acknowledge its *
|
|
// * use in resulting scientific publications, and indicate your *
|
|
// * acceptance of all terms of the Geant4 Software license. *
|
|
// ********************************************************************
|
|
//
|
|
// Implementation of inline methods of G4ExtrudedSolid
|
|
// --------------------------------------------------------------------
|
|
|
|
inline
|
|
G4int G4ExtrudedSolid::GetNofVertices() const
|
|
{
|
|
return fNv;
|
|
}
|
|
|
|
inline G4TwoVector G4ExtrudedSolid::GetVertex(G4int index) const
|
|
{
|
|
if ( index<0 || index >= fNv )
|
|
{
|
|
G4Exception ("G4ExtrudedSolid::GetVertex()", "GeomSolids0003",
|
|
FatalException, "Index outside range.");
|
|
return G4TwoVector();
|
|
}
|
|
return fPolygon[index];
|
|
}
|
|
|
|
inline
|
|
std::vector<G4TwoVector> G4ExtrudedSolid::GetPolygon() const
|
|
{
|
|
return fPolygon;
|
|
}
|
|
|
|
inline
|
|
G4int G4ExtrudedSolid::GetNofZSections() const
|
|
{
|
|
return fNz;
|
|
}
|
|
|
|
inline
|
|
G4ExtrudedSolid::ZSection G4ExtrudedSolid::GetZSection(G4int index) const
|
|
{
|
|
if ( index<0 || index >= fNz )
|
|
{
|
|
G4Exception ("G4ExtrudedSolid::GetZSection()", "GeomSolids0003",
|
|
FatalException, "Index outside range.");
|
|
return ZSection(0.0, G4TwoVector(), 0.0);
|
|
}
|
|
return fZSections[index];
|
|
}
|
|
|
|
inline
|
|
std::vector<G4ExtrudedSolid::ZSection> G4ExtrudedSolid::GetZSections() const
|
|
{
|
|
return fZSections;
|
|
}
|
|
|
|
inline
|
|
G4bool G4ExtrudedSolid::PointInPolygon(const G4ThreeVector& p) const
|
|
{
|
|
G4bool in = 0;
|
|
G4int icur = (fPolygon[fNv-1].y() > p.y()), iprev = 0;
|
|
for (G4int i = 0; i < fNv; ++i)
|
|
{
|
|
iprev = icur;
|
|
if ((icur = (fPolygon[i].y() > p.y())) != iprev)
|
|
{
|
|
in ^= (p.y()*fLines[i].k + fLines[i].m < p.x());
|
|
}
|
|
}
|
|
return in;
|
|
}
|
|
|
|
inline
|
|
G4double G4ExtrudedSolid::DistanceToPolygonSqr(const G4ThreeVector& p) const
|
|
{
|
|
G4double dd = DBL_MAX;
|
|
for (G4int i=0, k=fNv-1; i<fNv; k=i++)
|
|
{
|
|
G4double ix = p.x() - fPolygon[i].x();
|
|
G4double iy = p.y() - fPolygon[i].y();
|
|
G4double u = fPlanes[i].a*iy - fPlanes[i].b*ix;
|
|
if (u < 0)
|
|
{
|
|
G4double tmp = ix*ix + iy*iy;
|
|
if (tmp < dd) dd = tmp;
|
|
}
|
|
else if (u > fLengths[i])
|
|
{
|
|
G4double kx = p.x() - fPolygon[k].x();
|
|
G4double ky = p.y() - fPolygon[k].y();
|
|
G4double tmp = kx*kx + ky*ky;
|
|
if (tmp < dd) dd = tmp;
|
|
}
|
|
else
|
|
{
|
|
G4double tmp = fPlanes[i].a*p.x() + fPlanes[i].b*p.y() + fPlanes[i].d;
|
|
tmp *= tmp;
|
|
if (tmp < dd) dd = tmp;
|
|
}
|
|
}
|
|
return dd;
|
|
}
|