From: Artem Zhidkov Date: Thu, 19 Mar 2020 13:52:10 +0000 (+0300) Subject: Avoid crash while placing the presentation of constraint attached to the closed curve... X-Git-Tag: V9_5_0a2~32 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=4b83439d48e6e58e229aacc0b5a4a1616fcdded7;p=modules%2Fshaper.git Avoid crash while placing the presentation of constraint attached to the closed curve (issues #17347, #18882). --- diff --git a/src/SketcherPrs/SketcherPrs_PositionMgr.cpp b/src/SketcherPrs/SketcherPrs_PositionMgr.cpp index 84fe25890..eb87e2884 100644 --- a/src/SketcherPrs/SketcherPrs_PositionMgr.cpp +++ b/src/SketcherPrs/SketcherPrs_PositionMgr.cpp @@ -188,10 +188,12 @@ gp_Vec getVector(ObjectPtr theShape, GeomDirPtr theDir, gp_Pnt theP) gp_Vec aVec; std::shared_ptr aShape = SketcherPrs_Tools::getShape(theShape); if (aShape->isEdge()) { + std::shared_ptr anEdge = aShape->edge(); std::shared_ptr aCurve = std::shared_ptr(new GeomAPI_Curve(aShape)); - if (aCurve->isCircle() || aCurve->isEllipse()) { + if (anEdge->isClosed()) { + double aPeriod = aCurve->endParam() - aCurve->startParam(); Handle(Geom_Curve) aCurv = aCurve->impl(); GeomAPI_ProjectPointOnCurve anExtr(theP, aCurv); double aParam = anExtr.LowerDistanceParameter(); @@ -205,9 +207,9 @@ gp_Vec getVector(ObjectPtr theShape, GeomDirPtr theDir, gp_Pnt theP) // if parameter is near the LastParam, make the vector go inside (reverse) double aDelta = aLastParam - aParam; while (aDelta < -Precision::Confusion()) - aDelta += 2. * M_PI; - while (aDelta > 2. * M_PI - Precision::Confusion()) - aDelta -= 2. * M_PI; + aDelta += aPeriod; + while (aDelta > aPeriod + Precision::Confusion()) + aDelta -= aPeriod; if (fabs(aDelta) < Precision::Confusion()) aVec.Reverse(); }