0024510: Remove unused local variables
[occt.git] / src / GccAna / GccAna_Circ2d3Tan_5.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.
b311480e 14
7fd59977 15// init. de MinRad et MaxRad (PRO15604), JCT 09/10/98
16
17#include <GccAna_Circ2d3Tan.jxx>
18
19#include <ElCLib.hxx>
20#include <IntAna2d_AnaIntersection.hxx>
21#include <IntAna2d_IntPoint.hxx>
22#include <gp_Lin2d.hxx>
23#include <gp_Circ2d.hxx>
24#include <gp_Dir2d.hxx>
25#include <TColStd_Array1OfReal.hxx>
26#include <GccAna_CircLin2dBisec.hxx>
27#include <GccAna_LinPnt2dBisec.hxx>
28#include <GccInt_IType.hxx>
29#include <GccInt_BLine.hxx>
30#include <GccInt_BParab.hxx>
31#include <IntAna2d_Conic.hxx>
32#include <GccEnt_BadQualifier.hxx>
33
0d969553
Y
34//===========================================================================
35// Creation of a circle tangent to a circle, a straight line and a point. +
36//===========================================================================
7fd59977 37
38GccAna_Circ2d3Tan::
39 GccAna_Circ2d3Tan (const GccEnt_QualifiedCirc& Qualified1 ,
40 const GccEnt_QualifiedLin& Qualified2 ,
41 const gp_Pnt2d& Point3 ,
42 const Standard_Real Tolerance ):
43
44//=========================================================================
0d969553 45// Initialization of fields. +
7fd59977 46//=========================================================================
47
48 cirsol(1,4) ,
49 qualifier1(1,4) ,
50 qualifier2(1,4) ,
51 qualifier3(1,4) ,
52 TheSame1(1,4) ,
53 TheSame2(1,4) ,
54 TheSame3(1,4) ,
55 pnttg1sol(1,4) ,
56 pnttg2sol(1,4) ,
57 pnttg3sol(1,4) ,
58 par1sol(1,4) ,
59 par2sol(1,4) ,
60 par3sol(1,4) ,
61 pararg1(1,4) ,
62 pararg2(1,4) ,
63 pararg3(1,4)
64{
65
66 gp_Dir2d dirx(1.0,0.0);
67 Standard_Real Tol = Abs(Tolerance);
68 Standard_Real MaxRad = 1e10, MinRad = 1e-6;
69 WellDone = Standard_False;
70 NbrSol = 0;
71 if (!(Qualified1.IsEnclosed() || Qualified1.IsEnclosing() ||
72 Qualified1.IsOutside() || Qualified1.IsUnqualified()) ||
73 !(Qualified2.IsEnclosed() ||
74 Qualified2.IsOutside() || Qualified2.IsUnqualified())) {
75 GccEnt_BadQualifier::Raise();
76 return;
77 }
78
79//=========================================================================
0d969553 80// Processing. +
7fd59977 81//=========================================================================
82
83 gp_Circ2d C1(Qualified1.Qualified());
84 gp_Lin2d L2(Qualified2.Qualified());
85 Standard_Real R1 = C1.Radius();
86 gp_Pnt2d center1(C1.Location());
87 gp_Pnt2d origin2(L2.Location());
88 gp_Dir2d dir2(L2.Direction());
89 gp_Dir2d normL2(-dir2.Y(),dir2.X());
90
91 TColStd_Array1OfReal Radius(1,2);
92 GccAna_CircLin2dBisec Bis1(C1,L2);
93 GccAna_LinPnt2dBisec Bis2(L2,Point3);
94 if (Bis1.IsDone() && Bis2.IsDone()) {
95 Standard_Integer nbsolution1 = Bis1.NbSolutions();
96 for (Standard_Integer i = 1 ; i <= nbsolution1; i++) {
97 Handle(GccInt_Bisec) Sol1 = Bis1.ThisSolution(i);
98 Handle(GccInt_Bisec) Sol2 = Bis2.ThisSolution();
99 GccInt_IType typ1 = Sol1->ArcType();
100 GccInt_IType typ2 = Sol2->ArcType();
101 IntAna2d_AnaIntersection Intp;
102 if (typ1 == GccInt_Lin) {
103 if (typ2 == GccInt_Lin) {
104 Intp.Perform(Sol1->Line(),Sol2->Line());
105 }
106 else if (typ2 == GccInt_Par) {
107 Intp.Perform(Sol1->Line(),IntAna2d_Conic(Sol2->Parabola()));
108 }
109 }
110 else if (typ1 == GccInt_Par) {
111 if (typ2 == GccInt_Lin) {
112 Intp.Perform(Sol2->Line(),IntAna2d_Conic(Sol1->Parabola()));
113 }
114 else if (typ2 == GccInt_Par) {
115 Intp.Perform(Sol1->Parabola(),IntAna2d_Conic(Sol2->Parabola()));
116 }
117 }
118 if (Intp.IsDone()) {
119 if (!Intp.IsEmpty()) {
120 for (Standard_Integer j = 1 ; j <= Intp.NbPoints() ; j++) {
121 gp_Pnt2d Center(Intp.Point(j).Value());
122 Standard_Real dist1 = Center.Distance(C1.Location());
123 Standard_Real dist2 = L2.Distance(Center);
124 Standard_Real dist3 = Center.Distance(Point3);
125 Standard_Integer nbsol1 = 0;
7fd59977 126 Standard_Integer nbsol3 = 0;
127 Standard_Boolean ok = Standard_False;
128 if (Qualified1.IsEnclosed()) {
129 if (dist1-R1 < Tolerance) {
130 Radius(1) = Abs(R1-dist1);
131 nbsol1 = 1;
132 ok = Standard_True;
133 }
134 }
135 else if (Qualified1.IsOutside()) {
136 if (R1-dist1 < Tolerance) {
137 Radius(1) = Abs(R1-dist1);
138 nbsol1 = 1;
139 ok = Standard_True;
140 }
141 }
142 else if (Qualified1.IsEnclosing()) {
143 ok = Standard_True;
144 nbsol1 = 1;
145 Radius(1) = Abs(R1-dist1);
146 }
147 else if (Qualified1.IsUnqualified()) {
148 ok = Standard_True;
149 nbsol1 = 2;
150 Radius(1) = Abs(R1-dist1);
151 Radius(2) = R1+dist1;
152 }
153 if (Qualified2.IsEnclosed() && ok) {
154 if ((((L2.Location().X()-Center.X())*(-L2.Direction().Y()))+
155 ((L2.Location().Y()-Center.Y())*(L2.Direction().X())))<=0){
156 for (Standard_Integer ii = 1 ; ii <= nbsol1 ; ii++) {
157 if (Abs(dist2-Radius(ii)) < Tol) {
158 ok = Standard_True;
7fd59977 159 Radius(1) = Radius(ii);
160 }
161 }
162 }
163 }
164 else if (Qualified2.IsOutside() && ok) {
165 if ((((L2.Location().X()-Center.X())*(-L2.Direction().Y()))+
166 ((L2.Location().Y()-Center.Y())*(L2.Direction().X())))>=0){
167 for (Standard_Integer ii = 1 ; ii <= nbsol1 ; ii++) {
168 if (Abs(dist2-Radius(ii)) < Tol) {
169 ok = Standard_True;
7fd59977 170 Radius(1) = Radius(ii);
171 }
172 }
173 }
174 }
175 else if (Qualified2.IsUnqualified() && ok) {
176 for (Standard_Integer ii = 1 ; ii <= nbsol1 ; ii++) {
177 if (Abs(dist2-Radius(ii)) < Tol) {
178 ok = Standard_True;
7fd59977 179 Radius(1) = Radius(ii);
180 }
181 }
182 }
183 if (Abs(dist3-Radius(1)) <= Tol && ok) {
184 ok = Standard_True;
185 nbsol3 = 1;
186 }
187 if (ok) {
188 for (Standard_Integer k = 1 ; k <= nbsol3 ; k++) {
189 if (NbrSol==4)
190 break;
0d969553 191// pop : if the radius is too great - no creation
7fd59977 192 if (Radius(k) > MaxRad) break;
193 if (Abs(Radius(k)) < MinRad) break;
194
195 NbrSol++;
196 cirsol(NbrSol) = gp_Circ2d(gp_Ax2d(Center,dirx),Radius(k));
197// ==========================================================
198 Standard_Real distcc1 = Center.Distance(center1);
199 if (!Qualified1.IsUnqualified()) {
200 qualifier1(NbrSol) = Qualified1.Qualifier();
201 }
202 else if (Abs(distcc1+Radius(k)-R1) < Tol) {
203 qualifier1(NbrSol) = GccEnt_enclosed;
204 }
205 else if (Abs(distcc1-R1-Radius(k)) < Tol) {
206 qualifier1(NbrSol) = GccEnt_outside;
207 }
208 else { qualifier1(NbrSol) = GccEnt_enclosing; }
209 gp_Dir2d dc2(origin2.XY()-Center.XY());
210 if (!Qualified2.IsUnqualified()) {
211 qualifier2(NbrSol) = Qualified2.Qualifier();
212 }
213 else if (dc2.Dot(normL2) > 0.0) {
214 qualifier2(NbrSol) = GccEnt_outside;
215 }
216 else { qualifier2(NbrSol) = GccEnt_enclosed; }
217 qualifier3(NbrSol) = GccEnt_noqualifier;
218 if (Center.Distance(C1.Location()) <= Tolerance &&
219 Abs(Radius(k)-R1) <= Tolerance) {
220 TheSame1(NbrSol) = 1;
221 }
222 else {
223 TheSame1(NbrSol) = 0;
224// modified by NIZHNY-EAP Mon Nov 1 13:48:21 1999 ___BEGIN___
225// gp_Dir2d dc(C1.Location().XY()-Center.XY());
226 gp_Dir2d dc(Center.XY()-C1.Location().XY());
227// modified by NIZHNY-EAP Mon Nov 1 13:48:55 1999 ___END___
228 pnttg1sol(NbrSol)=gp_Pnt2d(Center.XY()+Radius(k)*dc.XY());
229 par1sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),
230 pnttg1sol(NbrSol));
231 pararg1(NbrSol)=ElCLib::Parameter(C1,pnttg1sol(NbrSol));
232 }
233 TheSame2(NbrSol) = 0;
234 TheSame3(NbrSol) = 0;
235 gp_Dir2d dc(L2.Location().XY()-Center.XY());
236 Standard_Real sign = dc.Dot(gp_Dir2d(-L2.Direction().Y(),
237 L2.Direction().X()));
238 dc = gp_Dir2d(sign*gp_XY(-L2.Direction().Y(),
239 L2.Direction().X()));
240 pnttg2sol(NbrSol) = gp_Pnt2d(Center.XY()+Radius(k)*dc.XY());
241 par2sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),
242 pnttg2sol(NbrSol));
243 pararg2(NbrSol)=ElCLib::Parameter(L2,pnttg2sol(NbrSol));
244 pnttg3sol(NbrSol) = Point3;
245 par3sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),
246 pnttg3sol(NbrSol));
247 pararg3(NbrSol) = 0.;
248 }
249 }
250 }
251 }
252 WellDone = Standard_True;
253 }
254 if (NbrSol==4)
255 break;
256 }
257 }
258 }