Geant4-11
G4ExtrudedSolid.icc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26// Implementation of inline methods of G4ExtrudedSolid
27// --------------------------------------------------------------------
28
29inline
30G4int G4ExtrudedSolid::GetNofVertices() const
31{
32 return fNv;
33}
34
35inline G4TwoVector G4ExtrudedSolid::GetVertex(G4int index) const
36{
37 if ( index<0 || index >= fNv )
38 {
39 G4Exception ("G4ExtrudedSolid::GetVertex()", "GeomSolids0003",
40 FatalException, "Index outside range.");
41 return G4TwoVector();
42 }
43 return fPolygon[index];
44}
45
46inline
47std::vector<G4TwoVector> G4ExtrudedSolid::GetPolygon() const
48{
49 return fPolygon;
50}
51
52inline
53G4int G4ExtrudedSolid::GetNofZSections() const
54{
55 return fNz;
56}
57
58inline
59G4ExtrudedSolid::ZSection G4ExtrudedSolid::GetZSection(G4int index) const
60{
61 if ( index<0 || index >= fNz )
62 {
63 G4Exception ("G4ExtrudedSolid::GetZSection()", "GeomSolids0003",
64 FatalException, "Index outside range.");
65 return ZSection(0.0, G4TwoVector(), 0.0);
66 }
67 return fZSections[index];
68}
69
70inline
71std::vector<G4ExtrudedSolid::ZSection> G4ExtrudedSolid::GetZSections() const
72{
73 return fZSections;
74}
75
76inline
77G4bool G4ExtrudedSolid::PointInPolygon(const G4ThreeVector& p) const
78{
79 G4bool in = 0;
80 G4int icur = (fPolygon[fNv-1].y() > p.y()), iprev = 0;
81 for (G4int i = 0; i < fNv; ++i)
82 {
83 iprev = icur;
84 if ((icur = (fPolygon[i].y() > p.y())) != iprev)
85 {
86 in ^= (p.y()*fLines[i].k + fLines[i].m < p.x());
87 }
88 }
89 return in;
90}
91
92inline
93G4double G4ExtrudedSolid::DistanceToPolygonSqr(const G4ThreeVector& p) const
94{
95 G4double dd = DBL_MAX;
96 for (G4int i=0, k=fNv-1; i<fNv; k=i++)
97 {
98 G4double ix = p.x() - fPolygon[i].x();
99 G4double iy = p.y() - fPolygon[i].y();
100 G4double u = fPlanes[i].a*iy - fPlanes[i].b*ix;
101 if (u < 0)
102 {
103 G4double tmp = ix*ix + iy*iy;
104 if (tmp < dd) dd = tmp;
105 }
106 else if (u > fLengths[i])
107 {
108 G4double kx = p.x() - fPolygon[k].x();
109 G4double ky = p.y() - fPolygon[k].y();
110 G4double tmp = kx*kx + ky*ky;
111 if (tmp < dd) dd = tmp;
112 }
113 else
114 {
115 G4double tmp = fPlanes[i].a*p.x() + fPlanes[i].b*p.y() + fPlanes[i].d;
116 tmp *= tmp;
117 if (tmp < dd) dd = tmp;
118 }
119 }
120 return dd;
121}