Salome HOME
ebcfb39d962f95920446533c8c4a612b4255fc80
[modules/shaper.git] / src / GeomAPI / Test / TestEllipse2d.py
1 # Copyright (C) 2018-2023  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 email : webmaster.salome@opencascade.com
18 #
19
20 import math
21
22 from GeomAPI import *
23
24 TOLERANCE = 1.e-7
25
26 center = GeomAPI_Pnt2d(10, 0)
27 xAxis = GeomAPI_Dir2d(1, 0)
28 majorRadius = 10
29 minorRadius = 5
30
31 # Test 1. Default ellipse
32 ellipse = GeomAPI_Ellipse2d(center, xAxis, majorRadius, minorRadius)
33 assert(ellipse.center().distance(center) < TOLERANCE)
34 assert(ellipse.firstFocus().distance(GeomAPI_Pnt2d(18.66025404, 0.)) < TOLERANCE)
35 assert(ellipse.secondFocus().distance(GeomAPI_Pnt2d(1.339745962, 0.)) < TOLERANCE)
36 assert(ellipse.majorRadius() == majorRadius)
37 assert(ellipse.minorRadius() == minorRadius)
38
39 # Test 2. Ellipse with swapped radii
40 ellipse = GeomAPI_Ellipse2d(center, xAxis, minorRadius, majorRadius)
41 assert(ellipse.center().distance(center) < TOLERANCE)
42 assert(ellipse.firstFocus().distance(GeomAPI_Pnt2d(10., 8.66025404)) < TOLERANCE)
43 assert(ellipse.secondFocus().distance(GeomAPI_Pnt2d(10., -8.66025404)) < TOLERANCE)
44 assert(ellipse.majorRadius() == majorRadius)
45 assert(ellipse.minorRadius() == minorRadius)
46
47 # Test 3. Ellipse by 3 points
48 axisPnt = GeomAPI_Pnt2d(center.x() + majorRadius, center.y())
49 passedPnt = GeomAPI_Pnt2d(center.x(), center.y() + minorRadius)
50 ellipse = GeomAPI_Ellipse2d(center, axisPnt, passedPnt)
51 assert(ellipse.center().distance(center) < TOLERANCE)
52 assert(ellipse.firstFocus().distance(GeomAPI_Pnt2d(18.66025404, 0.)) < TOLERANCE)
53 assert(ellipse.secondFocus().distance(GeomAPI_Pnt2d(1.339745962, 0.)) < TOLERANCE)
54 assert(ellipse.majorRadius() == majorRadius)
55 assert(ellipse.minorRadius() == minorRadius)