Salome HOME
Merge branch 'master' into cgt/devCEA
[modules/shaper.git] / src / PythonAPI / Test / TestSketcherSetAngle.py
1 import unittest
2 from salome.shaper import model
3 import math
4 import TestSketcher
5 from TestSketcher import SketcherTestCase
6
7 class SketcherSetAngle(SketcherTestCase):   
8     def runTest(self):
9         # Set the constraint
10         l1 = self.sketch.addLine(0, 0, 0, 1)
11         l2 = self.sketch.addLine(0, 0, 1, 1)
12         self.sketch.setAngle(l1.result(), l2.result(), 30.0)
13         # Commit the transaction
14         model.do()
15         # Check the result
16         dot_product = (l1.endPoint().x() - l1.startPoint().x()) * \
17                       (l2.endPoint().x() - l2.startPoint().x()) + \
18                       (l1.endPoint().y() - l1.startPoint().y()) * \
19                       (l2.endPoint().y() - l2.startPoint().y())
20         norm_1 = math.sqrt(
21             math.pow((l1.endPoint().x() - l1.startPoint().x()), 2) + 
22             math.pow((l1.endPoint().y() - l1.startPoint().y()), 2)
23             )
24         norm_2 = math.sqrt(
25             math.pow((l2.endPoint().x() - l2.startPoint().x()), 2) + 
26             math.pow((l2.endPoint().y() - l2.startPoint().y()), 2)
27             )
28         angle = math.acos(dot_product / (norm_1 * norm_2))
29         self.assertAlmostEqual(
30             angle * 180 / math.pi, 30.0, delta=TestSketcher.DELTA
31             )
32         
33 if __name__ == "__main__":
34     unittest.main()