Warnings on vc14 were eliminated
[occt.git] / src / GccAna / GccAna_Circ2d3Tan_7.cxx
1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
15
16 #include <ElCLib.hxx>
17 #include <GccAna_Circ2d3Tan.hxx>
18 #include <GccAna_CircPnt2dBisec.hxx>
19 #include <GccAna_Pnt2dBisec.hxx>
20 #include <GccEnt_BadQualifier.hxx>
21 #include <GccEnt_QualifiedCirc.hxx>
22 #include <GccEnt_QualifiedLin.hxx>
23 #include <GccInt_BCirc.hxx>
24 #include <GccInt_BElips.hxx>
25 #include <GccInt_BHyper.hxx>
26 #include <GccInt_BLine.hxx>
27 #include <GccInt_IType.hxx>
28 #include <gp_Circ2d.hxx>
29 #include <gp_Dir2d.hxx>
30 #include <gp_Lin2d.hxx>
31 #include <gp_Pnt2d.hxx>
32 #include <IntAna2d_AnaIntersection.hxx>
33 #include <IntAna2d_Conic.hxx>
34 #include <IntAna2d_IntPoint.hxx>
35 #include <Precision.hxx>
36 #include <Standard_OutOfRange.hxx>
37 #include <StdFail_NotDone.hxx>
38 #include <TColStd_Array1OfReal.hxx>
39
40 //=======================================================================
41 //   Creation of a circle tangent to a circle and two points.           +
42 //=======================================================================
43 GccAna_Circ2d3Tan::
44    GccAna_Circ2d3Tan (const GccEnt_QualifiedCirc& Qualified1 ,
45                       const gp_Pnt2d&             Point2     ,
46                       const gp_Pnt2d&             Point3     ,
47                       const Standard_Real         Tolerance  ):
48
49    cirsol(1,2)     ,
50    qualifier1(1,2) ,
51    qualifier2(1,2) ,
52    qualifier3(1,2) ,
53    TheSame1(1,2)   ,
54    TheSame2(1,2)   ,
55    TheSame3(1,2)   ,
56    pnttg1sol(1,2)  ,
57    pnttg2sol(1,2)  ,
58    pnttg3sol(1,2)  ,
59    par1sol(1,2)    ,
60    par2sol(1,2)    ,
61    par3sol(1,2)    ,
62    pararg1(1,2)    ,
63    pararg2(1,2)    ,
64    pararg3(1,2)    
65 {
66
67    gp_Dir2d dirx(1.0,0.0);
68    Standard_Real Tol = Abs(Tolerance);
69    WellDone = Standard_False;
70    NbrSol = 0;
71    if (!(Qualified1.IsEnclosed() || Qualified1.IsEnclosing() || 
72          Qualified1.IsOutside() || Qualified1.IsUnqualified())) {
73      throw GccEnt_BadQualifier();
74      return;
75    }
76
77 //=========================================================================
78 //   Processing.                                                          +
79 //=========================================================================
80
81    gp_Circ2d C1 = Qualified1.Qualified();
82    Standard_Real R1 = C1.Radius();
83    gp_Pnt2d center1(C1.Location());
84    TColStd_Array1OfReal Radius(1,2);
85
86    if (Point2.IsEqual(Point3,Precision::Confusion())) {
87      WellDone = Standard_False;
88      return ;
89    }
90
91    GccAna_Pnt2dBisec Bis1(Point2,Point3);
92    GccAna_CircPnt2dBisec Bis2(C1,Point2);
93
94    if (Bis1.IsDone() && Bis2.IsDone()) {
95      Standard_Integer nbsolution2 = Bis2.NbSolutions();
96      for (Standard_Integer i = 1 ; i <=  nbsolution2; i++) {
97        Handle(GccInt_Bisec) Sol2 = Bis2.ThisSolution(i);
98        GccInt_IType typ2 = Sol2->ArcType();
99        gp_Lin2d Sol1(Bis1.ThisSolution());
100        IntAna2d_AnaIntersection Intp;
101        if (typ2 == GccInt_Cir) {
102          Intp.Perform(Sol1,Sol2->Circle());
103        }
104        else if (typ2 == GccInt_Lin) {
105          Intp.Perform(Sol1,Sol2->Line());
106        }
107        else if (typ2 == GccInt_Hpr) {
108          Intp.Perform(Sol1,IntAna2d_Conic(Sol2->Hyperbola()));
109        }
110        else if (typ2 == GccInt_Ell) {
111          Intp.Perform(Sol1,IntAna2d_Conic(Sol2->Ellipse()));
112        }
113
114        if (Intp.IsDone()) {
115          if (!Intp.IsEmpty()) {
116            for (Standard_Integer j = 1 ; j <= Intp.NbPoints() ; j++) {
117              gp_Pnt2d Center(Intp.Point(j).Value());
118              Standard_Real dist1 = Center.Distance(center1);
119              Standard_Real dist2 = Center.Distance(Point2);
120              Standard_Real dist3 = Center.Distance(Point3);
121              Standard_Integer nbsol1 = 0;
122 //           Standard_Integer nbsol2 = 0;
123              Standard_Integer nbsol3 = 0;
124              Standard_Boolean ok = Standard_False;
125              if (Qualified1.IsEnclosed()) {
126                if (dist1-R1 < Tolerance) {
127                  Radius(1) = Abs(R1-dist1);
128                  nbsol1 = 1;
129                  ok = Standard_True;
130                }
131              }
132              else if (Qualified1.IsOutside()) {
133                if (R1-dist1 < Tolerance) {
134                  Radius(1) = Abs(R1-dist1);
135                  nbsol1 = 1;
136                  ok = Standard_True;
137                }
138              }
139              else if (Qualified1.IsEnclosing()) {
140                ok = Standard_True;
141                nbsol1 = 1;
142                Radius(1) = R1+dist1;
143              }
144              else if (Qualified1.IsUnqualified()) {
145                ok = Standard_True;
146                nbsol1 = 2;
147                Radius(1) = Abs(R1-dist1);
148                Radius(2) = R1+dist1;
149              }
150              if (ok) {
151                ok = Standard_False;
152                for (Standard_Integer ii = 1 ; ii <= nbsol1 ; ii++) {
153 //pop            if (Abs(dist2-Radius(ii))<=Tol && Abs(dist2-Radius(ii))<=Tol){
154                  if (Abs(dist2-Radius(ii))<=Tol && Abs(dist3-Radius(ii))<=Tol){
155                    nbsol3 = ii;
156                    ok = Standard_True;
157                  }
158                }
159              }
160
161              if (ok) {
162 //             for (Standard_Integer k = 1 ; k <= nbsol3 ; k++) {
163                  if (NbrSol>=2) break;
164                  NbrSol++;
165 //               cirsol(NbrSol) = gp_Circ2d(gp_Ax2d(Center,dirx),Radius(k));
166                  cirsol(NbrSol) = gp_Circ2d(gp_Ax2d(Center,dirx),Radius(nbsol3));
167 //               ==========================================================
168                  Standard_Real distcc1 = Center.Distance(center1);
169                  if (!Qualified1.IsUnqualified()) { 
170                    qualifier1(NbrSol) = Qualified1.Qualifier();
171                  }
172                  else if (Abs(distcc1+Radius(nbsol3)-R1) < Tol) {
173                    qualifier1(NbrSol) = GccEnt_enclosed;
174                  }
175                  else if (Abs(distcc1-R1-Radius(nbsol3)) < Tol) {
176                    qualifier1(NbrSol) = GccEnt_outside;
177                  }
178                  else { qualifier1(NbrSol) = GccEnt_enclosing; }
179                  qualifier2(NbrSol) = GccEnt_noqualifier;
180                  qualifier3(NbrSol) = GccEnt_noqualifier;
181                  if (Center.Distance(center1) <= Tolerance &&
182                      Abs(Radius(nbsol3)-R1) <= Tolerance) {
183                    TheSame1(NbrSol) = 1;
184                  }
185                  else {
186                    TheSame1(NbrSol) = 0;
187                    gp_Dir2d dc(center1.XY()-Center.XY());
188                    pnttg1sol(NbrSol)=gp_Pnt2d(Center.XY()+Radius(nbsol3)*dc.XY());
189                    par1sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),
190                                                     pnttg1sol(NbrSol));
191                    pararg1(NbrSol)=ElCLib::Parameter(C1,pnttg1sol(NbrSol));
192                  }
193
194                  TheSame2(NbrSol) = 0;
195                  pnttg2sol(NbrSol) = Point2;
196                  par2sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),
197                                                   pnttg2sol(NbrSol));
198                  pararg2(NbrSol)=0.;
199                  TheSame3(NbrSol) = 0;
200                  pnttg3sol(NbrSol) = Point3;
201                  par3sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),
202                                                   pnttg3sol(NbrSol));
203                  pararg3(NbrSol) = 0.;
204                //}
205              }
206            }
207          }
208          WellDone = Standard_True;
209        }
210      }
211    }
212  }
213
214