0031668: Visualization - WebGL sample doesn't work on Emscripten 1.39
[occt.git] / src / GccAna / GccAna_Circ2d3Tan_2.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//
d5f74e42 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
973c2be1 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
7fd59977 15
7fd59977 16#include <ElCLib.hxx>
42cf5bc1 17#include <GccAna_Circ2d3Tan.hxx>
7fd59977 18#include <GccAna_CircLin2dBisec.hxx>
19#include <GccAna_Lin2dBisec.hxx>
42cf5bc1 20#include <GccEnt_BadQualifier.hxx>
21#include <GccEnt_QualifiedCirc.hxx>
22#include <GccEnt_QualifiedLin.hxx>
7fd59977 23#include <GccInt_BLine.hxx>
24#include <GccInt_BParab.hxx>
42cf5bc1 25#include <GccInt_IType.hxx>
26#include <gp_Circ2d.hxx>
27#include <gp_Dir2d.hxx>
28#include <gp_Lin2d.hxx>
29#include <gp_Pnt2d.hxx>
30#include <IntAna2d_AnaIntersection.hxx>
7fd59977 31#include <IntAna2d_Conic.hxx>
42cf5bc1 32#include <IntAna2d_IntPoint.hxx>
33#include <Standard_OutOfRange.hxx>
34#include <StdFail_NotDone.hxx>
35#include <TColStd_Array1OfReal.hxx>
7fd59977 36
37//=========================================================================
0d969553 38// Creation of a circle tangent to a circle and two straight lines. +
7fd59977 39//=========================================================================
7fd59977 40GccAna_Circ2d3Tan::GccAna_Circ2d3Tan (const GccEnt_QualifiedCirc& Qualified1 ,
41 const GccEnt_QualifiedLin& Qualified2 ,
42 const GccEnt_QualifiedLin& Qualified3 ,
43 const Standard_Real Tolerance )
44
45//=========================================================================
0d969553 46// Initialisation of fields. +
7fd59977 47//=========================================================================
48
49:cirsol(1,8) ,
50qualifier1(1,8) ,
51qualifier2(1,8) ,
52qualifier3(1,8) ,
53TheSame1(1,8) ,
54TheSame2(1,8) ,
55TheSame3(1,8) ,
56pnttg1sol(1,8) ,
57pnttg2sol(1,8) ,
58pnttg3sol(1,8) ,
59par1sol(1,8) ,
60par2sol(1,8) ,
61par3sol(1,8) ,
62pararg1(1,8) ,
63pararg2(1,8) ,
64pararg3(1,8)
65{
66
67 TheSame1.Init(0);
68
69 gp_Dir2d dirx(1.0,0.0);
70 Standard_Real Tol = Abs(Tolerance);
71 WellDone = Standard_False;
72 NbrSol = 0;
73 if (!(Qualified1.IsEnclosed() || Qualified1.IsEnclosing() ||
74 Qualified1.IsOutside() || Qualified1.IsUnqualified()) ||
75 !(Qualified2.IsEnclosed() ||
76 Qualified2.IsOutside() || Qualified2.IsUnqualified()) ||
77 !(Qualified3.IsEnclosed() ||
78 Qualified3.IsOutside() || Qualified3.IsUnqualified())) {
9775fa61 79 throw GccEnt_BadQualifier();
7fd59977 80 return;
81 }
82
83//=========================================================================
0d969553 84// Processing. +
7fd59977 85//=========================================================================
86
87 gp_Circ2d C1 = Qualified1.Qualified();
88 gp_Lin2d L2 = Qualified2.Qualified();
89 gp_Lin2d L3 = Qualified3.Qualified();
90 Standard_Real R1 = C1.Radius();
91 gp_Pnt2d center1(C1.Location());
92 gp_Pnt2d origin2(L2.Location());
93 gp_Dir2d dir2(L2.Direction());
94 gp_Dir2d normL2(-dir2.Y(),dir2.X());
95 gp_Pnt2d origin3(L3.Location());
96 gp_Dir2d dir3(L3.Direction());
97 gp_Dir2d normL3(-dir3.Y(),dir3.X());
98
99 TColStd_Array1OfReal Radius(1,2);
100 GccAna_CircLin2dBisec Bis1(C1,L2);
101 GccAna_Lin2dBisec Bis2(L2,L3);
102 if (Bis1.IsDone() && Bis2.IsDone()) {
103 Standard_Integer nbsolution1 = Bis1.NbSolutions();
104 Standard_Integer nbsolution2 = Bis2.NbSolutions();
105 for (Standard_Integer i = 1 ; i <= nbsolution1; i++) {
106 Handle(GccInt_Bisec) Sol1 = Bis1.ThisSolution(i);
107 GccInt_IType typ1 = Sol1->ArcType();
108 IntAna2d_AnaIntersection Intp;
109 for (Standard_Integer k = 1 ; k <= nbsolution2; k++) {
110 if (typ1 == GccInt_Lin) {
111 Intp.Perform(Sol1->Line(),Bis2.ThisSolution(k));
112 }
113 else if (typ1 == GccInt_Par) {
114 Intp.Perform(Bis2.ThisSolution(k),IntAna2d_Conic(Sol1->Parabola()));
115 }
116 if (Intp.IsDone()) {
117 if ((!Intp.IsEmpty())&&(!Intp.ParallelElements())&&
118 (!Intp.IdenticalElements())) {
119 for (Standard_Integer j = 1 ; j <= Intp.NbPoints() ; j++) {
120 gp_Pnt2d Center(Intp.Point(j).Value());
121 Standard_Real dist1 = Center.Distance(center1);
122 Standard_Real dist2 = L2.Distance(Center);
123 Standard_Real dist3 = L3.Distance(Center);
124 Standard_Integer nbsol1 = 0;
7fd59977 125 Standard_Integer nbsol3 = 0;
126 Standard_Boolean ok = Standard_False;
127 if (Qualified1.IsEnclosed()) {
128 if (dist1-R1 < Tolerance) {
129 Radius(1) = Abs(R1-dist1);
130 nbsol1 = 1;
131 ok = Standard_True;
132 }
133 }
134 else if (Qualified1.IsOutside()) {
135 if (R1-dist1 < Tolerance) {
136 Radius(1) = Abs(R1-dist1);
137 nbsol1 = 1;
138 ok = Standard_True;
139 }
140 }
141 else if (Qualified1.IsEnclosing()) {
142 ok = Standard_True;
143 nbsol1 = 1;
144 Radius(1) = Abs(R1-dist1);
145 }
146 else if (Qualified1.IsUnqualified()) {
147 ok = Standard_True;
148 nbsol1 = 2;
149 Radius(1) = Abs(R1-dist1);
150 Radius(2) = R1+dist1;
151 }
152 if (Qualified2.IsEnclosed() && ok) {
153 if ((((origin2.X()-Center.X())*(-dir2.Y()))+
154 ((origin2.Y()-Center.Y())*(dir2.X())))<=0){
155 for (Standard_Integer ii = 1 ; ii <= nbsol1 ; ii++) {
156 if (Abs(dist2-Radius(ii)) < Tol) {
157 ok = Standard_True;
7fd59977 158 Radius(1) = Radius(ii);
159 }
160 }
161 }
162 }
163 else if (Qualified2.IsOutside() && ok) {
164 if ((((origin2.X()-Center.X())*(-dir2.Y()))+
165 ((origin2.Y()-Center.Y())*(dir2.X())))>=0){
166 for (Standard_Integer ii = 1 ; ii <= nbsol1 ; ii++) {
167 if (Abs(dist2-Radius(ii)) < Tol) {
168 ok = Standard_True;
7fd59977 169 Radius(1) = Radius(ii);
170 }
171 }
172 }
173 }
174 else if (Qualified2.IsUnqualified() && ok) {
175 for (Standard_Integer ii = 1 ; ii <= nbsol1 ; ii++) {
176 if (Abs(dist2-Radius(ii)) < Tol) {
177 ok = Standard_True;
7fd59977 178 Radius(1) = Radius(ii);
179 }
180 }
181 }
182 if (Qualified3.IsEnclosed() && ok) {
183 if ((((origin3.X()-Center.X())*(-dir3.Y()))+
184 ((origin3.Y()-Center.Y())*(dir3.X())))<=0){
185 if (Abs(dist3-Radius(1)) < Tol) {
186 ok = Standard_True;
187 nbsol3 = 1;
188 }
189 }
190 }
191 else if (Qualified3.IsOutside() && ok) {
192 if ((((origin3.X()-Center.X())*(-dir3.Y()))+
193 ((origin3.Y()-Center.Y())*(dir3.X())))>=0){
194 if (Abs(dist3-Radius(1)) < Tol) {
195 ok = Standard_True;
196 nbsol3 = 1;
197 }
198 }
199 }
200 else if (Qualified3.IsUnqualified() && ok) {
201 if (Abs(dist3-Radius(1)) < Tol) {
202 ok = Standard_True;
203 nbsol3 = 1;
204 }
205 }
206 if (ok) {
3d8539a3 207 for (Standard_Integer m = 1 ; m <= nbsol3 ; m++) {
7fd59977 208 NbrSol++;
3d8539a3 209 cirsol(NbrSol) = gp_Circ2d(gp_Ax2d(Center,dirx),Radius(m));
7fd59977 210// ==========================================================
211 Standard_Real distcc1 = Center.Distance(center1);
212 if (!Qualified1.IsUnqualified()) {
213 qualifier1(NbrSol) = Qualified1.Qualifier();
214 }
3d8539a3 215 else if (Abs(distcc1+Radius(m)-R1) < Tol) {
7fd59977 216 qualifier1(NbrSol) = GccEnt_enclosed;
217 }
3d8539a3 218 else if (Abs(distcc1-R1-Radius(m)) < Tol) {
7fd59977 219 qualifier1(NbrSol) = GccEnt_outside;
220 }
221 else { qualifier1(NbrSol) = GccEnt_enclosing; }
222 gp_Dir2d dc2(origin2.XY()-Center.XY());
223 if (!Qualified2.IsUnqualified()) {
224 qualifier2(NbrSol) = Qualified2.Qualifier();
225 }
226 else if (dc2.Dot(normL2) > 0.0) {
227 qualifier2(NbrSol) = GccEnt_outside;
228 }
229 else { qualifier2(NbrSol) = GccEnt_enclosed; }
230 gp_Dir2d dc3(origin3.XY()-Center.XY());
231 if (!Qualified3.IsUnqualified()) {
232 qualifier3(NbrSol) = Qualified3.Qualifier();
233 }
234 else if (dc3.Dot(normL3) > 0.0) {
235 qualifier3(NbrSol) = GccEnt_outside;
236 }
237 else { qualifier3(NbrSol) = GccEnt_enclosed; }
238 if (Center.Distance(center1) <= Tolerance &&
3d8539a3 239 Abs(Radius(m)-R1) <= Tolerance) {
7fd59977 240 TheSame1(NbrSol) = 1;
241 }
242 else {
243 TheSame1(NbrSol) = 0;
244 gp_Dir2d dc(center1.XY()-Center.XY());
3d8539a3 245 pnttg1sol(NbrSol)=gp_Pnt2d(Center.XY()+Radius(m)*dc.XY());
7fd59977 246 par1sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),
247 pnttg1sol(NbrSol));
248 pararg1(NbrSol)=ElCLib::Parameter(C1,pnttg1sol(NbrSol));
249 }
250 TheSame2(NbrSol) = 0;
251 TheSame3(NbrSol) = 0;
252 gp_Dir2d dc(origin2.XY()-Center.XY());
253 Standard_Real sign = dc.Dot(gp_Dir2d(-dir2.Y(),dir2.X()));
254 dc = gp_Dir2d(sign*gp_XY(-dir2.Y(),dir2.X()));
3d8539a3 255 pnttg2sol(NbrSol) = gp_Pnt2d(Center.XY()+Radius(m)*dc.XY());
7fd59977 256 par2sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),
257 pnttg2sol(NbrSol));
258 pararg2(NbrSol)=ElCLib::Parameter(L2,pnttg2sol(NbrSol));
259 dc = gp_Dir2d(origin3.XY()-Center.XY());
260 sign = dc.Dot(gp_Dir2d(-dir3.Y(),dir3.X()));
261 dc = gp_Dir2d(sign*gp_XY(-dir3.Y(),dir3.X()));
3d8539a3 262 pnttg3sol(NbrSol) = gp_Pnt2d(Center.XY()+Radius(m)*dc.XY());
7fd59977 263 par3sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),
264 pnttg3sol(NbrSol));
265 pararg3(NbrSol)=ElCLib::Parameter(L3,pnttg3sol(NbrSol));
266 }
267 }
268 }
269 }
270 WellDone = Standard_True;
271 }
272 }
273 }
274 }
275 }
276
277