Salome HOME
updated copyright message
[modules/shaper.git] / src / SketchPlugin / Test / TestCreateArcByThreePoints.py
index 0844028d99bce4045ce2a3fac6d98586f6bf7a64..0eaff9beb8a1636143358571c8cacecdf7c8baf5 100644 (file)
@@ -1,22 +1,21 @@
-## Copyright (C) 2014-2017  CEA/DEN, EDF R&D
-##
-## This library is free software; you can redistribute it and/or
-## modify it under the terms of the GNU Lesser General Public
-## License as published by the Free Software Foundation; either
-## version 2.1 of the License, or (at your option) any later version.
-##
-## This library is distributed in the hope that it will be useful,
-## but WITHOUT ANY WARRANTY; without even the implied warranty of
-## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-## Lesser General Public License for more details.
-##
-## You should have received a copy of the GNU Lesser General Public
-## License along with this library; if not, write to the Free Software
-## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-##
-## See http:##www.salome-platform.org/ or
-## email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
-##
+# Copyright (C) 2014-2023  CEA, EDF
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
 
 """
     TestCreateArcByThreePoints.py
@@ -48,13 +47,10 @@ def verifyLastArc(theSketch, theX, theY, theR):
     """
     aLastArc = model.lastSubFeature(theSketch, "SketchArc")
     aCenter = geomDataAPI_Point2D(aLastArc.attribute("center_point"))
-    verifyPointCoordinates(aCenter, theX, theY)
+    model.assertPoint(aCenter, [theX, theY])
     aRadius = aLastArc.real("radius")
     assert aRadius.value() == theR, "Wrong radius {0}, expected {1}".format(aRadius.value(), theR)
 
-def verifyPointCoordinates(thePoint, theX, theY):
-    assert thePoint.x() == theX and thePoint.y() == theY, "Wrong '{0}' point ({1}, {2}), expected ({3}, {4})".format(thePoint.attributeType(), thePoint.x(), thePoint.y(), theX, theY)
-
 def verifyPointOnArc(thePoint, theArc):
     aCenter = geomDataAPI_Point2D(theArc.attribute("center_point"))
     aDistCP = model.distancePointPoint(aCenter, thePoint)
@@ -78,17 +74,9 @@ def verifyTangentCircular(theDistBetweenCenters, theRadius1, theRadius2):
 def verifyTangentArcLine(theArc, theLine):
     aCenter = geomDataAPI_Point2D(theArc.attribute("center_point"))
     aRadius = theArc.real("radius").value()
-    aDistCL = distancePointLine(aCenter, theLine)
+    aDistCL = model.distancePointLine(aCenter, theLine)
     assert math.fabs(aDistCL - aRadius) < TOLERANCE, "Circle and line are not tangent"
 
-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)
-
 
 #=========================================================================
 # Start of test
@@ -178,9 +166,9 @@ anArcPnt3.setValue(aLineStart[0], aLineStart[1])
 aSession.finishOperation()
 assert (aSketchFeature.numberOfSubs() == 7)
 # check the points do not change their positions
-verifyPointCoordinates(aPrevCenter, aPrevCenterXY[0], aPrevCenterXY[1])
-verifyPointCoordinates(aPointCoord, aPointCoodinates[0], aPointCoodinates[1])
-verifyPointCoordinates(aStartPnt, aLineStart[0], aLineStart[1])
+model.assertPoint(aPrevCenter, aPrevCenterXY)
+model.assertPoint(aPointCoord, aPointCoodinates)
+model.assertPoint(aStartPnt, aLineStart)
 # check newly created arc passes through the points
 anArc = model.lastSubFeature(aSketchFeature, "SketchArc")
 verifyPointOnArc(aPrevCenter, anArc)
@@ -209,9 +197,9 @@ anArcPnt3.setValue(20, 25)
 aSession.finishOperation()
 assert (aSketchFeature.numberOfSubs() == 9)
 # check the points do not change their positions
-verifyPointCoordinates(aPrevCenter, aPrevCenterXY[0], aPrevCenterXY[1])
-verifyPointCoordinates(aPointCoord, aPointCoodinates[0], aPointCoodinates[1])
-verifyPointCoordinates(aStartPnt, aLineStart[0], aLineStart[1])
+model.assertPoint(aPrevCenter, aPrevCenterXY)
+model.assertPoint(aPointCoord, aPointCoodinates)
+model.assertPoint(aStartPnt, aLineStart)
 # check sub-features
 model.testNbSubFeatures(aSketch, "SketchConstraintCoincidence", 3)
 model.testNbSubFeatures(aSketch, "SketchConstraintTangent", 1)