0031682: Visualization - Prs3d_ShadingAspect::SetTransparency() has no effect with...
[occt.git] / src / GccAna / GccAna_Circ2d2TanOn_7.cxx
CommitLineData
b311480e 1// Created on: 1992-01-02
2// Created by: Remi GILET
3// Copyright (c) 1992-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
7fd59977 17
18#include <ElCLib.hxx>
42cf5bc1 19#include <GccAna_Circ2d2TanOn.hxx>
7fd59977 20#include <GccAna_CircLin2dBisec.hxx>
42cf5bc1 21#include <GccEnt_BadQualifier.hxx>
22#include <GccEnt_QualifiedCirc.hxx>
23#include <GccEnt_QualifiedLin.hxx>
7fd59977 24#include <GccInt_BCirc.hxx>
42cf5bc1 25#include <GccInt_IType.hxx>
26#include <gp_Ax2d.hxx>
27#include <gp_Circ2d.hxx>
28#include <gp_Dir2d.hxx>
29#include <gp_Lin2d.hxx>
30#include <gp_Pnt2d.hxx>
31#include <IntAna2d_AnaIntersection.hxx>
7fd59977 32#include <IntAna2d_Conic.hxx>
42cf5bc1 33#include <IntAna2d_IntPoint.hxx>
34#include <Standard_OutOfRange.hxx>
35#include <StdFail_NotDone.hxx>
7fd59977 36#include <TColStd_Array1OfReal.hxx>
7fd59977 37
38GccAna_Circ2d2TanOn::
39 GccAna_Circ2d2TanOn (const GccEnt_QualifiedCirc& Qualified1 ,
40 const GccEnt_QualifiedLin& Qualified2 ,
41 const gp_Circ2d& OnCirc ,
42 const Standard_Real Tolerance ):
43 cirsol(1,4) ,
44 qualifier1(1,4) ,
45 qualifier2(1,4),
46 TheSame1(1,4) ,
47 TheSame2(1,4) ,
48 pnttg1sol(1,4) ,
49 pnttg2sol(1,4) ,
50 pntcen(1,4) ,
51 par1sol(1,4) ,
52 par2sol(1,4) ,
53 pararg1(1,4) ,
54 pararg2(1,4) ,
55 parcen3(1,4)
56{
57 TheSame1.Init(0);
58 TheSame2.Init(0);
59 WellDone = Standard_False;
60 NbrSol = 0;
61 if (!(Qualified1.IsEnclosed() || Qualified1.IsEnclosing() ||
62 Qualified1.IsOutside() || Qualified1.IsUnqualified()) ||
63 !(Qualified2.IsEnclosed() ||
64 Qualified2.IsOutside() || Qualified2.IsUnqualified())) {
9775fa61 65 throw GccEnt_BadQualifier();
7fd59977 66 return;
67 }
68 Standard_Real Radius=0;
69 gp_Dir2d dirx(1.,0.);
70 gp_Circ2d C1 = Qualified1.Qualified();
71 gp_Lin2d L2 = Qualified2.Qualified();
72 Standard_Real R1 = C1.Radius();
73 gp_Pnt2d center1(C1.Location());
74 gp_Pnt2d origin2(L2.Location());
75 gp_Dir2d dirL2(L2.Direction());
76 gp_Dir2d normL2(-dirL2.Y(),dirL2.X());
77
78//=========================================================================
0d969553 79// Processing of boundary cases. +
7fd59977 80//=========================================================================
81
82 Standard_Real Tol = Abs(Tolerance);
83 TColStd_Array1OfReal Rradius(1,2);
84 Standard_Integer nbsol1 = 1;
85// Standard_Integer nbsol2 = 0;
86 Standard_Real Ron = OnCirc.Radius();
87 Standard_Real distcco = OnCirc.Location().Distance(center1);
88 gp_Dir2d dircc(OnCirc.Location().XY()-center1.XY());
89 gp_Pnt2d pinterm(center1.XY()+(distcco-Ron)*dircc.XY());
90 Standard_Real distpl2 =L2.Distance(pinterm);
91 Standard_Real distcc1 =pinterm.Distance(center1);
92 Standard_Real d1 = Abs(distpl2-Abs(distcc1-R1));
93 Standard_Real d2 = Abs(distpl2-(distcc1+R1));
94 if ( d1 > Tol || d2 > Tol ) {
95 pinterm = gp_Pnt2d(center1.XY()+(distcco-Ron)*dircc.XY());
96 if ( d1 > Tol || d2 > Tol ) {
97 nbsol1 = 0;
98 }
99 }
100 if (nbsol1 > 0) {
101 if (Qualified1.IsEnclosed() || Qualified1.IsOutside()) {
102 nbsol1 = 1;
103 Rradius(1) = Abs(distcc1-R1);
104 }
105 else if (Qualified1.IsEnclosing()) {
106 nbsol1 = 1;
107 Rradius(1) = R1+distcc1;
108 }
109 else if (Qualified1.IsUnqualified()) {
110 nbsol1 = 2;
111 Rradius(1) = Abs(distcc1-R1);
112 Rradius(2) = R1+distcc1;
113 }
114 gp_Dir2d dirbid(origin2.XY()-pinterm.XY());
115 gp_Dir2d normal(-dirL2.Y(),dirL2.X());
116 if (Qualified1.IsEnclosed() && dirbid.Dot(normal) < 0.) {
117 nbsol1 = 0;
118 }
119 else if (Qualified1.IsOutside() && dirbid.Dot(normal) < 0.) {
120 nbsol1 = 0;
121 }
122 for (Standard_Integer i = 1 ; i <= nbsol1 ; i++) {
123 if (Abs(Rradius(i)-distpl2) <= Tol) {
124 WellDone = Standard_True;
125 NbrSol++;
126 cirsol(NbrSol) = gp_Circ2d(gp_Ax2d(pinterm,dirx),Rradius(i));
127// ===========================================================
128 gp_Dir2d dc1(center1.XY()-pinterm.XY());
129 gp_Dir2d dc2(origin2.XY()-pinterm.XY());
130 distcc1 = pinterm.Distance(center1);
131 if (!Qualified1.IsUnqualified()) {
132 qualifier1(NbrSol) = Qualified1.Qualifier();
133 }
134 else if (Abs(distcc1+Rradius(i)-R1) < Tol) {
135 qualifier1(NbrSol) = GccEnt_enclosed;
136 }
137 else if (Abs(distcc1-R1-Rradius(i)) < Tol) {
138 qualifier1(NbrSol) = GccEnt_outside;
139 }
140 else { qualifier1(NbrSol) = GccEnt_enclosing; }
141 if (!Qualified2.IsUnqualified()) {
142 qualifier2(NbrSol) = Qualified2.Qualifier();
143 }
144 else if (dc2.Dot(normL2) > 0.0) {
145 qualifier2(NbrSol) = GccEnt_outside;
146 }
147 else { qualifier2(NbrSol) = GccEnt_enclosed; }
148
149 Standard_Real sign = dc2.Dot(gp_Dir2d(-dirL2.Y(),dirL2.X()));
150 dc2 = gp_Dir2d(sign*gp_XY(-dirL2.Y(),dirL2.X()));
151 pnttg1sol(NbrSol) = gp_Pnt2d(pinterm.XY()+Rradius(i)*dc1.XY());
152 pnttg2sol(NbrSol) = gp_Pnt2d(pinterm.XY()+Rradius(i)*dc2.XY());
153 par1sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),pnttg1sol(NbrSol));
154 pararg1(NbrSol)=ElCLib::Parameter(C1,pnttg1sol(NbrSol));
155 par2sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),pnttg2sol(NbrSol));
156 pararg2(NbrSol)=ElCLib::Parameter(L2,pnttg2sol(NbrSol));
157 parcen3(NbrSol)=ElCLib::Parameter(OnCirc,pntcen(NbrSol));
158 }
159 }
160 if (WellDone) { return; }
161 }
162
163//=========================================================================
0d969553 164// General case. +
7fd59977 165//=========================================================================
166
167 GccAna_CircLin2dBisec Bis(C1,L2);
168 if (Bis.IsDone()) {
169 Standard_Integer nbsolution = Bis.NbSolutions();
170 for (Standard_Integer i = 1 ; i <= nbsolution; i++) {
171 Handle(GccInt_Bisec) Sol = Bis.ThisSolution(i);
172 GccInt_IType type = Sol->ArcType();
173 IntAna2d_AnaIntersection Intp;
174 if (type == GccInt_Lin) {
175 Intp.Perform(Sol->Line(),OnCirc);
176 }
177 else if (type == GccInt_Par) {
178 Intp.Perform(OnCirc,IntAna2d_Conic(Sol->Parabola()));
179 }
180 if (Intp.IsDone()) {
181 if ((!Intp.IsEmpty())&&(!Intp.ParallelElements())&&
182 (!Intp.IdenticalElements())) {
183 for (Standard_Integer j = 1 ; j <= Intp.NbPoints() ; j++) {
184 gp_Pnt2d Center(Intp.Point(j).Value());
185 Standard_Real dist1 = Center.Distance(center1);
186 Standard_Real dist2 = L2.Distance(Center);
187// Standard_Integer nbsol = 1;
188 Standard_Boolean ok = Standard_False;
189 if (Qualified1.IsEnclosed()) {
190 if (dist1-R1 < Tolerance) {
191 if (Abs(Abs(R1-dist1)-dist2)<Tolerance) { ok=Standard_True; }
192 }
193 }
194 else if (Qualified1.IsOutside()) {
195 if (R1-dist1 < Tolerance) {
196 if (Abs(Abs(R1-dist1)-dist2)<Tolerance) { ok=Standard_True; }
197 }
198 }
199 else if (Qualified1.IsEnclosing() || Qualified1.IsUnqualified()) {
200 ok = Standard_True;
201 }
202 if (Qualified2.IsEnclosed() && ok) {
203 if ((((origin2.X()-Center.X())*(-dirL2.Y()))+
204 ((origin2.Y()-Center.Y())*(dirL2.X())))<=0){
205 ok = Standard_True;
206 Radius = dist2;
207 }
208 }
209 else if (Qualified2.IsOutside() && ok) {
210 if ((((origin2.X()-Center.X())*(-dirL2.Y()))+
211 ((origin2.Y()-Center.Y())*(dirL2.X())))>=0){
212 ok = Standard_True;
213 Radius = dist2;
214 }
215 }
216 else if (Qualified2.IsUnqualified() && ok) {
217 ok = Standard_True;
218 Radius = dist2;
219 }
220 if (ok) {
221 NbrSol++;
222 cirsol(NbrSol) = gp_Circ2d(gp_Ax2d(Center,dirx),Radius);
223// =======================================================
224 gp_Dir2d dc2(origin2.XY()-Center.XY());
225 distcc1 = Center.Distance(center1);
226 if (!Qualified1.IsUnqualified()) {
227 qualifier1(NbrSol) = Qualified1.Qualifier();
228 }
229 else if (Abs(distcc1+Radius-R1) < Tol) {
230 qualifier1(NbrSol) = GccEnt_enclosed;
231 }
232 else if (Abs(distcc1-R1-Radius) < Tol) {
233 qualifier1(NbrSol) = GccEnt_outside;
234 }
235 else { qualifier1(NbrSol) = GccEnt_enclosing; }
236 if (!Qualified2.IsUnqualified()) {
237 qualifier2(NbrSol) = Qualified2.Qualifier();
238 }
239 else if (dc2.Dot(normL2) > 0.0) {
240 qualifier2(NbrSol) = GccEnt_outside;
241 }
242 else { qualifier2(NbrSol) = GccEnt_enclosed; }
243 if (Center.Distance(center1) <= Tolerance &&
244 Abs(Radius-C1.Radius()) <= Tolerance) {
245 TheSame1(NbrSol) = 1;
246 }
247 else {
248 TheSame1(NbrSol) = 0;
249 gp_Dir2d dc1(center1.XY()-Center.XY());
250 pnttg1sol(NbrSol) = gp_Pnt2d(Center.XY()+Radius*dc1.XY());
251 par1sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),
252 pnttg1sol(NbrSol));
253 pararg1(NbrSol)=ElCLib::Parameter(C1,pnttg1sol(NbrSol));
254 }
255 TheSame2(NbrSol) = 0;
256 Standard_Real sign = dc2.Dot(gp_Dir2d(normL2.XY()));
257 dc2 = gp_Dir2d(sign*gp_XY(normL2.XY()));
258 pnttg2sol(NbrSol) = gp_Pnt2d(Center.XY()+Radius*dc2.XY());
259 par2sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),
260 pnttg2sol(NbrSol));
261 pararg2(NbrSol)=ElCLib::Parameter(L2,pnttg2sol(NbrSol));
262 pntcen(NbrSol) = Center;
263 parcen3(NbrSol)=ElCLib::Parameter(OnCirc,pntcen(NbrSol));
264 }
265 }
266 }
267 WellDone = Standard_True;
268 }
269 }
270 }
271}
272