From 462efdab37d2feeaf50f42e802b6b6422bbba6cf Mon Sep 17 00:00:00 2001 From: wmayer Date: Fri, 30 Oct 2020 13:55:31 +0100 Subject: [PATCH] Part: [skip ci] After removing a knot check if the B-spline is still valid --- src/Mod/Part/App/Geometry.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/Mod/Part/App/Geometry.cpp b/src/Mod/Part/App/Geometry.cpp index 6346f066a5de..8bbf143b7246 100644 --- a/src/Mod/Part/App/Geometry.cpp +++ b/src/Mod/Part/App/Geometry.cpp @@ -1400,11 +1400,25 @@ void GeomBSplineCurve::increaseMultiplicity(int index, int multiplicity) bool GeomBSplineCurve::removeKnot(int index, int multiplicity, double tolerance) { try { - Handle(Geom_BSplineCurve) curve = Handle(Geom_BSplineCurve)::DownCast(this->handle()); - return curve->RemoveKnot(index, multiplicity, tolerance) == Standard_True; + Handle(Geom_BSplineCurve) curve =Handle(Geom_BSplineCurve)::DownCast(myCurve->Copy()); + if (curve->RemoveKnot(index, multiplicity, tolerance)) { + + // It can happen that OCCT computes a negative weight but still claims the removal was successful + TColStd_Array1OfReal weights(1, curve->NbPoles()); + curve->Weights(weights); + for (Standard_Integer i = weights.Lower(); i <= weights.Upper(); i++) { + double v = weights(i); + if (v <= gp::Resolution()) + return false; + } + + myCurve = curve; + return true; + } + + return false; } catch (Standard_Failure& e) { - THROWM(Base::CADKernelError,e.GetMessageString()) } }