From da65953fac478d8e87f89b294c3344f1b4250258 Mon Sep 17 00:00:00 2001 From: azv Date: Mon, 7 Oct 2019 12:00:38 +0300 Subject: [PATCH 1/1] Avoid instability of test cases. --- src/GeomAPI/GeomAPI_Ellipse2d.cpp | 15 ++++++++++----- src/SketchPlugin/Test/TestTrimEllipse.py | 7 ++++--- .../SketchSolver_ConstraintTangent.cpp | 2 ++ 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/GeomAPI/GeomAPI_Ellipse2d.cpp b/src/GeomAPI/GeomAPI_Ellipse2d.cpp index 464d4b1c4..e10765c78 100644 --- a/src/GeomAPI/GeomAPI_Ellipse2d.cpp +++ b/src/GeomAPI/GeomAPI_Ellipse2d.cpp @@ -136,13 +136,20 @@ static double extrema(IntAna2d_AnaIntersection* theIntersectionAlgo, gp_Pnt2d anArrangePoint(theArrangePoint->x(), theArrangePoint->y()); gp_Pnt2d anInterPnt = theIntersectionAlgo->Point(1).Value(); aDistance = anArrangePoint.SquareDistance(anInterPnt); - // get solution nearest to theArrangePoint + int aNbMergedPoints = 1; + // get solution nearest to theArrangePoint, + // if there are several point near each other, calculate average coordinates for (int i = 2; i <= theIntersectionAlgo->NbPoints(); ++i) { const IntAna2d_IntPoint& aPnt = theIntersectionAlgo->Point(i); double aSqDist = aPnt.Value().SquareDistance(anArrangePoint); - if (aSqDist < aDistance) { + if (aSqDist - aDistance < -Precision::Confusion() * aDistance) { aDistance = aSqDist; anInterPnt = aPnt.Value(); + aNbMergedPoints = 1; + } else if (aSqDist - aDistance < Precision::Confusion() * aDistance) { + anInterPnt.ChangeCoord() = + (anInterPnt.XY() * aNbMergedPoints + aPnt.Value().XY()) / (aNbMergedPoints + 1); + ++aNbMergedPoints; } } @@ -181,9 +188,7 @@ double GeomAPI_Ellipse2d::distance(const std::shared_ptr& theCir { IntAna2d_AnaIntersection anInter(theCircle->impl(), IntAna2d_Conic(*MY_ELLIPSE)); Extrema_ExtElC2d anExtema(theCircle->impl(), *MY_ELLIPSE); - GeomPnt2dPtr aCircleStart; - theCircle->D0(0.0, aCircleStart); - return extrema(&anInter, &anExtema, aCircleStart, thePointOnCircle, thePointOnMe); + return extrema(&anInter, &anExtema, firstFocus(), thePointOnCircle, thePointOnMe); } double GeomAPI_Ellipse2d::distance(const std::shared_ptr& theEllipse, diff --git a/src/SketchPlugin/Test/TestTrimEllipse.py b/src/SketchPlugin/Test/TestTrimEllipse.py index f621c2c8c..ba3c59dcf 100644 --- a/src/SketchPlugin/Test/TestTrimEllipse.py +++ b/src/SketchPlugin/Test/TestTrimEllipse.py @@ -32,7 +32,7 @@ DOF = 11 NB_LINES = 3 NB_ELLIPSES = 1 NB_ELLIPTIC_ARCS = 0 -NB_COINCIDENCES = 5 +NB_COINCIDENCES = 6 NB_EQUALS = 0 TOLERANCE = 1.e-6 @@ -72,9 +72,10 @@ SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.startPoint() SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchEllipse_1.result()) SketchLine_2 = Sketch_1.addLine(-16.85909682653373, 35.30399198463829, 20.9032928583277, -19.27802168426675) SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint()) -SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchEllipse_1.result()) +SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_2.startPoint(), SketchEllipse_1.result()) +SketchConstraintCoincidence_5 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchEllipse_1.result()) SketchLine_3 = Sketch_1.addLine(34.69765676551338, 36.08465583643841, 35.0422024535432, -17.96612629290852) -SketchConstraintCoincidence_5 = Sketch_1.setCoincident(SketchLine_3.startPoint(), SketchEllipse_1.result()) +SketchConstraintCoincidence_6 = Sketch_1.setCoincident(SketchLine_3.startPoint(), SketchEllipse_1.result()) model.do() checkFeaturesQuantity(Sketch_1) diff --git a/src/SketchSolver/SketchSolver_ConstraintTangent.cpp b/src/SketchSolver/SketchSolver_ConstraintTangent.cpp index c54b01e91..18d95f8ec 100644 --- a/src/SketchSolver/SketchSolver_ConstraintTangent.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintTangent.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include @@ -368,6 +369,7 @@ static std::set pointsOnFeature(FeaturePtr theFeature) for (std::set::const_iterator anIt = aRefs.begin(); anIt != aRefs.end(); ++anIt) { FeaturePtr aRef = ModelAPI_Feature::feature((*anIt)->owner()); if (aRef && (aRef->getKind() == SketchPlugin_ConstraintCoincidence::ID() || + aRef->getKind() == SketchPlugin_ConstraintCoincidenceInternal::ID() || aRef->getKind() == SketchPlugin_ConstraintMiddle::ID())) { for (int i = 0; i < CONSTRAINT_ATTR_SIZE; ++i) { AttributeRefAttrPtr aRefAttr = aRef->refattr(SketchPlugin_Constraint::ATTRIBUTE(i)); -- 2.30.2