From f483d3e94d5374e3ac8c845fec76d4e8770cc4d6 Mon Sep 17 00:00:00 2001 From: azv Date: Thu, 6 Apr 2017 14:58:02 +0300 Subject: [PATCH] Update Arc unit test --- .../Test/TestCreateArcByCenterStartEnd.py | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/SketchPlugin/Test/TestCreateArcByCenterStartEnd.py b/src/SketchPlugin/Test/TestCreateArcByCenterStartEnd.py index 4f01b367f..4f05ecf69 100644 --- a/src/SketchPlugin/Test/TestCreateArcByCenterStartEnd.py +++ b/src/SketchPlugin/Test/TestCreateArcByCenterStartEnd.py @@ -46,6 +46,31 @@ def verifyLastArc(theSketch, theCenter, theStart, theEnd): def verifyPointCoordinates(thePoint, theX, theY): assert thePoint.x() == theX and thePoint.y() == theY, "Wrong '{0}' point ({1}, {2}), expected ({3}, {4})".format(thePoint.id(), thePoint.x(), thePoint.y(), theX, theY) +def verifyPointOnLine(thePoint, theLine): + aDistance = distancePointLine(thePoint, theLine) + assert aDistance < TOLERANCE, "Point is not on Line, distance: {0}".format(aDistance) + +def verifyPointOnCircle(thePoint, theCircular): + if theCircular.getKind() == "SketchArc": + aCenterPoint = geomDataAPI_Point2D(theCircular.attribute("center_point")) + aStartPoint = geomDataAPI_Point2D(theCircular.attribute("start_point")) + aRadius = model.distancePointPoint(aCenterPoint, aStartPoint) + elif theCircular.getKind() == "SketchCircle": + aCenterPoint = geomDataAPI_Point2D(theCircular.attribute("circle_center")) + aRadius = theCircular.real("circle_radius").value() + else: + return + assert math.fabs(model.distancePointPoint(aCenterPoint, thePoint) - aRadius) < TOLERANCE + + +def distancePointLine(thePoint, theLine): + aLineStart = geomDataAPI_Point2D(theLine.attribute("StartPoint")).pnt().xy() + aLineEnd = geomDataAPI_Point2D(theLine.attribute("EndPoint")).pnt().xy() + aLineDir = aLineEnd.decreased(aLineStart) + aLineLen = aLineEnd.distance(aLineStart) + aPntDir = thePoint.pnt().xy().decreased(aLineStart) + return math.fabs(aPntDir.cross(aLineDir) / aLineLen) + aSession = ModelAPI_Session.get() aDocument = aSession.moduleDocument() -- 2.39.2