From 4d2e4fea4463cd5abb058fa96531aa8230410ed4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Sch=C3=B6berl?= Date: Fri, 16 Oct 2020 09:44:11 +0200 Subject: [PATCH] unique-ptr for TangentialSolid --- libsrc/csg/edgeflw.cpp | 20 ++++++++++++-------- libsrc/csg/singularref.cpp | 6 +++--- libsrc/csg/solid.cpp | 4 +++- libsrc/csg/solid.hpp | 2 +- libsrc/csg/specpoin.cpp | 36 ++++++++++++++++++------------------ 5 files changed, 37 insertions(+), 31 deletions(-) diff --git a/libsrc/csg/edgeflw.cpp b/libsrc/csg/edgeflw.cpp index 106a951c..850c28ad 100644 --- a/libsrc/csg/edgeflw.cpp +++ b/libsrc/csg/edgeflw.cpp @@ -970,7 +970,7 @@ namespace netgen for (int i = 0; i < geometry.GetNTopLevelObjects(); i++) { - Solid * locsol; + // Solid * locsol; if (geometry.GetTopLevelObject(i)->GetLayer() != layer) continue; @@ -978,7 +978,8 @@ namespace netgen const Solid * sol = geometry.GetTopLevelObject(i)->GetSolid(); const Surface * surf = geometry.GetTopLevelObject(i)->GetSurface(); - sol -> TangentialSolid (hp, locsol, locsurfind, size*ideps); + // sol -> TangentialSolid (hp, locsol, locsurfind, size*ideps); + auto locsol = sol -> TangentialSolid (hp, locsurfind, size*ideps); //*testout << "hp = " << hp << endl; //(*testout) << "locsol: " << endl; @@ -995,7 +996,8 @@ namespace netgen ReducePrimitiveIterator rpi(boxp); UnReducePrimitiveIterator urpi; - ((Solid*)locsol) -> IterateSolid (rpi); + // ((Solid*)locsol) -> IterateSolid (rpi); + locsol -> IterateSolid (rpi); locsol -> CalcSurfaceInverse (); @@ -1020,7 +1022,8 @@ namespace netgen } } - ((Solid*)locsol) -> IterateSolid (urpi); + // ((Solid*)locsol) -> IterateSolid (urpi); + locsol -> IterateSolid (urpi); if (debug) @@ -1259,7 +1262,7 @@ namespace netgen m *= -1; } } - delete locsol; + // delete locsol; } @@ -1780,7 +1783,7 @@ namespace netgen int nsurf = geometry.GetNSurf(); int layer = 0; - Solid * tansol; + // Solid * tansol; NgArray tansurfind; double size = geometry.MaxSize(); @@ -1838,7 +1841,8 @@ namespace netgen continue; const Solid * sol = geometry.GetTopLevelObject(j)->GetSolid(); - sol -> TangentialSolid (p1, tansol, tansurfind, ideps*size); + // sol -> TangentialSolid (p1, tansol, tansurfind, ideps*size); + auto tansol = sol -> TangentialSolid (p1, tansurfind, ideps*size); layer = geometry.GetTopLevelObject(j)->GetLayer(); @@ -1868,7 +1872,7 @@ namespace netgen // seg.invs1 = surfaces[i] -> Inverse(); // seg.invs2 = ! (surfaces[i] -> Inverse()); } - delete tansol; + // delete tansol; } } diff --git a/libsrc/csg/singularref.cpp b/libsrc/csg/singularref.cpp index a230c518..8dc1b7e5 100644 --- a/libsrc/csg/singularref.cpp +++ b/libsrc/csg/singularref.cpp @@ -168,7 +168,7 @@ void SingularPoint :: FindPoints (class Mesh & mesh) for (int k = 1; k <= 3; k++) { const Solid * solk(NULL); - Solid *tansol; + // Solid *tansol; switch (k) { case 1: solk = sol1; break; @@ -176,7 +176,7 @@ void SingularPoint :: FindPoints (class Mesh & mesh) case 3: solk = sol3; break; } - solk -> TangentialSolid (p, tansol, surfk, 1e-3); + auto tansol = solk -> TangentialSolid (p, surfk, 1e-3); (*testout) << "Tansol = " << *tansol << endl; if (!tansol) continue; @@ -195,7 +195,7 @@ void SingularPoint :: FindPoints (class Mesh & mesh) if (!surf.Contains (surfk[i])) surf.Append (surfk[i]); - delete tansol; + // delete tansol; } if (surf.Size() < 3) continue; diff --git a/libsrc/csg/solid.cpp b/libsrc/csg/solid.cpp index 6ba50cf7..b14dc1fe 100644 --- a/libsrc/csg/solid.cpp +++ b/libsrc/csg/solid.cpp @@ -638,13 +638,15 @@ namespace netgen } - void Solid :: TangentialSolid (const Point<3> & p, Solid *& tansol, NgArray & surfids, double eps) const + unique_ptr Solid :: TangentialSolid (const Point<3> & p, NgArray & surfids, double eps) const { int in, strin; + Solid * tansol = nullptr; RecTangentialSolid (p, tansol, surfids, in, strin, eps); surfids.SetSize (0); if (tansol) tansol -> GetTangentialSurfaceIndices (p, surfids, eps); + return unique_ptr (tansol); } diff --git a/libsrc/csg/solid.hpp b/libsrc/csg/solid.hpp index 51720275..3e884048 100644 --- a/libsrc/csg/solid.hpp +++ b/libsrc/csg/solid.hpp @@ -114,7 +114,7 @@ namespace netgen /// compute localization in point p - void TangentialSolid (const Point<3> & p, Solid *& tansol, NgArray & surfids, double eps) const; + unique_ptr TangentialSolid (const Point<3> & p, NgArray & surfids, double eps) const; /// compute localization in point p tangential to vector t void TangentialSolid2 (const Point<3> & p, const Vec<3> & t, diff --git a/libsrc/csg/specpoin.cpp b/libsrc/csg/specpoin.cpp index 16024e95..d4535e33 100644 --- a/libsrc/csg/specpoin.cpp +++ b/libsrc/csg/specpoin.cpp @@ -289,8 +289,8 @@ namespace netgen for (int j = 0; j < pts.Size(); j++) if (Dist (pts[j], box.Center()) < box.Diam()/2) { - Solid * tansol; - sol -> TangentialSolid (pts[j], tansol, surfids, 1e-9*size); + // Solid * tansol; + auto tansol = sol -> TangentialSolid (pts[j], surfids, 1e-9*size); if(!tansol) continue; @@ -314,7 +314,7 @@ namespace netgen if (AddPoint (pts[j], layer)) (*testout) << "cross point found, 1: " << pts[j] << endl; } - delete tansol; + // delete tansol; } } @@ -333,8 +333,8 @@ namespace netgen for (int j = 0; j < pts.Size(); j++) if (Dist (pts[j], box.Center()) < box.Diam()/2) { - Solid * tansol; - sol -> TangentialSolid (pts[j], tansol, surfids, 1e-9*size); + // Solid * tansol; + auto tansol = sol -> TangentialSolid (pts[j], surfids, 1e-9*size); if(!tansol) continue; @@ -358,7 +358,7 @@ namespace netgen if (AddPoint (pts[j], layer)) (*testout) << "cross point found, 2: " << pts[j] << endl; } - delete tansol; + // delete tansol; } } @@ -372,15 +372,15 @@ namespace netgen for (int j = 0; j < pts.Size(); j++) if (Dist (pts[j], box.Center()) < box.Diam()/2) { - Solid * tansol; - sol -> TangentialSolid (pts[j], tansol, surfids, 1e-9*size); + // Solid * tansol; + auto tansol = sol -> TangentialSolid (pts[j], surfids, 1e-9*size); if (tansol) // sol -> IsIn (pts[j], 1e-6*size) && !sol->IsStrictIn (pts[j], 1e-6*size) ) { if (AddPoint (pts[j], layer)) (*testout) << "extremal point found, 1: " << pts[j] << endl; } - delete tansol; + // delete tansol; } } } @@ -409,8 +409,8 @@ namespace netgen for (int j = 0; j < pts.Size(); j++) if (Dist (pts[j], box.Center()) < box.Diam()/2) { - Solid * tansol; - sol -> TangentialSolid (pts[j], tansol, surfids, 1e-9*size); + // Solid * tansol; + auto tansol = sol -> TangentialSolid (pts[j], surfids, 1e-9*size); if(!tansol) continue; @@ -434,7 +434,7 @@ namespace netgen if (AddPoint (pts[j], layer)) (*testout) << "cross point found, 1: " << pts[j] << endl; } - delete tansol; + // delete tansol; } } @@ -449,15 +449,15 @@ namespace netgen for (int j = 0; j < pts.Size(); j++) if (Dist (pts[j], box.Center()) < box.Diam()/2) { - Solid * tansol; - sol -> TangentialSolid (pts[j], tansol, surfids, 1e-9*size); + // Solid * tansol; + auto tansol = sol -> TangentialSolid (pts[j], surfids, 1e-9*size); if (tansol) // sol -> IsIn (pts[j], 1e-6*size) && !sol->IsStrictIn (pts[j], 1e-6*size) ) { if (AddPoint (pts[j], layer)) (*testout) << "extremal point found, spheres: " << pts[j] << endl; } - delete tansol; + // delete tansol; } } @@ -1829,8 +1829,8 @@ namespace netgen continue; - Solid * locsol; - sol -> TangentialSolid (p, locsol, surfind, ideps*geomsize); + // Solid * locsol; + auto locsol = sol -> TangentialSolid (p, surfind, ideps*geomsize); rep_surfind.SetSize (surfind.Size()); @@ -2158,7 +2158,7 @@ namespace netgen } - delete locsol; + // delete locsol; } }