From 9e3bcbbe53a91512c98db4328d7ab304d7e27367 Mon Sep 17 00:00:00 2001 From: mbs Date: Tue, 9 Jul 2024 17:53:06 +0100 Subject: [PATCH] [bos #42502] fixed unstable constraint test --- src/SketchPlugin/Test/TestConstraintCollinear.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/SketchPlugin/Test/TestConstraintCollinear.py b/src/SketchPlugin/Test/TestConstraintCollinear.py index 10695983b..41ace70f2 100644 --- a/src/SketchPlugin/Test/TestConstraintCollinear.py +++ b/src/SketchPlugin/Test/TestConstraintCollinear.py @@ -45,7 +45,12 @@ class TestConstraintCollinear(unittest.TestCase): model.begin() self.myDocument = model.moduleDocument() self.mySketch = model.addSketch(self.myDocument, model.defaultPlane("XOY")) - self.myTolerance = 1.e-6 + # We are going to compare the difference between the dot product and the product of the lengths of the vectors, + # which corresponds to the cosine of the angle between the vectors. So, we have an angular tolerance, which should + # not be squared but multiplied by the product of the lengths of the vectors: + # dot(a, b) = |a|*|b|*cos(angle) + # dot(a, b) - |a|*|b| = |a|*|b|*(cos(angle) - 1) < |a|*|b|*|cos(1.e-6) - 1| ~ |a|*|b|*5.e-13 + self.myTolerance = math.fabs(math.cos(1.e-6) - 1.0) self.myDOF = 0 def tearDown(self): @@ -56,7 +61,7 @@ class TestConstraintCollinear(unittest.TestCase): aLen1 = math.hypot(theX1, theY1) aLen2 = math.hypot(theX2, theY2) aDot = theX1 * theX2 + theY1 * theY2 - self.assertTrue(math.fabs(math.fabs(aDot) - aLen1 * aLen2) < self.myTolerance**2, "Vectors ({0}, {1}) and ({2}, {3}) do not collinear".format(theX1, theY1, theX2, theY2)) + self.assertTrue(math.fabs(math.fabs(aDot) - aLen1 * aLen2) < self.myTolerance*aLen1*aLen2, "Vectors ({0}, {1}) and ({2}, {3}) do not collinear".format(theX1, theY1, theX2, theY2)) def checkLineCollinearity(self, theLine1, theLine2): aStartPoint1 = theLine1.startPoint() -- 2.39.2