0024510: Remove unused local variables
[occt.git] / src / GccAna / GccAna_Circ2d2TanOn_8.cxx
1 // Created on: 1992-01-02
2 // Created by: Remi GILET
3 // Copyright (c) 1992-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
9 // under the terms of the GNU Lesser General Public 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 //   Creation of a circle tangent to two elements : Straight line.        +
19 //                                                  Circle.               +
20 //                                                  Point.                +
21 //                              center on a third : Straight line.        +
22 //                                                  Circle.               +
23 //=========================================================================
24
25 #include <GccAna_Circ2d2TanOn.jxx>
26
27 #include <ElCLib.hxx>
28 #include <gp_Dir2d.hxx>
29 #include <gp_Ax2d.hxx>
30 #include <IntAna2d_AnaIntersection.hxx>
31 #include <IntAna2d_IntPoint.hxx>
32 #include <Standard_ConstructionError.hxx>
33 #include <GccInt_IType.hxx>
34 #include <GccInt_Bisec.hxx>
35 #include <GccInt_BLine.hxx>
36 #include <GccInt_BCirc.hxx>
37 #include <IntAna2d_Conic.hxx>
38 #include <GccAna_CircPnt2dBisec.hxx>
39 #include <TColStd_Array1OfReal.hxx>
40 #include <GccEnt_BadQualifier.hxx>
41 #include <Precision.hxx>
42 GccAna_Circ2d2TanOn::
43    GccAna_Circ2d2TanOn (const GccEnt_QualifiedCirc& Qualified1 ,
44                         const gp_Pnt2d&             Point2     ,
45                         const gp_Circ2d&            OnCirc     ,
46                         const Standard_Real         Tolerance  ):
47    cirsol(1,4)     ,
48    qualifier1(1,4) ,
49    qualifier2(1,4),
50    TheSame1(1,4)   ,
51    TheSame2(1,4)   ,
52    pnttg1sol(1,4)  ,
53    pnttg2sol(1,4)  ,
54    pntcen(1,4)     ,
55    par1sol(1,4)    ,
56    par2sol(1,4)    ,
57    pararg1(1,4)    ,
58    pararg2(1,4)    ,
59    parcen3(1,4)    
60 {
61   TheSame1.Init(0);
62   TheSame2.Init(0);
63   WellDone = Standard_False;
64   NbrSol = 0;
65   if (!(Qualified1.IsEnclosed() || Qualified1.IsEnclosing() || 
66         Qualified1.IsOutside() || Qualified1.IsUnqualified())) {
67     GccEnt_BadQualifier::Raise();
68     return;
69   }
70   Standard_Real Tol = Abs(Tolerance);
71   TColStd_Array1OfReal Radius(1,2);
72   gp_Dir2d dirx(1.,0.);
73   gp_Circ2d C1 = Qualified1.Qualified();
74   Standard_Real R1 = C1.Radius();
75   gp_Pnt2d center1(C1.Location());
76
77 //=========================================================================
78 //   Processing of boundary cases.                                          +
79 //=========================================================================
80
81   Standard_Integer nbsol1 = 1;
82 //  Standard_Integer nbsol2 = 0;
83   Standard_Real Ron = OnCirc.Radius();
84   Standard_Real distcco = OnCirc.Location().Distance(center1);
85   gp_Pnt2d pinterm;
86   gp_Dir2d dircc;
87   Standard_Boolean SameCenter(Standard_False);
88   if (!OnCirc.Location().IsEqual(center1,Precision::Confusion())) {
89     dircc = gp_Dir2d(OnCirc.Location().XY()-center1.XY());
90     pinterm = gp_Pnt2d(center1.XY()+(distcco-Ron)*dircc.XY());
91     Standard_Real distcc2 =pinterm.Distance(Point2);
92     Standard_Real distcc1 =pinterm.Distance(center1);
93     Standard_Real d1 = Abs(distcc2-Abs(distcc1-R1));
94     Standard_Real d2 = Abs(distcc2-(distcc1+R1));
95     if ( d1 > Tol || d2 > Tol) {
96       if (!SameCenter) pinterm = gp_Pnt2d(center1.XY()+(distcco+Ron)*dircc.XY());
97       distcc2 =pinterm.Distance(Point2);
98       distcc1 =pinterm.Distance(center1);
99       d1 = Abs(distcc2-Abs(distcc1-R1));
100       d2 = Abs(distcc2-(distcc1+R1));
101       if ( d1 > Tol || d2 > Tol ) { nbsol1 = 0; }
102     }
103     if (nbsol1 > 0) {
104       if (Qualified1.IsEnclosed() || Qualified1.IsOutside()) {
105         nbsol1 = 1;
106         Radius(1) = Abs(distcc1-R1);
107       }
108       else if (Qualified1.IsEnclosing()) {
109         nbsol1 = 1;
110         Radius(1) = R1+distcc1;
111       }
112       else if (Qualified1.IsUnqualified()) {
113         nbsol1 = 2;
114         Radius(1) = Abs(distcc1-R1);
115         Radius(2) = R1+distcc1;
116       }
117       for (Standard_Integer i = 1 ; i <= nbsol1 ; i++) {
118         WellDone = Standard_True;
119         if (!(i == 1 && SameCenter)) {
120           NbrSol++;
121           cirsol(NbrSol) = gp_Circ2d(gp_Ax2d(pinterm,dirx),Radius(i));
122 //    ===========================================================
123           gp_Dir2d dc1;
124           if (!SameCenter) dc1 = gp_Dir2d(center1.XY()-pinterm.XY());
125           if (!Qualified1.IsUnqualified()) { 
126             qualifier1(NbrSol) = Qualified1.Qualifier();
127           }
128           else if (Abs(distcc1+Radius(i)-R1) < Tol) {
129             qualifier1(NbrSol) = GccEnt_enclosed;
130           }
131           else if (Abs(distcc1-R1-Radius(i)) < Tol) {
132             qualifier1(NbrSol) = GccEnt_outside;
133           }
134           else { qualifier1(NbrSol) = GccEnt_enclosing; }
135           qualifier2(NbrSol) = GccEnt_noqualifier;
136           if (!SameCenter) 
137             pnttg1sol(NbrSol) = gp_Pnt2d(pinterm.XY()+Radius(i)*dc1.XY());
138           else
139             pnttg1sol(NbrSol) = gp_Pnt2d(pinterm.XY());
140           pnttg2sol(NbrSol) = Point2;
141           pntcen(NbrSol) = cirsol(NbrSol).Location();
142           par1sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),pnttg1sol(NbrSol));
143           pararg1(NbrSol)=ElCLib::Parameter(C1,pnttg1sol(NbrSol));
144           par2sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),pnttg2sol(NbrSol));
145           pararg2(NbrSol) = 0.;
146           parcen3(NbrSol)=ElCLib::Parameter(OnCirc,pntcen(NbrSol));
147         }
148       }
149       if (WellDone) { return; }
150     }
151   }
152   
153 //=========================================================================
154 //   General case.                                                         +
155 //=========================================================================
156
157   GccAna_CircPnt2dBisec Bis(C1,Point2);
158   if (Bis.IsDone()) {
159     Standard_Integer nbsolution = Bis.NbSolutions();
160     for (Standard_Integer i = 1 ; i <=  nbsolution; i++) {
161
162       Handle(GccInt_Bisec) Sol = Bis.ThisSolution(i);
163       GccInt_IType type = Sol->ArcType();
164       IntAna2d_AnaIntersection Intp;
165       if (type == GccInt_Lin) {
166         Intp.Perform(Sol->Line(),OnCirc);
167       }
168       else if (type == GccInt_Cir) {
169         Intp.Perform(OnCirc,Sol->Circle());
170       }
171       else if (type == GccInt_Hpr) {
172         Intp.Perform(OnCirc,IntAna2d_Conic(Sol->Hyperbola()));
173       }
174       else if (type == GccInt_Ell) {
175         Intp.Perform(OnCirc,IntAna2d_Conic(Sol->Ellipse()));
176       }
177       if (Intp.IsDone()) {
178         if ((!Intp.IsEmpty())&&(!Intp.ParallelElements())&&
179             (!Intp.IdenticalElements())) {
180           for (Standard_Integer j = 1 ; j <= Intp.NbPoints() ; j++) {
181             gp_Pnt2d Center(Intp.Point(j).Value());
182             Standard_Real dist1 = center1.Distance(Center);
183             Standard_Integer nbsol = 1;
184             Standard_Boolean ok = Standard_False;
185             if (Qualified1.IsEnclosed()) {
186               if (dist1-C1.Radius() <= Tol) {
187                 ok = Standard_True;
188                 Radius(1) = Abs(C1.Radius()-dist1);
189               }
190             }
191             else if (Qualified1.IsOutside()) {
192               if (C1.Radius()-dist1 <= Tol) {
193                 ok = Standard_True;
194                 Radius(1) = Abs(C1.Radius()-dist1);
195               }
196             }
197             else if (Qualified1.IsEnclosing()) {
198               ok = Standard_True;
199               Radius(1) = C1.Radius()+dist1;
200             }
201             else if (Qualified1.IsUnqualified()) {
202               ok = Standard_True;
203               nbsol = 2;
204               Radius(1) = Abs(C1.Radius()-dist1);
205               Radius(2) = C1.Radius()+dist1;
206             }
207             if (ok) {
208               for (Standard_Integer k = 1 ; k <= nbsol ; k++) {
209                 
210                 // pop : protection against case center1 == Center
211                 if (center1.IsEqual(Center,Precision::Confusion())) {
212                   continue;
213                 }                 
214                 if (OnCirc.Distance(Center)>Tol) {
215                   continue;
216                 }
217                 if (NbrSol == 4 ) break;
218                 NbrSol++;
219                 cirsol(NbrSol) = gp_Circ2d(gp_Ax2d(Center,dirx),Radius(k));
220 //              ==========================================================
221                 Standard_Real distcc1 = Center.Distance(center1);
222                 if (!Qualified1.IsUnqualified()) { 
223                   qualifier1(NbrSol) = Qualified1.Qualifier();
224                 }
225                 else if (Abs(distcc1+Radius(k)-R1) < Tol) {
226                   qualifier1(NbrSol) = GccEnt_enclosed;
227                 }
228                 else if (Abs(distcc1-R1-Radius(k)) < Tol) {
229                   qualifier1(NbrSol) = GccEnt_outside;
230                 }
231                 else { qualifier1(NbrSol) = GccEnt_enclosing; }
232                 qualifier2(NbrSol) = GccEnt_noqualifier;
233                 if (distcc1 <= Tol && Abs(Radius(k)-C1.Radius()) <= Tol) {
234                   TheSame1(NbrSol) = 1;
235                 }
236                 else {
237                   TheSame1(NbrSol) = 0;
238                   gp_Dir2d dc1(center1.XY()-Center.XY());
239                   pnttg1sol(NbrSol) = gp_Pnt2d(Center.XY()+
240                                                Radius(k)*dc1.XY());
241                   par1sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),
242                                                     pnttg1sol(NbrSol));
243                   pararg1(NbrSol)=ElCLib::Parameter(C1,pnttg1sol(NbrSol));
244                 }
245                 TheSame2(NbrSol) = 0;
246                 pntcen(NbrSol) = Center;
247                 pnttg2sol(NbrSol) = Point2;
248                 pararg2(NbrSol) = 0.;
249                 par2sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),
250                                                   pnttg2sol(NbrSol));
251                 parcen3(NbrSol)=ElCLib::Parameter(OnCirc,pntcen(NbrSol));
252               }
253             }
254           }
255         }
256         WellDone = Standard_True;
257       }
258     }
259   }
260 }