Problem 314

Summary: Incorrect surface normal from G4IntersectionSolid
Product: Geant4 Reporter: gas
Component: geometry/solidsAssignee: Gabriele Cosmo <Gabriele.Cosmo>
Status: RESOLVED FIXED    
Severity: normal CC: Vladimir.Grichine
Priority: P2    
Version: 3.2   
Hardware: PC   
OS: Linux   
URL: http://citnp.caltech.edu/kamland/montecarlo/KLG4sim/G4IntersectionSolid.cc.patch

Description gas 2001-10-18 16:23:56 CEST
When a point is on the surface of solidB and inside solidA,
G4IntersectionSolid incorrectly returns the normal from solidA.

The reason is an incorrect declaration of the variables
"insideA" and "insideB" in G4IntersectionSolid::SurfaceNormal()
(line 167): they are declared as "G4bool", but they need to be
"EInside".  Changing "G4bool" to "EInside" fixes the problem.

The problem may not be reproducible on all platforms: I am using g++
"egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)".  The reason
the problem occurs is that the assignment
       insideA= fPtrSolidA->Inside(p)
casts the "enum" returned by Inside into a "bool".  In doing so,
code produced by the g++ compiler converts any non-zero value of
the enum into the standard "true" value of 1.  Subsequently, the
test
  if( insideA == kSurface )
returns true even if the original value of "fPtrSolidA->Inside(p)"
was "kInside".  This leads to the problem described.
Comment 1 Gabriele Cosmo 2001-10-19 09:05:59 CEST
Thanks for spotting this. The bug was actually already fixed in a recent
development tag "geom-solid-bool-V03-02-00". The fix will be included in
the next December release.