| Summary: | G4VFacet returns false positives for facet identity, due to counting error | ||
|---|---|---|---|
| Product: | Geant4 | Reporter: | marcus.h.mendenhall |
| Component: | geometry/solids | Assignee: | Gabriele Cosmo <Gabriele.Cosmo> |
| Status: | RESOLVED FIXED | ||
| Severity: | normal | CC: | flei, robert.a.weller |
| Priority: | P5 | ||
| Version: | 9.1 | ||
| Hardware: | All | ||
| OS: | All | ||
Thanks for reporting the problem. The suggested fix is now implemented in tag "geom-specific-V09-01-15" and will be included in the next release and patch. |
I was having an issue with G4Tessellated slids randomly deleting facets, resulting in broken geometries. I have traced it down to an error in G4VFacet::operator ==. Thie issue is that, as written, the loop for a 3-sided facet runs from 0-3 (inclusive) due to a misplaced autoincrement. Here is the original and the fix. ORIGINAL -- broken /////////////////////////////////////////////////////////////////////////////// // G4bool G4VFacet::operator== (const G4VFacet &right) const { G4double tolerance = kCarTolerance*kCarTolerance/4.0; if (nVertices != right.GetNumberOfVertices()) { return false; } else if ((circumcentre-right.GetCircumcentre()).mag2() > tolerance) { return false; } else if (std::fabs((right.GetSurfaceNormal()).dot(surfaceNormal)) < 0.9999999999) { return false; } G4bool coincident = true; size_t i = 0; do { coincident = false; size_t j = 0; do { coincident = (GetVertex(i)-right.GetVertex(j)).mag2() < tolerance; } while (!coincident && j++ < nVertices); } while (coincident && i++ < nVertices); return coincident; } CORRECTED: /////////////////////////////////////////////////////////////////////////////// // G4bool G4VFacet::operator== (const G4VFacet &right) const { G4double tolerance = kCarTolerance*kCarTolerance/4.0; if (nVertices != right.GetNumberOfVertices()) { return false; } else if ((circumcentre-right.GetCircumcentre()).mag2() > tolerance) { return false; } else if (std::fabs((right.GetSurfaceNormal()).dot(surfaceNormal)) < 0.9999999999) { return false; } G4bool coincident = true; size_t i = 0; do { coincident = false; size_t j = 0; do { coincident = (GetVertex(i)-right.GetVertex(j)).mag2() < tolerance; } while (!coincident && ++j < nVertices); } while (coincident && ++i < nVertices); return coincident; }