From 4b83439d48e6e58e229aacc0b5a4a1616fcdded7 Mon Sep 17 00:00:00 2001 From: Artem Zhidkov Date: Thu, 19 Mar 2020 16:52:10 +0300 Subject: [PATCH] Avoid crash while placing the presentation of constraint attached to the closed curve (issues #17347, #18882). --- src/SketcherPrs/SketcherPrs_PositionMgr.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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(); } -- 2.39.2