Salome HOME
Merge remote-tracking branch 'remotes/origin/master' into Dev_2.8.0
[modules/shaper.git] / src / PythonAPI / model / sketcher / tools.py
index de3032f54d16bae221e821bfa78cb0d68c397e36..5c1903a062196d3e71b4565a7f993cd9e097b01b 100644 (file)
@@ -77,6 +77,20 @@ def distancePointPoint(thePoint1, thePoint2):
         aGeomPnt2 = thePoint2.pnt()
     return aGeomPnt1.distance(aGeomPnt2)
 
+def signedDistancePointLine(thePoint, theLine):
+    aPoint = toList(thePoint)
+    aLine = toSketchFeature(theLine)
+
+    aLineStart = geomDataAPI_Point2D(aLine.attribute("StartPoint")).pnt().xy()
+    aLineEnd = geomDataAPI_Point2D(aLine.attribute("EndPoint")).pnt().xy()
+    aLineDir = aLineEnd.decreased(aLineStart)
+    aLineLen = aLineEnd.distance(aLineStart)
+    aCross = (aPoint[0] - aLineStart.x()) * aLineDir.y() - (aPoint[1] - aLineStart.y()) * aLineDir.x()
+    return aCross / aLineLen
+
+def distancePointLine(thePoint, theLine):
+    return math.fabs(signedDistancePointLine(thePoint, theLine))
+
 def lastSubFeature(theSketch, theKind):
     """
     obtains last feature of given kind from the sketch