@@ -328,38 +328,36 @@ bool TGeoTessellated::FacetCheck(int ifacet) const
328328
329329void TGeoTessellated::CloseShape (bool check, bool fixFlipped, bool verbose)
330330{
331- if (fIsClosed && fBVH ) {
331+ const bool initialized = fIsClosed && fBVH ;
332+ if (initialized && !check) {
332333 return ;
333334 }
334- // Compute bounding box
335- fDefined = true ;
336- fNvert = fVertices .size ();
337- fNfacets = fFacets .size ();
338- ComputeBBox ();
339335
340- BuildBVH ();
341- if (fOutwardNormals .size () == 0 ) {
342- CalculateNormals ();
343- } else {
344- // short check if the normal container is of correct size
345- if (fOutwardNormals .size () != fFacets .size ()) {
346- std::cerr << " Inconsistency in normal container" ;
347- }
348- }
349- fIsClosed = true ;
336+ if (!initialized) {
337+ // Compute bounding box
338+ fDefined = true ;
339+ fNvert = fVertices .size ();
340+ fNfacets = fFacets .size ();
341+ ComputeBBox ();
350342
351- // Cleanup the vertex map
352- std::multimap<long , int >().swap (fVerticesMap );
343+ BuildBVH ();
344+ fIsClosed = true ;
345+
346+ // Cleanup the vertex map
347+ std::multimap<long , int >().swap (fVerticesMap );
348+ }
353349
354350 if (fVertices .size () > 0 ) {
355- if (!check)
356- return ;
351+ if (check) {
352+ // Check facets
353+ for (auto i = 0 ; i < fNfacets ; ++i)
354+ FacetCheck (i);
357355
358- // Check facets
359- for (auto i = 0 ; i < fNfacets ; ++i)
360- FacetCheck (i);
356+ fClosedBody = CheckClosure (fixFlipped, verbose);
357+ }
361358
362- fClosedBody = CheckClosure (fixFlipped, verbose);
359+ if (fOutwardNormals .size () != fFacets .size ())
360+ CalculateNormals ();
363361 }
364362}
365363
@@ -422,6 +420,8 @@ bool TGeoTessellated::CheckClosure(bool fixFlipped, bool verbose)
422420 }
423421 if (nfixed && verbose)
424422 Info (" Check" , " Automatically flipped %d facets to match first defined facet" , nfixed);
423+ if (nfixed && !fOutwardNormals .empty ())
424+ CalculateNormals ();
425425 }
426426 delete[] nn;
427427 delete[] flipped;
@@ -1277,8 +1277,7 @@ inline Double_t TGeoTessellated::SafetyKernel(const Double_t *point, bool in, in
12771277 const auto object_id = mybvh->prim_ids [p_id];
12781278
12791279 const auto &facet = fFacets [object_id];
1280- auto thissafetySQ =
1281- pointFacetDistSq (Vec3f<float >(point[0 ], point[1 ], point[2 ]), facet, fVertices );
1280+ auto thissafetySQ = pointFacetDistSq (Vec3f<float >(point[0 ], point[1 ], point[2 ]), facet, fVertices );
12821281
12831282 if (thissafetySQ < smallest_safety_sq) {
12841283 smallest_safety_sq = thissafetySQ;
0 commit comments