Salome HOME
[Code coverage GeomAPI]: Unit test for Ax1, Ax2, Ax3
[modules/shaper.git] / src / GeomAPI / Test / TestAx123.py
1 ## Copyright (C) 2018-20xx  CEA/DEN, EDF R&D
2 ##
3 ## This library is free software; you can redistribute it and/or
4 ## modify it under the terms of the GNU Lesser General Public
5 ## License as published by the Free Software Foundation; either
6 ## version 2.1 of the License, or (at your option) any later version.
7 ##
8 ## This library is distributed in the hope that it will be useful,
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 ## Lesser General Public License for more details.
12 ##
13 ## You should have received a copy of the GNU Lesser General Public
14 ## License along with this library; if not, write to the Free Software
15 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 ##
17 ## See http:##www.salome-platform.org/ or
18 ## email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 ##
20
21 import math
22
23 from GeomAPI import *
24
25 TOLERANCE = 1.e-7
26
27 origin = GeomAPI_Pnt(10, 0, 0)
28 dir = GeomAPI_Dir(1, 0, 0)
29
30 # Test GeomAPI_Ax1
31 ax1 = GeomAPI_Ax1()
32 ax1.setOrigin(origin)
33 ax1.setDir(dir)
34 assert(ax1.origin().distance(origin) < TOLERANCE)
35 assert(math.fabs(ax1.dir().dot(dir) - 1.) < TOLERANCE)
36
37 ax1.reverse()
38 ax1 = ax1.reversed()
39 assert(ax1.origin().distance(origin) < TOLERANCE)
40 assert(math.fabs(ax1.dir().dot(dir) - 1.) < TOLERANCE)
41
42
43 # Test GeomAPI_Ax2
44 ax2 = GeomAPI_Ax2()
45 ax2.setOrigin(origin)
46 ax2.setDir(dir)
47 assert(ax2.origin().distance(origin) < TOLERANCE)
48 assert(math.fabs(ax2.dir().dot(dir) - 1.) < TOLERANCE)
49
50 ax2 = GeomAPI_Ax2(origin, dir)
51 assert(ax2.origin().distance(origin) < TOLERANCE)
52 assert(math.fabs(ax2.dir().dot(dir) - 1.) < TOLERANCE)
53
54 dx = GeomAPI_Dir(0, 1, 0)
55 ax2 = GeomAPI_Ax2(origin, dir, dx)
56 assert(ax2.origin().distance(origin) < TOLERANCE)
57 assert(math.fabs(ax2.dir().dot(dir) - 1.) < TOLERANCE)
58
59
60 # Test GeomAPI_Ax3
61 dy = GeomAPI_Dir(0, 0, 1)
62 ax3 = GeomAPI_Ax3()
63 ax3.setOrigin(origin)
64 ax3.setNormal(dy)
65 ax3.setDirX(dir)
66 ax3.setDirY(dx)
67 assert(ax3.origin().distance(origin) < TOLERANCE)
68 assert(math.fabs(ax3.normal().dot(dy) - 1.) < TOLERANCE)
69 assert(math.fabs(ax3.dirX().dot(dir) - 1.) < TOLERANCE)
70 assert(math.fabs(ax3.dirY().dot(dx) - 1.) < TOLERANCE)
71
72 ax3 = GeomAPI_Ax3(origin, dx, dir)
73 assert(ax3.origin().distance(origin) < TOLERANCE)
74 assert(math.fabs(ax3.normal().dot(dir) - 1.) < TOLERANCE)
75 assert(math.fabs(ax3.dirX().dot(dx) - 1.) < TOLERANCE)
76 assert(math.fabs(ax3.dirY().dot(dy) - 1.) < TOLERANCE)
77
78 p2d = GeomAPI_Pnt2d(1, 2)
79 a2d = ax3.to2D(origin.x() + dx.x() * p2d.x() + dy.x() * p2d.y(),
80                origin.y() + dx.y() * p2d.x() + dy.y() * p2d.y(),
81                origin.z() + dx.z() * p2d.x() + dy.z() * p2d.y())
82 assert(a2d.distance(p2d) < TOLERANCE)