Salome HOME
[Code coverage GeomAlgoAPI]: Call static methods of builders
[modules/shaper.git] / src / GeomAPI / Test / TestBuilders.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 GeomAlgoAPI import GeomAlgoAPI_Circ2dBuilder as circBuilder
24 from GeomAlgoAPI import GeomAlgoAPI_CurveBuilder as curveBuilder
25 from GeomAlgoAPI import GeomAlgoAPI_EdgeBuilder as edgeBuilder
26 from GeomAlgoAPI import GeomAlgoAPI_FaceBuilder as faceBuilder
27 from GeomAlgoAPI import GeomAlgoAPI_ShapeTools as tools
28 from GeomAlgoAPI import GeomAlgoAPI_MakeVolume as makeVolume
29 from GeomAPI import GeomAPI_Ax3 as ax3
30 from GeomAPI import GeomAPI_Dir as dir
31 from GeomAPI import GeomAPI_Pnt as pnt
32 from GeomAPI import GeomAPI_Pnt2d as pnt2d
33 from GeomAPI import GeomAPI_Circ2d
34 from GeomAPI import GeomAPI_Shape
35
36 TOLERANCE = 1.e-7
37
38 center = pnt(10, 0, 0)
39 normal = dir(0, 0, 1)
40 xAxis = dir(1, 0, 0)
41 majorRadius = 10
42 minorRadius = 5
43
44 # Test 1. Elliptical edge
45 ellipseEdge = edgeBuilder.ellipse(center, normal, xAxis, majorRadius, minorRadius)
46 ellipse = ellipseEdge.ellipse()
47 assert(ellipse is not None)
48 assert(ellipse.center().distance(center) < TOLERANCE)
49 assert(ellipse.firstFocus().distance(pnt(18.66025404, 0., 0.)) < TOLERANCE)
50 assert(ellipse.secondFocus().distance(pnt(1.339745962, 0., 0.)) < TOLERANCE)
51 assert(ellipse.majorRadius() == majorRadius)
52 assert(ellipse.minorRadius() == minorRadius)
53
54 # Test 2. Square face
55 size = 100.
56 squareFace = faceBuilder.squareFace(center, normal, size)
57 assert(squareFace.middlePoint().distance(center) < TOLERANCE)
58
59 # Test 3. Check are of the face
60 assert(tools.area(squareFace) == size**2)
61
62 # Test 4. Check properties of wrong shapes
63 assert(tools.volume(None) == 0)
64 assert(tools.volume(GeomAPI_Shape()) == 0)
65 assert(tools.area(None) == 0)
66 assert(tools.area(GeomAPI_Shape()) == 0)
67 assert(tools.centreOfMass(None) is None)
68 assert(tools.centreOfMass(GeomAPI_Shape()) is None)
69
70 # Test 5. Curve with duplicated points
71 points = [pnt(10, 0, 0),
72           pnt(20, 10, 0),
73           pnt(20, 10, 0),
74           pnt(10, 10, 0),
75           pnt(10, 0, 0)]
76 curve = curveBuilder.edge(points, True, True, None, None)
77 assert(curve is not None)
78
79 # Test 6. Circle by center and radius
80 center = pnt2d(5, 0)
81 radius = 5
82 plane = ax3(pnt(0, 0, 0), dir(0, 0, 1), dir(1, 0, 0))
83 circleBuilder = circBuilder(plane)
84 circleBuilder.setCenter(center)
85 circleBuilder.setRadius(radius)
86 circle = circBuilder.circle(circleBuilder)
87 assert(circle is not None)
88 assert(circle.center().distance(center) < TOLERANCE)
89 assert(circle.radius() == radius)
90
91 # Test 7. Circle by 3 points
92 p1 = pnt2d(center.x() + radius, center.y())
93 p2 = pnt2d(center.x() - radius, center.y())
94 p3 = pnt2d(center.x(), center.y() + radius)
95 circle = circBuilder.circle(p1, p2, p3)
96 assert(circle is not None)
97 assert(circle.center().distance(center) < TOLERANCE)
98 assert(circle.radius() == radius)