Salome HOME
Update calculation of angle value (issue #788)
[modules/shaper.git] / src / SketchSolver / SketchSolver_ConstraintAngle.cpp
1 #include <SketchSolver_ConstraintAngle.h>
2
3 #include <cmath>
4
5 void SketchSolver_ConstraintAngle::getAttributes(
6     double& theValue, std::vector<Slvs_hEntity>& theAttributes)
7 {
8   SketchSolver_Constraint::getAttributes(theValue, theAttributes);
9
10   myAngle = theValue;
11 }
12
13
14 void SketchSolver_ConstraintAngle::adjustConstraint()
15 {
16   Slvs_Constraint aConstraint = myStorage->getConstraint(mySlvsConstraints.front());
17
18   double aLineDir[2][2] = { {0.0, 0.0}, {0.0, 0.0} };
19   Slvs_hEntity anEnt[2] = {aConstraint.entityA, aConstraint.entityB};
20   for (int i = 0; i < 2; i++) {
21     const Slvs_Entity& aLine = myStorage->getEntity(anEnt[i]);
22     double aCoef = -1.0;
23     for (int j = 0; j < 2; j++, aCoef += 2.0) {
24       const Slvs_Entity& aPoint = myStorage->getEntity(aLine.point[j]);
25       for (int k = 0; k < 2; k++)
26         aLineDir[i][k] += aCoef * myStorage->getParameter(aPoint.param[k]).val;
27     }
28   }
29   double aDot = aLineDir[0][0] * aLineDir[1][0] + aLineDir[0][1] * aLineDir[1][1];
30
31   aConstraint.other = aDot * (90.0 - fabs(aConstraint.valA)) < 0.0;
32   if ((90.0 - fabs(aConstraint.valA)) * (90.0 - fabs(myAngle)) < 0.0)
33     aConstraint.other = !aConstraint.other;
34   myAngle = aConstraint.valA;
35   myStorage->updateConstraint(aConstraint);
36 }