]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Update the angle calculation when lines are intersected in the inner point
authorazv <azv@opencascade.com>
Fri, 11 Sep 2015 06:36:16 +0000 (09:36 +0300)
committerazv <azv@opencascade.com>
Fri, 11 Sep 2015 06:36:16 +0000 (09:36 +0300)
src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp

index 9fbe2d84fa4b21b38b963c4cc65e681416124845..7874be39513f2c17c99082de801dbabbed27d366 100644 (file)
@@ -154,16 +154,31 @@ double SketchPlugin_ConstraintAngle::calculateAngle()
   std::shared_ptr<GeomAPI_Pnt2d> aStartB = aPointB1->pnt();
   std::shared_ptr<GeomAPI_Pnt2d> aEndB   = aPointB2->pnt();
 
+  double aDist[2][2] = {
+      { anInter->distance(aStartA), anInter->distance(aEndA) },
+      { anInter->distance(aStartB), anInter->distance(aEndB) }
+  };
+
   // Directions of lines
-  if (anInter->distance(aEndA) < tolerance)
+  if (aDist[0][1] < tolerance)
     aEndA = aStartA;
-  if (anInter->distance(aEndB) < tolerance)
+  if (aDist[1][1] < tolerance)
     aEndB = aStartB;
   std::shared_ptr<GeomAPI_Dir2d> aDirA(new GeomAPI_Dir2d(aEndA->xy()->decreased(anInter->xy())));
   std::shared_ptr<GeomAPI_Dir2d> aDirB(new GeomAPI_Dir2d(aEndB->xy()->decreased(anInter->xy())));
 
-  anAngle = aDirA->angle(aDirB) * 180.0 / PI;
-  return fabs(anAngle);
+  anAngle = fabs(aDirA->angle(aDirB)) * 180.0 / PI;
+
+  // If the lines intersected inside one of them, the angle selected is less than 90 degrees
+  if ((aDist[0][0] >= tolerance && aDist[0][1] >= tolerance &&
+      aDist[0][0] + aDist[0][1] < aStartA->distance(aEndA) + 2.0 * tolerance) ||
+      (aDist[1][0] >= tolerance && aDist[1][1] >= tolerance &&
+      aDist[1][0] + aDist[1][1] < aStartB->distance(aEndB) + 2.0 * tolerance)) {
+    if (anAngle > 90.0)
+      anAngle = 180.0 - anAngle;
+  }
+
+  return anAngle;
 }
 
 void SketchPlugin_ConstraintAngle::move(double theDeltaX, double theDeltaY)