Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/geometry/solids/specific/src/G4ClippablePolygon.cc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /geometry/solids/specific/src/G4ClippablePolygon.cc (Version 11.3.0) and /geometry/solids/specific/src/G4ClippablePolygon.cc (Version 10.6)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
 26 // G4ClippablePolygon implementation               26 // G4ClippablePolygon implementation
 27 //                                                 27 //
 28 // Includes code from G4VSolid (P.Kent, V.Gric     28 // Includes code from G4VSolid (P.Kent, V.Grichine, J.Allison)
 29 // -------------------------------------------     29 // --------------------------------------------------------------------
 30                                                    30 
 31 #include "G4ClippablePolygon.hh"                   31 #include "G4ClippablePolygon.hh"
 32                                                    32 
 33 #include "G4VoxelLimits.hh"                        33 #include "G4VoxelLimits.hh"
 34 #include "G4GeometryTolerance.hh"                  34 #include "G4GeometryTolerance.hh"
 35                                                    35 
 36 // Constructor                                     36 // Constructor
 37 //                                                 37 //
 38 G4ClippablePolygon::G4ClippablePolygon()           38 G4ClippablePolygon::G4ClippablePolygon()
 39   : normal(0.,0.,0.)                               39   : normal(0.,0.,0.)
 40 {                                                  40 {
 41   kCarTolerance = G4GeometryTolerance::GetInst     41   kCarTolerance = G4GeometryTolerance::GetInstance()->GetSurfaceTolerance();
 42 }                                                  42 }
 43                                                    43 
 44 // Destructor                                      44 // Destructor
 45 //                                                 45 //
 46 G4ClippablePolygon::~G4ClippablePolygon() = de <<  46 G4ClippablePolygon::~G4ClippablePolygon()
                                                   >>  47 {
                                                   >>  48 }
 47                                                    49 
 48 // AddVertexInOrder                                50 // AddVertexInOrder
 49 //                                                 51 //
 50 void G4ClippablePolygon::AddVertexInOrder( con     52 void G4ClippablePolygon::AddVertexInOrder( const G4ThreeVector vertex )
 51 {                                                  53 {
 52   vertices.push_back( vertex );                    54   vertices.push_back( vertex );
 53 }                                                  55 }
 54                                                    56 
 55 // ClearAllVertices                                57 // ClearAllVertices
 56 //                                                 58 //
 57 void G4ClippablePolygon::ClearAllVertices()        59 void G4ClippablePolygon::ClearAllVertices()
 58 {                                                  60 {
 59   vertices.clear();                                61   vertices.clear();
 60 }                                                  62 }
 61                                                    63 
 62 // Clip                                            64 // Clip
 63 //                                                 65 //
 64 G4bool G4ClippablePolygon::Clip( const G4Voxel     66 G4bool G4ClippablePolygon::Clip( const G4VoxelLimits& voxelLimit )
 65 {                                                  67 {
 66   if (voxelLimit.IsLimited())                      68   if (voxelLimit.IsLimited())
 67   {                                                69   {
 68     ClipAlongOneAxis( voxelLimit, kXAxis );        70     ClipAlongOneAxis( voxelLimit, kXAxis );
 69     ClipAlongOneAxis( voxelLimit, kYAxis );        71     ClipAlongOneAxis( voxelLimit, kYAxis );
 70     ClipAlongOneAxis( voxelLimit, kZAxis );        72     ClipAlongOneAxis( voxelLimit, kZAxis );
 71   }                                                73   }
 72                                                    74   
 73   return (!vertices.empty());                  <<  75   return (vertices.size() > 0);
 74 }                                                  76 }
 75                                                    77 
 76 // PartialClip                                     78 // PartialClip
 77 //                                                 79 //
 78 // Clip, while ignoring the indicated axis         80 // Clip, while ignoring the indicated axis
 79 //                                                 81 //
 80 G4bool G4ClippablePolygon::PartialClip( const      82 G4bool G4ClippablePolygon::PartialClip( const G4VoxelLimits& voxelLimit,
 81                                         const      83                                         const EAxis IgnoreMe )
 82 {                                                  84 {
 83   if (voxelLimit.IsLimited())                      85   if (voxelLimit.IsLimited())
 84   {                                                86   {
 85     if (IgnoreMe != kXAxis) ClipAlongOneAxis(      87     if (IgnoreMe != kXAxis) ClipAlongOneAxis( voxelLimit, kXAxis );
 86     if (IgnoreMe != kYAxis) ClipAlongOneAxis(      88     if (IgnoreMe != kYAxis) ClipAlongOneAxis( voxelLimit, kYAxis );
 87     if (IgnoreMe != kZAxis) ClipAlongOneAxis(      89     if (IgnoreMe != kZAxis) ClipAlongOneAxis( voxelLimit, kZAxis );
 88   }                                                90   }
 89                                                    91   
 90   return (!vertices.empty());                  <<  92   return (vertices.size() > 0);
 91 }                                                  93 }
 92                                                    94 
 93 // GetExtent                                       95 // GetExtent
 94 //                                                 96 //
 95 G4bool G4ClippablePolygon::GetExtent( const EA     97 G4bool G4ClippablePolygon::GetExtent( const EAxis axis, 
 96                                             G4     98                                             G4double& min,
 97                                             G4     99                                             G4double& max ) const
 98 {                                                 100 {
 99   //                                              101   //
100   // Okay, how many entries do we have?           102   // Okay, how many entries do we have?
101   //                                              103   //
102   std::size_t noLeft = vertices.size();        << 104   G4int noLeft = vertices.size();
103                                                   105   
104   //                                              106   //
105   // Return false if nothing is left              107   // Return false if nothing is left
106   //                                              108   //
107   if (noLeft == 0) return false;                  109   if (noLeft == 0) return false;
108                                                   110   
109   //                                              111   //
110   // Initialize min and max to our first verte    112   // Initialize min and max to our first vertex
111   //                                              113   //
112   min = max = vertices[0].operator()( axis );     114   min = max = vertices[0].operator()( axis );
113                                                   115   
114   //                                              116   //
115   // Compare to the rest                          117   // Compare to the rest
116   //                                              118   //
117   for( std::size_t i=1; i<noLeft; ++i )        << 119   for( G4int i=1; i<noLeft; ++i )
118   {                                               120   {
119     G4double component = vertices[i].operator(    121     G4double component = vertices[i].operator()( axis );
120     if (component < min )                         122     if (component < min )
121       min = component;                            123       min = component;
122     else if (component > max )                    124     else if (component > max )
123       max = component;                            125       max = component;
124   }                                               126   }
125                                                   127   
126   return true;                                    128   return true;
127 }                                                 129 }
128                                                   130 
129 // GetMinPoint                                    131 // GetMinPoint
130 //                                                132 //
131 // Returns pointer to minimum point along the     133 // Returns pointer to minimum point along the specified axis.
132 // Take care! Do not use pointer after destroy    134 // Take care! Do not use pointer after destroying parent polygon.
133 //                                                135 //
134 const G4ThreeVector* G4ClippablePolygon::GetMi    136 const G4ThreeVector* G4ClippablePolygon::GetMinPoint( const EAxis axis ) const
135 {                                                 137 {
136   std::size_t noLeft = vertices.size();        << 138   G4int noLeft = vertices.size();
137   if (noLeft==0)                                  139   if (noLeft==0)
138   {                                            << 
139     G4Exception("G4ClippablePolygon::GetMinPoi    140     G4Exception("G4ClippablePolygon::GetMinPoint()",
140                 "GeomSolids0002", FatalExcepti    141                 "GeomSolids0002", FatalException, "Empty polygon.");
141   }                                            << 142   
142                                                << 
143   const G4ThreeVector *answer = &(vertices[0])    143   const G4ThreeVector *answer = &(vertices[0]);
144   G4double min = answer->operator()(axis);        144   G4double min = answer->operator()(axis);
145                                                   145 
146   for( std::size_t i=1; i<noLeft; ++i )        << 146   for( G4int i=1; i<noLeft; ++i )
147   {                                               147   {
148     G4double component = vertices[i].operator(    148     G4double component = vertices[i].operator()( axis );
149     if (component < min)                          149     if (component < min)
150     {                                             150     {
151       answer = &(vertices[i]);                    151       answer = &(vertices[i]);
152       min = component;                            152       min = component;
153     }                                             153     }
154   }                                               154   }
155                                                   155   
156   return answer;                                  156   return answer;
157 }                                                 157 }
158                                                   158 
159 // GetMaxPoint                                    159 // GetMaxPoint
160 //                                                160 //
161 // Returns pointer to maximum point along the     161 // Returns pointer to maximum point along the specified axis.
162 // Take care! Do not use pointer after destroy    162 // Take care! Do not use pointer after destroying parent polygon.
163 //                                                163 //
164 const G4ThreeVector* G4ClippablePolygon::GetMa    164 const G4ThreeVector* G4ClippablePolygon::GetMaxPoint( const EAxis axis ) const
165 {                                                 165 {
166   std::size_t noLeft = vertices.size();        << 166   G4int noLeft = vertices.size();
167   if (noLeft==0)                                  167   if (noLeft==0)
168   {                                            << 
169     G4Exception("G4ClippablePolygon::GetMaxPoi    168     G4Exception("G4ClippablePolygon::GetMaxPoint()",
170                 "GeomSolids0002", FatalExcepti    169                 "GeomSolids0002", FatalException, "Empty polygon.");
171   }                                            << 170   
172                                                << 
173   const G4ThreeVector *answer = &(vertices[0])    171   const G4ThreeVector *answer = &(vertices[0]);
174   G4double max = answer->operator()(axis);        172   G4double max = answer->operator()(axis);
175                                                   173 
176   for( std::size_t i=1; i<noLeft; ++i )        << 174   for( G4int i=1; i<noLeft; ++i )
177   {                                               175   {
178     G4double component = vertices[i].operator(    176     G4double component = vertices[i].operator()( axis );
179     if (component > max)                          177     if (component > max)
180     {                                             178     {
181       answer = &(vertices[i]);                    179       answer = &(vertices[i]);
182       max = component;                            180       max = component;
183     }                                             181     }
184   }                                               182   }
185                                                   183   
186   return answer;                                  184   return answer;
187 }                                                 185 }
188                                                   186 
189 // InFrontOf                                      187 // InFrontOf
190 //                                                188 //
191 // Decide if this polygon is in "front" of ano    189 // Decide if this polygon is in "front" of another when
192 // viewed along the specified axis. For our pu    190 // viewed along the specified axis. For our purposes here,
193 // it is sufficient to use the minimum extent     191 // it is sufficient to use the minimum extent of the
194 // polygon along the axis to determine this.      192 // polygon along the axis to determine this.
195 //                                                193 //
196 // In case the minima of the two polygons are     194 // In case the minima of the two polygons are equal,
197 // we use a more sophisticated test.              195 // we use a more sophisticated test.
198 //                                                196 //
199 // Note that it is possible for the two follow    197 // Note that it is possible for the two following
200 // statements to both return true or both retu    198 // statements to both return true or both return false:
201 //         polygon1.InFrontOf(polygon2)           199 //         polygon1.InFrontOf(polygon2)
202 //         polygon2.BehindOf(polygon1)            200 //         polygon2.BehindOf(polygon1)
203 //                                                201 //
204 G4bool G4ClippablePolygon::InFrontOf( const G4    202 G4bool G4ClippablePolygon::InFrontOf( const G4ClippablePolygon& other,
205                                             EA    203                                             EAxis axis ) const
206 {                                                 204 {
207   //                                              205   //
208   // If things are empty, do something semi-se    206   // If things are empty, do something semi-sensible
209   //                                              207   //
210   std::size_t noLeft = vertices.size();        << 208   G4int noLeft = vertices.size();
211   if (noLeft==0) return false;                    209   if (noLeft==0) return false;
212                                                   210   
213   if (other.Empty()) return true;                 211   if (other.Empty()) return true;
214                                                   212 
215   //                                              213   //
216   // Get minimum of other polygon                 214   // Get minimum of other polygon
217   //                                              215   //
218   const G4ThreeVector *minPointOther = other.G    216   const G4ThreeVector *minPointOther = other.GetMinPoint( axis );
219   const G4double minOther = minPointOther->ope    217   const G4double minOther = minPointOther->operator()(axis);
220                                                   218   
221   //                                              219   //
222   // Get minimum of this polygon                  220   // Get minimum of this polygon
223   //                                              221   //
224   const G4ThreeVector *minPoint = GetMinPoint(    222   const G4ThreeVector *minPoint = GetMinPoint( axis );
225   const G4double min = minPoint->operator()(ax    223   const G4double min = minPoint->operator()(axis);
226                                                   224   
227   //                                              225   //
228   // Easy decision                                226   // Easy decision
229   //                                              227   //
230   if (min < minOther-kCarTolerance) return tru    228   if (min < minOther-kCarTolerance) return true;    // Clear winner
231                                                   229   
232   if (minOther < min-kCarTolerance) return fal    230   if (minOther < min-kCarTolerance) return false;    // Clear loser
233                                                   231   
234   //                                              232   //
235   // We have a tie (this will not be all that     233   // We have a tie (this will not be all that rare since our
236   // polygons are connected)                      234   // polygons are connected)
237   //                                              235   //
238   // Check to see if there is a vertex in the     236   // Check to see if there is a vertex in the other polygon
239   // that is behind this one (or vice versa)      237   // that is behind this one (or vice versa)
240   //                                              238   //
241   G4bool answer;                                  239   G4bool answer;
242   G4ThreeVector normalOther = other.GetNormal(    240   G4ThreeVector normalOther = other.GetNormal();
243                                                   241   
244   if (std::fabs(normalOther(axis)) > std::fabs    242   if (std::fabs(normalOther(axis)) > std::fabs(normal(axis)))
245   {                                               243   {
246     G4double minP, maxP;                          244     G4double minP, maxP;
247     GetPlanerExtent( *minPointOther, normalOth    245     GetPlanerExtent( *minPointOther, normalOther, minP, maxP );
248                                                   246     
249     answer = (normalOther(axis) > 0) ? (minP <    247     answer = (normalOther(axis) > 0) ? (minP < -kCarTolerance)
250                                      : (maxP >    248                                      : (maxP > +kCarTolerance);
251   }                                               249   }
252   else                                            250   else
253   {                                               251   {
254     G4double minP, maxP;                          252     G4double minP, maxP;
255     other.GetPlanerExtent( *minPoint, normal,     253     other.GetPlanerExtent( *minPoint, normal, minP, maxP );
256                                                   254     
257     answer = (normal(axis) > 0) ? (maxP > +kCa    255     answer = (normal(axis) > 0) ? (maxP > +kCarTolerance)
258                                 : (minP < -kCa    256                                 : (minP < -kCarTolerance);
259   }                                               257   }
260   return answer;                                  258   return answer;
261 }                                                 259 }
262                                                   260 
263 // BehindOf                                       261 // BehindOf
264 //                                                262 //
265 // Decide if this polygon is behind another.      263 // Decide if this polygon is behind another.
266 // See notes in method "InFrontOf"                264 // See notes in method "InFrontOf"
267 //                                                265 //
268 G4bool G4ClippablePolygon::BehindOf( const G4C    266 G4bool G4ClippablePolygon::BehindOf( const G4ClippablePolygon& other,
269                                            EAx    267                                            EAxis axis ) const
270 {                                                 268 {
271   //                                              269   //
272   // If things are empty, do something semi-se    270   // If things are empty, do something semi-sensible
273   //                                              271   //
274   std::size_t noLeft = vertices.size();        << 272   G4int noLeft = vertices.size();
275   if (noLeft==0) return false;                    273   if (noLeft==0) return false;
276                                                   274   
277   if (other.Empty()) return true;                 275   if (other.Empty()) return true;
278                                                   276 
279   //                                              277   //
280   // Get minimum of other polygon                 278   // Get minimum of other polygon
281   //                                              279   //
282   const G4ThreeVector *maxPointOther = other.G    280   const G4ThreeVector *maxPointOther = other.GetMaxPoint( axis );
283   const G4double maxOther = maxPointOther->ope    281   const G4double maxOther = maxPointOther->operator()(axis);
284                                                   282   
285   //                                              283   //
286   // Get minimum of this polygon                  284   // Get minimum of this polygon
287   //                                              285   //
288   const G4ThreeVector *maxPoint = GetMaxPoint(    286   const G4ThreeVector *maxPoint = GetMaxPoint( axis );
289   const G4double max = maxPoint->operator()(ax    287   const G4double max = maxPoint->operator()(axis);
290                                                   288   
291   //                                              289   //
292   // Easy decision                                290   // Easy decision
293   //                                              291   //
294   if (max > maxOther+kCarTolerance) return tru    292   if (max > maxOther+kCarTolerance) return true;    // Clear winner
295                                                   293   
296   if (maxOther > max+kCarTolerance) return fal    294   if (maxOther > max+kCarTolerance) return false;    // Clear loser
297                                                   295   
298   //                                              296   //
299   // We have a tie (this will not be all that     297   // We have a tie (this will not be all that rare since our
300   // polygons are connected)                      298   // polygons are connected)
301   //                                              299   //
302   // Check to see if there is a vertex in the     300   // Check to see if there is a vertex in the other polygon
303   // that is in front of this one (or vice ver    301   // that is in front of this one (or vice versa)
304   //                                              302   //
305   G4bool answer;                                  303   G4bool answer;
306   G4ThreeVector normalOther = other.GetNormal(    304   G4ThreeVector normalOther = other.GetNormal();
307                                                   305   
308   if (std::fabs(normalOther(axis)) > std::fabs    306   if (std::fabs(normalOther(axis)) > std::fabs(normal(axis)))
309   {                                               307   {
310     G4double minP, maxP;                          308     G4double minP, maxP;
311     GetPlanerExtent( *maxPointOther, normalOth    309     GetPlanerExtent( *maxPointOther, normalOther, minP, maxP );
312                                                   310     
313     answer = (normalOther(axis) > 0) ? (maxP >    311     answer = (normalOther(axis) > 0) ? (maxP > +kCarTolerance)
314                                      : (minP <    312                                      : (minP < -kCarTolerance);
315   }                                               313   }
316   else                                            314   else
317   {                                               315   {
318     G4double minP, maxP;                          316     G4double minP, maxP;
319     other.GetPlanerExtent( *maxPoint, normal,     317     other.GetPlanerExtent( *maxPoint, normal, minP, maxP );
320                                                   318     
321     answer = (normal(axis) > 0) ? (minP < -kCa    319     answer = (normal(axis) > 0) ? (minP < -kCarTolerance)
322                                 : (maxP > +kCa    320                                 : (maxP > +kCarTolerance);
323   }                                               321   }
324   return answer;                                  322   return answer;
325 }                                                 323 }
326                                                   324 
327 // GetPlanerExtent                                325 // GetPlanerExtent
328 //                                                326 //
329 // Get min/max distance in or out of a plane      327 // Get min/max distance in or out of a plane
330 //                                                328 //
331 G4bool G4ClippablePolygon::GetPlanerExtent( co    329 G4bool G4ClippablePolygon::GetPlanerExtent( const G4ThreeVector& pointOnPlane, 
332                                             co    330                                             const G4ThreeVector& planeNormal,
333                                                   331                                                   G4double& min,
334                                                   332                                                   G4double& max ) const
335 {                                                 333 {
336   //                                              334   //
337   // Okay, how many entries do we have?           335   // Okay, how many entries do we have?
338   //                                              336   //
339   std::size_t noLeft = vertices.size();        << 337   G4int noLeft = vertices.size();
340                                                   338   
341   //                                              339   //
342   // Return false if nothing is left              340   // Return false if nothing is left
343   //                                              341   //
344   if (noLeft == 0) return false;                  342   if (noLeft == 0) return false;
345                                                   343   
346   //                                              344   //
347   // Initialize min and max to our first verte    345   // Initialize min and max to our first vertex
348   //                                              346   //
349   min = max = planeNormal.dot(vertices[0]-poin    347   min = max = planeNormal.dot(vertices[0]-pointOnPlane);
350                                                   348   
351   //                                              349   //
352   // Compare to the rest                          350   // Compare to the rest
353   //                                              351   //
354   for( std::size_t i=1; i<noLeft; ++i )        << 352   for( G4int i=1; i<noLeft; ++i )
355   {                                               353   {
356     G4double component = planeNormal.dot(verti    354     G4double component = planeNormal.dot(vertices[i] - pointOnPlane);
357     if (component < min )                         355     if (component < min )
358       min = component;                            356       min = component;
359     else if (component > max )                    357     else if (component > max )
360       max = component;                            358       max = component;
361   }                                               359   }
362                                                   360   
363   return true;                                    361   return true;
364 }                                                 362 }
365                                                   363 
366 // ClipAlongOneAxis                               364 // ClipAlongOneAxis
367 //                                                365 //
368 // Clip along just one axis, as specified in v    366 // Clip along just one axis, as specified in voxelLimit
369 //                                                367 //
370 void G4ClippablePolygon::ClipAlongOneAxis( con    368 void G4ClippablePolygon::ClipAlongOneAxis( const G4VoxelLimits& voxelLimit,
371                                            con    369                                            const EAxis axis )
372 {                                                 370 {    
373   if (!voxelLimit.IsLimited(axis)) return;        371   if (!voxelLimit.IsLimited(axis)) return;
374                                                   372   
375   G4ThreeVectorList tempPolygon;                  373   G4ThreeVectorList tempPolygon;
376                                                   374 
377   //                                              375   //
378   // Build a "simple" voxelLimit that includes    376   // Build a "simple" voxelLimit that includes only the min extent
379   // and apply this to our vertices, producing    377   // and apply this to our vertices, producing result in tempPolygon
380   //                                              378   //
381   G4VoxelLimits simpleLimit1;                     379   G4VoxelLimits simpleLimit1;
382   simpleLimit1.AddLimit( axis, voxelLimit.GetM    380   simpleLimit1.AddLimit( axis, voxelLimit.GetMinExtent(axis), kInfinity );
383   ClipToSimpleLimits( vertices, tempPolygon, s    381   ClipToSimpleLimits( vertices, tempPolygon, simpleLimit1 );
384                                                   382 
385   //                                              383   //
386   // If nothing is left from the above clip, w    384   // If nothing is left from the above clip, we might as well return now
387   // (but with an empty vertices)                 385   // (but with an empty vertices)
388   //                                              386   //
389   if (tempPolygon.empty())                     << 387   if (tempPolygon.size() == 0)
390   {                                               388   {
391     vertices.clear();                             389     vertices.clear();
392     return;                                       390     return;
393   }                                               391   }
394                                                   392 
395   //                                              393   //
396   // Now do the same, but using a "simple" lim    394   // Now do the same, but using a "simple" limit that includes only the max
397   // extent. Apply this to out tempPolygon, pr    395   // extent. Apply this to out tempPolygon, producing result in vertices.
398   //                                              396   //
399   G4VoxelLimits simpleLimit2;                     397   G4VoxelLimits simpleLimit2;
400   simpleLimit2.AddLimit( axis, -kInfinity, vox    398   simpleLimit2.AddLimit( axis, -kInfinity, voxelLimit.GetMaxExtent(axis) );
401   ClipToSimpleLimits( tempPolygon, vertices, s    399   ClipToSimpleLimits( tempPolygon, vertices, simpleLimit2 );
402                                                   400 
403   //                                              401   //
404   // If nothing is left, return now               402   // If nothing is left, return now
405   //                                              403   //
406   if (vertices.empty()) return;                << 404   if (vertices.size() == 0) return;
407 }                                                 405 }
408                                                   406 
409 // ClipToSimpleLimits                             407 // ClipToSimpleLimits
410 //                                                408 //
411 // pVoxelLimits must be only limited along one    409 // pVoxelLimits must be only limited along one axis, and either the maximum
412 // along the axis must be +kInfinity, or the m    410 // along the axis must be +kInfinity, or the minimum -kInfinity
413 //                                                411 //
414 void G4ClippablePolygon::ClipToSimpleLimits( G    412 void G4ClippablePolygon::ClipToSimpleLimits( G4ThreeVectorList& pPolygon,
415                                              G    413                                              G4ThreeVectorList& outputPolygon,
416                                        const G    414                                        const G4VoxelLimits& pVoxelLimit   )
417 {                                                 415 {
418   std::size_t noVertices = pPolygon.size();    << 416   G4int noVertices = pPolygon.size();
419   G4ThreeVector vEnd,vStart;                      417   G4ThreeVector vEnd,vStart;
420                                                   418 
421   outputPolygon.clear();                          419   outputPolygon.clear();
422                                                   420     
423   for (std::size_t i=0; i<noVertices; ++i)     << 421   for (G4int i=0; i<noVertices; ++i)
424   {                                               422   {
425     vStart=pPolygon[i];                           423     vStart=pPolygon[i];
426     if (i==noVertices-1)                          424     if (i==noVertices-1)
427     {                                             425     {
428       vEnd=pPolygon[0];                           426       vEnd=pPolygon[0];
429     }                                             427     }
430     else                                          428     else
431     {                                             429     {
432       vEnd=pPolygon[i+1];                         430       vEnd=pPolygon[i+1];
433     }                                             431     }
434                                                   432 
435     if (pVoxelLimit.Inside(vStart))               433     if (pVoxelLimit.Inside(vStart))
436     {                                             434     {
437       if (pVoxelLimit.Inside(vEnd))               435       if (pVoxelLimit.Inside(vEnd))
438       {                                           436       {
439         // vStart and vEnd inside -> output en    437         // vStart and vEnd inside -> output end point
440         //                                        438         //
441         outputPolygon.push_back(vEnd);            439         outputPolygon.push_back(vEnd);
442       }                                           440       }
443       else                                        441       else
444       {                                           442       {
445         // vStart inside, vEnd outside -> outp    443         // vStart inside, vEnd outside -> output crossing point
446         //                                        444         //
447         pVoxelLimit.ClipToLimits(vStart,vEnd);    445         pVoxelLimit.ClipToLimits(vStart,vEnd);
448         outputPolygon.push_back(vEnd);            446         outputPolygon.push_back(vEnd);
449       }                                           447       }
450     }                                             448     }
451     else                                          449     else
452     {                                             450     {
453       if (pVoxelLimit.Inside(vEnd))               451       if (pVoxelLimit.Inside(vEnd))
454       {                                           452       {
455         // vStart outside, vEnd inside -> outp    453         // vStart outside, vEnd inside -> output inside section
456         //                                        454         //
457         pVoxelLimit.ClipToLimits(vStart,vEnd);    455         pVoxelLimit.ClipToLimits(vStart,vEnd);
458         outputPolygon.push_back(vStart);          456         outputPolygon.push_back(vStart);
459         outputPolygon.push_back(vEnd);            457         outputPolygon.push_back(vEnd);
460       }                                           458       }
461       else    // Both point outside -> no outp    459       else    // Both point outside -> no output
462       {                                           460       {
463       }                                           461       }
464     }                                             462     }
465   }                                               463   }
466 }                                                 464 }
467                                                   465