0022627: Change OCCT memory management defaults
[occt.git] / src / GccAna / GccAna_Circ2dTanOnRad_5.cxx
1 // file GccAna_Circ2dTanOnRad_5.cxx, REG 08/07/91
2 #include <GccAna_Circ2dTanOnRad.jxx>
3
4 #include <ElCLib.hxx>
5 #include <IntAna2d_AnaIntersection.hxx>
6 #include <IntAna2d_IntPoint.hxx>
7 #include <Standard_NegativeValue.hxx>
8 #include <Standard_OutOfRange.hxx>
9 #include <gp_Dir2d.hxx>
10
11 //=========================================================================
12 //   Circle tangent to a point   Point1.                                  +
13 //          center on circle     OnCirc.                                  +
14 //          radius               Radius.                                  +
15 //                                                                        +
16 //  Initialize the table of solutions cirsol and all fields.              +
17 //  Eliminate cases not being the solution.                               +
18 //  Create the circle with center in Point1 of radius Radius.             +
19 //  Intersect this circle with OnCirc and obtain the center points        +
20 //  of found solutions.                                                   +
21 //  Create solutions cirsol.                                              +
22 //=========================================================================
23
24 GccAna_Circ2dTanOnRad::
25    GccAna_Circ2dTanOnRad (const gp_Pnt2d&     Point1    ,
26                           const gp_Circ2d&    OnCirc    ,
27                           const Standard_Real Radius    ,
28                           const Standard_Real Tolerance ):
29    cirsol(1,2)   ,
30    qualifier1(1,2) ,
31    TheSame1(1,2) ,
32    pnttg1sol(1,2),
33    pntcen3(1,2)  ,
34    par1sol(1,2)  ,
35    pararg1(1,2)  ,
36    parcen3(1,2)  
37 {
38
39    gp_Dir2d dirx(1.0,0.0);
40    Standard_Real Tol = Abs(Tolerance);
41    WellDone = Standard_False;
42    NbrSol = 0;
43    Standard_Real Roncirc = OnCirc.Radius();
44    Standard_Real dist1 = Point1.Distance(OnCirc.Location())-Roncirc;
45    Standard_Real dist2 = Point1.Distance(OnCirc.Location())+Roncirc;
46
47    if (Radius < 0.0) { Standard_NegativeValue::Raise(); }
48    else if ((dist1-Radius > Tol) || (Tol < Radius-dist2)) { 
49      WellDone = Standard_True; 
50    }
51    else {
52      Standard_Integer signe = 0;
53      if (Abs(dist1-Radius) < Tol) { signe = 1; }
54      else if (Abs(dist2-Radius) < Tol) { signe = -1; }
55      if (signe != 0) {
56        gp_Ax2d axe(gp_Pnt2d(OnCirc.Location().XY()-Roncirc*
57                          gp_Dir2d(OnCirc.Location().X()-signe*Point1.X(),
58                            OnCirc.Location().Y()-signe*Point1.Y()).XY()),dirx);
59        cirsol(1) = gp_Circ2d(axe,Radius);
60 //      ================================
61        qualifier1(1) = GccEnt_noqualifier;
62        TheSame1(1) = 0;
63        pnttg1sol(1) = Point1;
64        pntcen3(1) = cirsol(1).Location();
65        pararg1(1) = 0.0;
66        par1sol(1)=ElCLib::Parameter(cirsol(1),pnttg1sol(1));
67        parcen3(1) = ElCLib::Parameter(OnCirc,pntcen3(1));
68        WellDone = Standard_True;
69        NbrSol = 1;
70      }
71      else {
72        IntAna2d_AnaIntersection Intp(OnCirc,gp_Circ2d(gp_Ax2d(Point1,dirx),
73                                                       Radius));
74        if (Intp.IsDone()) {
75          if (!Intp.IsEmpty()) {
76            for (Standard_Integer i = 1 ; i <= Intp.NbPoints() ; i++) {
77              NbrSol++;
78              gp_Pnt2d Center(Intp.Point(i).Value());
79              cirsol(NbrSol) = gp_Circ2d(gp_Ax2d(Center,dirx),Radius);
80 //           =======================================================
81        qualifier1(1) = GccEnt_noqualifier;
82              TheSame1(1) = 0;
83              pnttg1sol(1) = Point1;
84              pntcen3(1) = cirsol(1).Location();
85              par1sol(1)=ElCLib::Parameter(cirsol(1),pnttg1sol(1));
86              parcen3(1) = ElCLib::Parameter(OnCirc,pntcen3(1));
87              pararg1(1) = 0.0;
88            }
89          }
90          WellDone = Standard_True;
91        }
92      }
93    }
94  }