Salome HOME
Merge branch 'V9_11_BR'
[modules/shaper.git] / src / GeomAPI / Test / TestAx123.py
1 # Copyright (C) 2018-2023  CEA, EDF
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 email : webmaster.salome@opencascade.com
18 #
19
20 import math
21
22 from GeomAPI import *
23
24 TOLERANCE = 1.e-7
25
26 origin = GeomAPI_Pnt(10, 0, 0)
27 dir = GeomAPI_Dir(1, 0, 0)
28
29 # Test GeomAPI_Ax1
30 ax1 = GeomAPI_Ax1()
31 ax1.setOrigin(origin)
32 ax1.setDir(dir)
33 assert(ax1.origin().distance(origin) < TOLERANCE)
34 assert(math.fabs(ax1.dir().dot(dir) - 1.) < TOLERANCE)
35
36 ax1.reverse()
37 ax1 = ax1.reversed()
38 assert(ax1.origin().distance(origin) < TOLERANCE)
39 assert(math.fabs(ax1.dir().dot(dir) - 1.) < TOLERANCE)
40
41
42 # Test GeomAPI_Ax2
43 ax2 = GeomAPI_Ax2()
44 ax2.setOrigin(origin)
45 ax2.setDir(dir)
46 assert(ax2.origin().distance(origin) < TOLERANCE)
47 assert(math.fabs(ax2.dir().dot(dir) - 1.) < TOLERANCE)
48
49 ax2 = GeomAPI_Ax2(origin, dir)
50 assert(ax2.origin().distance(origin) < TOLERANCE)
51 assert(math.fabs(ax2.dir().dot(dir) - 1.) < TOLERANCE)
52
53 dx = GeomAPI_Dir(0, 1, 0)
54 ax2 = GeomAPI_Ax2(origin, dir, dx)
55 assert(ax2.origin().distance(origin) < TOLERANCE)
56 assert(math.fabs(ax2.dir().dot(dir) - 1.) < TOLERANCE)
57
58
59 # Test GeomAPI_Ax3
60 dy = GeomAPI_Dir(0, 0, 1)
61 ax3 = GeomAPI_Ax3()
62 ax3.setOrigin(origin)
63 ax3.setNormal(dy)
64 ax3.setDirX(dir)
65 ax3.setDirY(dx)
66 assert(ax3.origin().distance(origin) < TOLERANCE)
67 assert(math.fabs(ax3.normal().dot(dy) - 1.) < TOLERANCE)
68 assert(math.fabs(ax3.dirX().dot(dir) - 1.) < TOLERANCE)
69 assert(math.fabs(ax3.dirY().dot(dx) - 1.) < TOLERANCE)
70
71 ax3 = GeomAPI_Ax3(origin, dx, dir)
72 assert(ax3.origin().distance(origin) < TOLERANCE)
73 assert(math.fabs(ax3.normal().dot(dir) - 1.) < TOLERANCE)
74 assert(math.fabs(ax3.dirX().dot(dx) - 1.) < TOLERANCE)
75 assert(math.fabs(ax3.dirY().dot(dy) - 1.) < TOLERANCE)
76
77 p2d = GeomAPI_Pnt2d(1, 2)
78 a2d = ax3.to2D(origin.x() + dx.x() * p2d.x() + dy.x() * p2d.y(),
79                origin.y() + dx.y() * p2d.x() + dy.y() * p2d.y(),
80                origin.z() + dx.z() * p2d.x() + dy.z() * p2d.y())
81 assert(a2d.distance(p2d) < TOLERANCE)