Salome HOME
Merge remote-tracking branch 'origin/Toolbars_Management'
[modules/shaper.git] / src / GeomAPI / Test / TestEllipse2d.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 center = GeomAPI_Pnt2d(10, 0)
28 xAxis = GeomAPI_Dir2d(1, 0)
29 majorRadius = 10
30 minorRadius = 5
31
32 # Test 1. Default ellipse
33 ellipse = GeomAPI_Ellipse2d(center, xAxis, majorRadius, minorRadius)
34 assert(ellipse.center().distance(center) < TOLERANCE)
35 assert(ellipse.firstFocus().distance(GeomAPI_Pnt2d(18.66025404, 0.)) < TOLERANCE)
36 assert(ellipse.secondFocus().distance(GeomAPI_Pnt2d(1.339745962, 0.)) < TOLERANCE)
37 assert(ellipse.majorRadius() == majorRadius)
38 assert(ellipse.minorRadius() == minorRadius)
39
40 # Test 2. Ellipse with swapped radii
41 ellipse = GeomAPI_Ellipse2d(center, xAxis, minorRadius, majorRadius)
42 assert(ellipse.center().distance(center) < TOLERANCE)
43 assert(ellipse.firstFocus().distance(GeomAPI_Pnt2d(10., 8.66025404)) < TOLERANCE)
44 assert(ellipse.secondFocus().distance(GeomAPI_Pnt2d(10., -8.66025404)) < TOLERANCE)
45 assert(ellipse.majorRadius() == majorRadius)
46 assert(ellipse.minorRadius() == minorRadius)
47
48 # Test 3. Ellipse by 3 points
49 axisPnt = GeomAPI_Pnt2d(center.x() + majorRadius, center.y())
50 passedPnt = GeomAPI_Pnt2d(center.x(), center.y() + minorRadius)
51 ellipse = GeomAPI_Ellipse2d(center, axisPnt, passedPnt)
52 assert(ellipse.center().distance(center) < TOLERANCE)
53 assert(ellipse.firstFocus().distance(GeomAPI_Pnt2d(18.66025404, 0.)) < TOLERANCE)
54 assert(ellipse.secondFocus().distance(GeomAPI_Pnt2d(1.339745962, 0.)) < TOLERANCE)
55 assert(ellipse.majorRadius() == majorRadius)
56 assert(ellipse.minorRadius() == minorRadius)