0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / GccAna / GccAna_Circ2d2TanRad_5.cxx
1 // Created on: 1991-09-24
2 // Created by: Remi GILET
3 // Copyright (c) 1991-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17
18 #include <ElCLib.hxx>
19 #include <GccAna_Circ2d2TanRad.hxx>
20 #include <GccEnt_BadQualifier.hxx>
21 #include <gp_Ax2d.hxx>
22 #include <gp_Circ2d.hxx>
23 #include <gp_Pnt2d.hxx>
24 #include <IntAna2d_AnaIntersection.hxx>
25 #include <IntAna2d_IntPoint.hxx>
26 #include <Standard_NegativeValue.hxx>
27
28 //   Circle passing by two points of given radius.
29 //   ==============================================
30 //==============================================================================
31 //   Solution of the equation of second degree showing that the center of the  +
32 //   circle is equidistant from two points.                                    +
33 //==============================================================================
34 GccAna_Circ2d2TanRad::
35    GccAna_Circ2d2TanRad (const gp_Pnt2d&             Point1     ,
36                          const gp_Pnt2d&             Point2     ,
37                          const Standard_Real         Radius     ,
38                          const Standard_Real         Tolerance  ):
39    qualifier1(1,2) ,
40    qualifier2(1,2),
41    TheSame1(1,2)   ,
42    TheSame2(1,2)   ,
43    cirsol(1,2)     ,
44    pnttg1sol(1,2)  ,
45    pnttg2sol(1,2)  ,
46    par1sol(1,2)    ,
47    par2sol(1,2)    ,
48    pararg1(1,2)    ,
49    pararg2(1,2)    
50 {
51
52   gp_Dir2d dirx(1.0,0.0);
53   Standard_Real Tol = Abs(Tolerance);
54   NbrSol = 0;
55   WellDone = Standard_False;
56   if (Radius < 0.0) { throw Standard_NegativeValue(); }
57   else {
58     if (Point1.Distance(Point2)-Radius*2.0 > Tol) { WellDone = Standard_True; }
59     else {
60       if (Point1.Distance(Point2)-Radius*2.0 >0.0) {
61         WellDone = Standard_True;
62         NbrSol = 1;
63         gp_Ax2d axe(gp_Pnt2d(0.5*(Point1.XY()+Point2.XY())),dirx);
64         cirsol(1) = gp_Circ2d(axe,Radius);
65 //      =================================
66         qualifier1(1) = GccEnt_noqualifier;
67         qualifier2(1) = GccEnt_noqualifier;
68         TheSame1(1) = 0;
69         TheSame2(1) = 0;
70         pnttg1sol(1) = Point1;
71         pnttg2sol(1) = Point2;
72       }
73       else {
74         gp_Circ2d C1(gp_Ax2d(Point1,dirx),Radius);
75         gp_Circ2d C2(gp_Ax2d(Point2,dirx),Radius);
76         IntAna2d_AnaIntersection Intp(C1,C2);
77         if (Intp.IsDone()) {
78           if (!Intp.IsEmpty()) {
79             for (Standard_Integer i = 1 ; i <= Intp.NbPoints() ; i++) {
80               NbrSol++;
81               gp_Pnt2d Center(Intp.Point(i).Value());
82               cirsol(NbrSol) = gp_Circ2d(gp_Ax2d(Center,dirx),Radius);
83 //            =======================================================
84               qualifier1(NbrSol) = GccEnt_noqualifier;
85               qualifier2(NbrSol) = GccEnt_noqualifier;
86               TheSame1(NbrSol) = 0;
87               TheSame2(NbrSol) = 0;
88               pnttg1sol(NbrSol) = Point1;
89               pnttg2sol(NbrSol) = Point2;
90             }
91           }
92           WellDone = Standard_True;
93         }
94       }
95     }
96   }
97   for (Standard_Integer i = 1 ; i <= NbrSol ; i++) {
98     pararg1(i) = 0.;
99     pararg2(i) = 0.;
100     par1sol(i)=ElCLib::Parameter(cirsol(i),pnttg1sol(i));
101     par2sol(i)=ElCLib::Parameter(cirsol(i),pnttg2sol(i));
102   }
103 }
104