Salome HOME
Issue #106 (reopened) fix: Crash on distance between coincident points
authorazv <azv@opencascade.com>
Fri, 12 Sep 2014 07:16:45 +0000 (11:16 +0400)
committerazv <azv@opencascade.com>
Fri, 12 Sep 2014 07:17:33 +0000 (11:17 +0400)
src/GeomAPI/GeomAPI_AISObject.cpp

index 7f068f0f9cd15267c9f23be3e9026b86c3b1b22b..22863757e8a855bdd25058438d88c99c827d74f4 100644 (file)
@@ -23,6 +23,8 @@
 #include <AIS_RadiusDimension.hxx>
 #include <AIS_Shape.hxx>
 
+const double tolerance = 1e-7;
+
 const int CONSTRAINT_TEXT_HEIGHT = 28;  /// the text height of the constraint
 const int CONSTRAINT_TEXT_SELECTION_TOLERANCE = 20;  /// the text selection tolerance
 
@@ -67,9 +69,14 @@ void GeomAPI_AISObject::createDistance(boost::shared_ptr<GeomAPI_Pnt> theStartPo
 {
   double aFlyout = 0;
   if (theFlyoutPoint) {
-    boost::shared_ptr<GeomAPI_Lin> aLine = boost::shared_ptr<GeomAPI_Lin>(
-        new GeomAPI_Lin(theStartPoint, theEndPoint));
-    double aDist = aLine->distance(theFlyoutPoint);
+    double aDist = 0.0;
+    if (theStartPoint->distance(theEndPoint) < tolerance)
+      aDist = theStartPoint->distance(theFlyoutPoint);
+    else {
+      boost::shared_ptr<GeomAPI_Lin> aLine = boost::shared_ptr<GeomAPI_Lin>(
+          new GeomAPI_Lin(theStartPoint, theEndPoint));
+      aDist = aLine->distance(theFlyoutPoint);
+    }
 
     boost::shared_ptr<GeomAPI_XYZ> aLineDir = theEndPoint->xyz()->decreased(theStartPoint->xyz());
     boost::shared_ptr<GeomAPI_XYZ> aFOutDir = theFlyoutPoint->xyz()->decreased(