0024510: Remove unused local variables
[occt.git] / src / GccAna / GccAna_Circ2d3Tan_1.cxx
CommitLineData
b311480e 1// Copyright (c) 1995-1999 Matra Datavision
973c2be1 2// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 3//
973c2be1 4// This file is part of Open CASCADE Technology software library.
b311480e 5//
973c2be1 6// This library is free software; you can redistribute it and / or modify it
7// under the terms of the GNU Lesser General Public 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.
b311480e 11//
973c2be1 12// Alternatively, this file may be used under the terms of Open CASCADE
13// commercial license or contractual agreement.
7fd59977 14
15#include <GccAna_Circ2d3Tan.jxx>
16
17#include <IntAna2d_AnaIntersection.hxx>
18#include <IntAna2d_IntPoint.hxx>
19#include <ElCLib.hxx>
20#include <gp_Lin2d.hxx>
21#include <gp_Circ2d.hxx>
22#include <gp_Dir2d.hxx>
23#include <TColStd_Array1OfReal.hxx>
24#include <GccAna_CircLin2dBisec.hxx>
25#include <GccInt_IType.hxx>
26#include <GccInt_BLine.hxx>
27#include <GccInt_BParab.hxx>
28#include <IntAna2d_Conic.hxx>
29#include <TColStd_Array1OfReal.hxx>
30#include <GccEnt_BadQualifier.hxx>
31#include <Precision.hxx>
32
33//=========================================================================
0d969553 34// Creation of a circle tangent to two circles and a straight line. +
7fd59977 35//=========================================================================
36
37GccAna_Circ2d3Tan::
38 GccAna_Circ2d3Tan (const GccEnt_QualifiedCirc& Qualified1,
39 const GccEnt_QualifiedCirc& Qualified2,
40 const GccEnt_QualifiedLin& Qualified3,
41 const Standard_Real Tolerance ):
42
43//=========================================================================
0d969553 44// Initialization of fields. +
7fd59977 45//=========================================================================
46
47 cirsol(1,16) ,
48 qualifier1(1,16) ,
49 qualifier2(1,16) ,
50 qualifier3(1,16),
51 TheSame1(1,16) ,
52 TheSame2(1,16) ,
53 TheSame3(1,16) ,
54 pnttg1sol(1,16) ,
55 pnttg2sol(1,16) ,
56 pnttg3sol(1,16) ,
57 par1sol(1,16) ,
58 par2sol(1,16) ,
59 par3sol(1,16) ,
60 pararg1(1,16) ,
61 pararg2(1,16) ,
62 pararg3(1,16)
63{
64
65 gp_Dir2d dirx(1.0,0.0);
66 Standard_Real Tol = Abs(Tolerance);
67 WellDone = Standard_False;
68 NbrSol = 0;
69 if (!(Qualified1.IsEnclosed() || Qualified1.IsEnclosing() ||
70 Qualified1.IsOutside() || Qualified1.IsUnqualified()) ||
71 !(Qualified2.IsEnclosed() || Qualified2.IsEnclosing() ||
72 Qualified2.IsOutside() || Qualified2.IsUnqualified()) ||
73 !(Qualified3.IsEnclosed() ||
74 Qualified3.IsOutside() || Qualified3.IsUnqualified())) {
75 GccEnt_BadQualifier::Raise();
76 return;
77 }
78
79//=========================================================================
0d969553 80// Processing. +
7fd59977 81//=========================================================================
82
83 gp_Circ2d C1 = Qualified1.Qualified();
84 gp_Circ2d C2 = Qualified2.Qualified();
85 gp_Lin2d L3 = Qualified3.Qualified();
86 Standard_Real R1 = C1.Radius();
87 Standard_Real R2 = C2.Radius();
88 gp_Pnt2d center1(C1.Location());
89#ifdef DEB
90 gp_Pnt2d center2(C2.Location());
91#else
92 C2.Location() ;
93#endif
94 gp_Pnt2d origin3(L3.Location());
95 gp_Dir2d dir3(L3.Direction());
96 gp_Dir2d normL3(-dir3.Y(),dir3.X());
97
98 TColStd_Array1OfReal Radius(1,2);
99 GccAna_CircLin2dBisec Bis1(C1,L3);
100 GccAna_CircLin2dBisec Bis2(C2,L3);
101 if (Bis1.IsDone() && Bis2.IsDone()) {
102 Standard_Integer nbsolution1 = Bis1.NbSolutions();
103 Standard_Integer nbsolution2 = Bis2.NbSolutions();
104 for (Standard_Integer i = 1 ; i <= nbsolution1; i++) {
105 Handle(GccInt_Bisec) Sol1 = Bis1.ThisSolution(i);
106 GccInt_IType typ1 = Sol1->ArcType();
107 IntAna2d_AnaIntersection Intp;
108 for (Standard_Integer k = 1 ; k <= nbsolution2; k++) {
109 Handle(GccInt_Bisec) Sol2 = Bis2.ThisSolution(k);
110 GccInt_IType typ2 = Sol2->ArcType();
111 if (typ1 == GccInt_Lin) {
112 if (typ2 == GccInt_Lin) {
113 Intp.Perform(Sol1->Line(),Sol2->Line());
114 }
115 else if (typ2 == GccInt_Par) {
116 Intp.Perform(Sol1->Line(),IntAna2d_Conic(Sol2->Parabola()));
117 }
118 }
119 else if (typ1 == GccInt_Par) {
120 if (typ2 == GccInt_Lin) {
121 Intp.Perform(Sol2->Line(),IntAna2d_Conic(Sol1->Parabola()));
122 }
123 else if (typ2 == GccInt_Par) {
124 Intp.Perform(Sol1->Parabola(),IntAna2d_Conic(Sol2->Parabola()));
125 }
126 }
127 if (Intp.IsDone()) {
128 if (!Intp.IsEmpty()) {
129 for (Standard_Integer j = 1 ; j <= Intp.NbPoints() ; j++) {
130 Standard_Real Rradius=0;
131 gp_Pnt2d Center(Intp.Point(j).Value());
132
0d969553 133// pop : if the coordinates are too great, no creation
7fd59977 134 if (Center.X() > 1e10 ||
135 Center.Y() > 1e10 ) break;
136
137 Standard_Real dist1 = Center.Distance(C1.Location());
138 Standard_Real dist2 = Center.Distance(C2.Location());
139 Standard_Real dist3 = L3.Distance(Center);
140
0d969553 141// pop : if the coordinates are too great, no creation
7fd59977 142 if (dist3 > 1e10 ) break;
143
144 Standard_Integer nbsol1 = 0;
145 Standard_Integer nbsol2 = 0;
146 Standard_Integer nbsol3 = 0;
147 Standard_Boolean ok = Standard_False;
148 if (Qualified1.IsEnclosed()) {
149 if (dist1-R1 < Tolerance) {
150 Radius(1) = Abs(R1-dist1);
151 nbsol1 = 1;
152 ok = Standard_True;
153 }
154 }
155 else if (Qualified1.IsOutside()) {
156 if (R1-dist1 < Tolerance) {
157 Radius(1) = Abs(R1-dist1);
158 nbsol1 = 1;
159 ok = Standard_True;
160 }
161 }
162 else if (Qualified1.IsEnclosing()) {
163 ok = Standard_True;
164 nbsol1 = 1;
165 Radius(1) = Abs(R1-dist1);
166 }
167 else if (Qualified1.IsUnqualified()) {
168 ok = Standard_True;
169 nbsol1 = 2;
170 Radius(1) = Abs(R1-dist1);
171 Radius(2) = R1+dist1;
172 }
173 if (Qualified2.IsEnclosed() && ok) {
174 if (dist2-R2 < Tolerance) {
175 for (Standard_Integer ii = 1 ; ii <= nbsol1 ; ii++) {
176 if (Abs(Radius(ii)-Abs(R2-dist2)) < Tol) {
177 Radius(1) = Abs(R2-dist2);
178 ok = Standard_True;
179 nbsol2 = 1;
180 }
181 }
182 }
183 }
184 else if (Qualified2.IsOutside() && ok) {
185 if (R2-dist2 < Tolerance) {
186 for (Standard_Integer ii = 1 ; ii <= nbsol1 ; ii++) {
187 if (Abs(Radius(ii)-Abs(R2-dist2)) < Tol) {
188 Radius(1) = Abs(R2-dist2);
189 ok = Standard_True;
190 nbsol2 = 1;
191 }
192 }
193 }
194 }
195 else if (Qualified2.IsEnclosing() && ok) {
196 for (Standard_Integer ii = 1 ; ii <= nbsol1 ; ii++) {
197 if (Abs(Radius(ii)-R2-dist2) < Tol) {
198 Radius(1) = R2+dist2;
199 ok = Standard_True;
200 nbsol2 = 1;
201 }
202 }
203 }
204 else if (Qualified2.IsUnqualified() && ok) {
205 for (Standard_Integer ii = 1 ; ii <= nbsol1 ; ii++) {
206 if (Abs(Radius(ii)-Abs(R2-dist2)) < Tol) {
207 Rradius = Abs(R2-dist2);
208 ok = Standard_True;
209 nbsol2++;
210 }
211 else if (Abs(Radius(ii)-R2-dist2) < Tol) {
212 Rradius = R2+dist2;
213 ok = Standard_True;
214 nbsol2++;
215 }
216 }
217 if (nbsol2 == 1) {
218 Radius(1) = Rradius;
219 }
220 else if (nbsol2 == 2) {
221 Radius(1) = Abs(R2-dist2);
222 Radius(2) = R2+dist2;
223 }
224 }
225 if (Qualified3.IsEnclosed() && ok) {
226 if ((((L3.Location().X()-Center.X())*(-L3.Direction().Y()))+
227 ((L3.Location().Y()-Center.Y())*(L3.Direction().X())))<=0){
228 ok = Standard_True;
229 nbsol3 = 1;
230 }
231 }
232 else if (Qualified2.IsOutside() && ok) {
233 if ((((L3.Location().X()-Center.X())*(-L3.Direction().Y()))+
234 ((L3.Location().Y()-Center.Y())*(L3.Direction().X())))>=0){
235 ok = Standard_True;
236 nbsol3 = 1;
237 }
238 }
239 else if (Qualified2.IsUnqualified() && ok) {
240 ok = Standard_True;
241 nbsol3 = 1;
242 }
243 if (ok) {
244 for (Standard_Integer ind3 = 1 ; ind3 <= nbsol3 ; ind3++) {
245 NbrSol++;
246 cirsol(NbrSol) = gp_Circ2d(gp_Ax2d(Center,dirx),Radius(ind3));
247// ==========================================================
248 Standard_Real distcc1 = Center.Distance(center1);
249 if (!Qualified1.IsUnqualified()) {
250 qualifier1(NbrSol) = Qualified1.Qualifier();
251 }
252 else if (Abs(distcc1+Radius(ind3)-R1) < Tol) {
253 qualifier1(NbrSol) = GccEnt_enclosed;
254 }
255 else if (Abs(distcc1-R1-Radius(ind3)) < Tol) {
256 qualifier1(NbrSol) = GccEnt_outside;
257 }
258 else { qualifier1(NbrSol) = GccEnt_enclosing; }
259 Standard_Real distcc2 = Center.Distance(center1);
260 if (!Qualified2.IsUnqualified()) {
261 qualifier2(NbrSol) = Qualified2.Qualifier();
262 }
263 else if (Abs(distcc2+Radius(ind3)-R2) < Tol) {
264 qualifier2(NbrSol) = GccEnt_enclosed;
265 }
266 else if (Abs(distcc2-R2-Radius(ind3)) < Tol) {
267 qualifier2(NbrSol) = GccEnt_outside;
268 }
269 else { qualifier2(NbrSol) = GccEnt_enclosing; }
270 gp_Dir2d dc3(origin3.XY()-Center.XY());
271 if (!Qualified3.IsUnqualified()) {
272 qualifier3(NbrSol) = Qualified3.Qualifier();
273 }
274 else if (dc3.Dot(normL3) > 0.0) {
275 qualifier3(NbrSol) = GccEnt_outside;
276 }
277 else { qualifier3(NbrSol) = GccEnt_enclosed; }
278 if (Center.Distance(C1.Location()) <= Tolerance &&
279 Abs(Radius(ind3)-R1) <= Tolerance) {
280 TheSame1(NbrSol) = 1;
281 }
282 else {
283 TheSame1(NbrSol) = 0;
284 gp_Dir2d dc(C1.Location().XY()-Center.XY());
285 pnttg1sol(NbrSol)=gp_Pnt2d(Center.XY()+Radius(ind3)*dc.XY());
0d969553 286 // POP for protection if cirsol(NbrSol).Location == pnttg1sol(NbrSol)
7fd59977 287 if (cirsol(NbrSol).Location().IsEqual(pnttg1sol(NbrSol),Precision::Confusion()))
288 par1sol(NbrSol)=1;
289 else
290 par1sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),
291 pnttg1sol(NbrSol));
0d969553 292 // POP for protection if C1.Location == pnttg1sol(NbrSol)
7fd59977 293 if (C1.Location().IsEqual(pnttg1sol(NbrSol),Precision::Confusion()))
294 pararg1(NbrSol)=1;
295 else
296 pararg1(NbrSol)=ElCLib::Parameter(C1,pnttg1sol(NbrSol));
297 }
298 if (Center.Distance(C2.Location()) <= Tolerance &&
299 Abs(Radius(ind3)-R2) <= Tolerance) {
300 TheSame2(NbrSol) = 1;
301 }
302 else {
303 TheSame2(NbrSol) = 0;
304 gp_Dir2d dc(C2.Location().XY()-Center.XY());
305 pnttg2sol(NbrSol)=gp_Pnt2d(Center.XY()+Radius(ind3)*dc.XY());
0d969553 306 // POP for protection if cirsol(NbrSol).Location == pnttg1sol(NbrSol)
7fd59977 307 if (cirsol(NbrSol).Location().IsEqual(pnttg1sol(NbrSol),Precision::Confusion()))
308 par1sol(NbrSol)=1;
309 else
310 par2sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),
311 pnttg2sol(NbrSol));
0d969553 312 // POP for protection if C2.Location == pnttg2sol(NbrSol)
7fd59977 313 if (C2.Location().IsEqual(pnttg2sol(NbrSol),Precision::Confusion()))
314 pararg2(NbrSol)=1;
315 else
316 pararg2(NbrSol)=ElCLib::Parameter(C2,pnttg2sol(NbrSol));
317 }
318 TheSame3(NbrSol) = 0;
319 gp_Dir2d dc(L3.Location().XY()-Center.XY());
320 Standard_Real sign = dc.Dot(gp_Dir2d(-L3.Direction().Y(),
321 L3.Direction().X()));
322 dc = gp_Dir2d(sign*gp_XY(-L3.Direction().Y(),
323 L3.Direction().X()));
324 pnttg3sol(NbrSol) = gp_Pnt2d(Center.XY()+Radius(ind3)*dc.XY());
325 par3sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),
326 pnttg3sol(NbrSol));
327 pararg3(NbrSol)=ElCLib::Parameter(L3,pnttg3sol(NbrSol));
328 }
329 }
330 }
331 }
332 WellDone = Standard_True;
333 }
334 }
335 }
336 }
337}