0031668: Visualization - WebGL sample doesn't work on Emscripten 1.39
[occt.git] / src / Geom2dGcc / Geom2dGcc_Circ2dTanOnRad.cxx
1 // Created on: 1992-10-21
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 under
9 // the terms of the GNU Lesser General Public License 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 #include <GccAna_Circ2dTanOnRad.hxx>
19 #include <GccEnt_BadQualifier.hxx>
20 #include <GccEnt_QualifiedCirc.hxx>
21 #include <GccEnt_QualifiedLin.hxx>
22 #include <Geom2d_Circle.hxx>
23 #include <Geom2d_Line.hxx>
24 #include <Geom2d_Point.hxx>
25 #include <Geom2dAdaptor_Curve.hxx>
26 #include <Geom2dGcc_Circ2dTanOnRad.hxx>
27 #include <Geom2dGcc_Circ2dTanOnRadGeo.hxx>
28 #include <Geom2dGcc_QCurve.hxx>
29 #include <Geom2dGcc_QualifiedCurve.hxx>
30 #include <gp_Circ2d.hxx>
31 #include <gp_Pnt2d.hxx>
32 #include <Standard_NegativeValue.hxx>
33 #include <Standard_OutOfRange.hxx>
34 #include <StdFail_NotDone.hxx>
35
36 Geom2dGcc_Circ2dTanOnRad::
37    Geom2dGcc_Circ2dTanOnRad (const Geom2dGcc_QualifiedCurve& Qualified1 ,
38                              const Geom2dAdaptor_Curve&      OnCurve    ,
39                              const Standard_Real             Radius     ,
40                              const Standard_Real             Tolerance  ):
41   cirsol(1,8)   ,
42   qualifier1(1,8),
43   TheSame1(1,8) ,
44   pnttg1sol(1,8),
45   par1sol(1,8)  ,
46   pararg1(1,8)  ,
47   pntcen3(1,8)   ,
48   parcen3(1,8)  
49 {
50   if (Radius < 0.) {
51     throw Standard_NegativeValue();
52   }
53   else {
54     Geom2dAdaptor_Curve C1 = Qualified1.Qualified();
55     GeomAbs_CurveType Type1 = C1.GetType();
56     GeomAbs_CurveType Type2 = OnCurve.GetType();
57     Handle(Geom2d_Curve) CC1 = C1.Curve();
58     Handle(Geom2d_Curve) Con = OnCurve.Curve();
59
60 //=============================================================================
61 //                            Appel a GccAna.                                 +
62 //=============================================================================
63
64     NbrSol = 0;
65     if ((Type1 == GeomAbs_Line || Type1 == GeomAbs_Circle) &&
66         (Type2 == GeomAbs_Line || Type2 == GeomAbs_Circle)) {
67       if (Type1 == GeomAbs_Circle) {
68         Handle(Geom2d_Circle) CCC1 = Handle(Geom2d_Circle)::DownCast(CC1);
69         gp_Circ2d c1(CCC1->Circ2d());
70         GccEnt_QualifiedCirc Qc1=GccEnt_QualifiedCirc(c1,
71                                                       Qualified1.Qualifier());
72         if (Type2 == GeomAbs_Circle) {
73           Handle(Geom2d_Circle) CCon = Handle(Geom2d_Circle)::DownCast(Con);
74           gp_Circ2d con(CCon->Circ2d());
75           GccAna_Circ2dTanOnRad Circ(Qc1,con,Radius,Tolerance);
76           WellDone = Circ.IsDone();
77           NbrSol = Circ.NbSolutions();
78           Results(Circ);
79         }
80         else {
81           Handle(Geom2d_Line) LLon = Handle(Geom2d_Line)::DownCast(Con);
82           gp_Lin2d lon(LLon->Lin2d());
83           GccAna_Circ2dTanOnRad Circ(Qc1,lon,Radius,Tolerance);
84           WellDone = Circ.IsDone();
85           NbrSol = Circ.NbSolutions();
86           Results(Circ);
87         }
88       }
89       else {
90         Handle(Geom2d_Line) LL1 = Handle(Geom2d_Line)::DownCast(CC1);
91         gp_Lin2d l1(LL1->Lin2d());
92         GccEnt_QualifiedLin Ql1=GccEnt_QualifiedLin(l1,Qualified1.Qualifier());
93         if (Type2 == GeomAbs_Circle) {
94           Handle(Geom2d_Circle) CCon = Handle(Geom2d_Circle)::DownCast(Con);
95           gp_Circ2d con(CCon->Circ2d());
96           GccAna_Circ2dTanOnRad Circ(Ql1,con,Radius,Tolerance);
97           WellDone = Circ.IsDone();
98           NbrSol = Circ.NbSolutions();
99           Results(Circ);
100         }
101         else {
102           Handle(Geom2d_Line) LLon = Handle(Geom2d_Line)::DownCast(Con);
103           gp_Lin2d lon(LLon->Lin2d());
104           GccAna_Circ2dTanOnRad Circ(Ql1,lon,Radius,Tolerance);
105           WellDone = Circ.IsDone();
106           NbrSol = Circ.NbSolutions();
107           Results(Circ);
108         }
109       }
110     }
111
112 //=============================================================================
113 //                            Appel a GccGeo.                                 +
114 //=============================================================================
115
116     else {
117       if (Type1 == GeomAbs_Circle) {
118         Handle(Geom2d_Circle) CCC1 = Handle(Geom2d_Circle)::DownCast(CC1);
119         gp_Circ2d c1(CCC1->Circ2d());
120         GccEnt_QualifiedCirc Qc1=GccEnt_QualifiedCirc(c1,
121                                                       Qualified1.Qualifier());
122         Geom2dGcc_Circ2dTanOnRadGeo CircGeo(Qc1,OnCurve,Radius,Tolerance);
123         WellDone = CircGeo.IsDone();
124         NbrSol = CircGeo.NbSolutions();
125         Results(CircGeo);
126       }
127       else if (Type1 == GeomAbs_Line) {
128         Handle(Geom2d_Line) LL1 = Handle(Geom2d_Line)::DownCast(CC1);
129         gp_Lin2d l1(LL1->Lin2d());
130         GccEnt_QualifiedLin Ql1=GccEnt_QualifiedLin(l1,Qualified1.Qualifier());
131         Geom2dGcc_Circ2dTanOnRadGeo CircGeo(Ql1,OnCurve,Radius,Tolerance);
132         WellDone = CircGeo.IsDone();
133         NbrSol = CircGeo.NbSolutions();
134         Results(CircGeo);
135       }
136       else {
137         Geom2dGcc_QCurve Qc1(C1,Qualified1.Qualifier());
138         Geom2dGcc_Circ2dTanOnRadGeo CircGeo(Qc1,OnCurve,Radius,Tolerance);
139         WellDone = CircGeo.IsDone();
140         NbrSol = CircGeo.NbSolutions();
141         Results(CircGeo);
142       }
143     }
144   }
145 }
146
147 Geom2dGcc_Circ2dTanOnRad::
148    Geom2dGcc_Circ2dTanOnRad (const Handle(Geom2d_Point)&     Point1     ,
149                              const Geom2dAdaptor_Curve&     OnCurve    ,
150                              const Standard_Real             Radius     ,
151                              const Standard_Real             Tolerance  ):
152   cirsol(1,8)   ,
153   qualifier1(1,8),
154   TheSame1(1,8) ,
155   pnttg1sol(1,8),
156   par1sol(1,8)  ,
157   pararg1(1,8)  ,
158   pntcen3(1,8)   ,
159   parcen3(1,8)  
160 {
161   if (Radius < 0.) {
162     throw Standard_NegativeValue();
163   }
164   else {
165     gp_Pnt2d point1(Point1->Pnt2d());
166     GeomAbs_CurveType Type2 = OnCurve.GetType();
167     Handle(Geom2d_Curve) Con = OnCurve.Curve();
168
169 //=============================================================================
170 //                            Appel a GccAna.                                 +
171 //=============================================================================
172
173     NbrSol = 0;
174     if (Type2 == GeomAbs_Line || Type2 == GeomAbs_Circle) {
175       if (Type2 == GeomAbs_Circle) {
176         Handle(Geom2d_Circle) CCon = Handle(Geom2d_Circle)::DownCast(Con);
177         gp_Circ2d con(CCon->Circ2d());
178         GccAna_Circ2dTanOnRad Circ(point1,con,Radius,Tolerance);
179         WellDone = Circ.IsDone();
180         NbrSol = Circ.NbSolutions();
181         Results(Circ);
182       }
183       else {
184         Handle(Geom2d_Line) LLon = Handle(Geom2d_Line)::DownCast(Con);
185         gp_Lin2d lon(LLon->Lin2d());
186         GccAna_Circ2dTanOnRad Circ(point1,lon,Radius,Tolerance);
187         WellDone = Circ.IsDone();
188         NbrSol = Circ.NbSolutions();
189         Results(Circ);
190       }
191     }
192
193 //=============================================================================
194 //                            Appel a GccGeo.                                 +
195 //=============================================================================
196
197     else {
198       Geom2dGcc_Circ2dTanOnRadGeo CircGeo(point1,OnCurve,Radius,Tolerance);
199       WellDone = CircGeo.IsDone();
200       NbrSol = CircGeo.NbSolutions();
201       Results(CircGeo);
202     }
203   }
204 }
205
206 void Geom2dGcc_Circ2dTanOnRad::Results(const GccAna_Circ2dTanOnRad& Circ)
207 {
208   for (Standard_Integer j = 1; j <= NbrSol; j++) {
209     cirsol(j)   = Circ.ThisSolution(j);
210     if (Circ.IsTheSame1(j)) { TheSame1(j) = 1; }
211     else {TheSame1(j) = 0; }
212     Circ.Tangency1(j,par1sol(j),pararg1(j),pnttg1sol(j));
213     Circ.CenterOn3(j,parcen3(j),pntcen3(j));
214     Circ.WhichQualifier(j,qualifier1(j));
215   }
216 }
217
218 void Geom2dGcc_Circ2dTanOnRad::Results(const Geom2dGcc_Circ2dTanOnRadGeo& Circ)
219 {
220   for (Standard_Integer j = 1; j <= NbrSol; j++) {
221     cirsol(j)   = Circ.ThisSolution(j);
222     if (Circ.IsTheSame1(j)) { TheSame1(j) = 1; }
223     else {TheSame1(j) = 0; }
224     Circ.Tangency1(j,par1sol(j),pararg1(j),pnttg1sol(j));
225     Circ.CenterOn3(j,parcen3(j),pntcen3(j));
226     Circ.WhichQualifier(j,qualifier1(j));
227   }
228 }
229
230 Standard_Boolean Geom2dGcc_Circ2dTanOnRad::
231    IsDone () const { return WellDone; }
232
233 Standard_Integer Geom2dGcc_Circ2dTanOnRad::
234   NbSolutions () const 
235
236   return NbrSol;
237 }
238
239 gp_Circ2d Geom2dGcc_Circ2dTanOnRad::
240   ThisSolution (const Standard_Integer Index) const 
241 {
242   if (!WellDone) { throw StdFail_NotDone(); }
243   if (Index <= 0 ||Index > NbrSol) { throw Standard_OutOfRange(); }
244   return cirsol(Index);
245 }
246
247 void Geom2dGcc_Circ2dTanOnRad::
248   WhichQualifier (const Standard_Integer Index,
249                         GccEnt_Position& Qualif1) const
250 {
251   if (!WellDone) { throw StdFail_NotDone(); }
252   else if (Index <= 0 ||Index > NbrSol) { throw Standard_OutOfRange(); }
253   else { Qualif1 = qualifier1(Index); }
254 }
255
256 void Geom2dGcc_Circ2dTanOnRad::
257   Tangency1 (const Standard_Integer Index,
258                    Standard_Real&   ParSol,
259                    Standard_Real&   ParArg,
260                    gp_Pnt2d&        PntSol) const
261 {
262   if (!WellDone) { throw StdFail_NotDone(); }
263   else if (Index <= 0 ||Index > NbrSol) { throw Standard_OutOfRange(); }
264   else {
265     if (TheSame1(Index) == 0) {
266       ParSol = par1sol(Index);
267       ParArg = pararg1(Index);
268       PntSol = pnttg1sol(Index);
269     }
270     else { throw StdFail_NotDone(); }
271   }
272 }
273
274 void Geom2dGcc_Circ2dTanOnRad::
275    CenterOn3 (const Standard_Integer Index,
276               Standard_Real& ParArg,
277               gp_Pnt2d& PntSol) const
278 {
279   if (!WellDone) { throw StdFail_NotDone(); }
280   else if (Index <= 0 ||Index > NbrSol) { throw Standard_OutOfRange(); }
281   else {
282     ParArg = parcen3(Index);
283     PntSol = pntcen3(Index);
284   }
285 }
286
287 Standard_Boolean Geom2dGcc_Circ2dTanOnRad::
288    IsTheSame1 (const Standard_Integer Index) const
289 {
290   if (!WellDone) { throw StdFail_NotDone(); }
291   if (Index <= 0 ||Index > NbrSol) { throw Standard_OutOfRange(); }
292   if (TheSame1(Index) == 0) { return Standard_False; }
293   return Standard_True; 
294 }
295
296