0028956: Coding Rules - eliminate several trivial compiler warnings
[occt.git] / src / GccAna / GccAna_Circ2d3Tan_6.cxx
1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
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
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.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
15
16 #include <ElCLib.hxx>
17 #include <GccAna_Circ2d3Tan.hxx>
18 #include <GccAna_Lin2dBisec.hxx>
19 #include <GccAna_LinPnt2dBisec.hxx>
20 #include <GccEnt_BadQualifier.hxx>
21 #include <GccEnt_QualifiedCirc.hxx>
22 #include <GccEnt_QualifiedLin.hxx>
23 #include <GccInt_BLine.hxx>
24 #include <GccInt_BParab.hxx>
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>
31 #include <IntAna2d_Conic.hxx>
32 #include <IntAna2d_IntPoint.hxx>
33 #include <Standard_OutOfRange.hxx>
34 #include <StdFail_NotDone.hxx>
35
36 //=========================================================================
37 //   Creation of a circle tangent to two straight lines and a point.      +
38 //=========================================================================
39 GccAna_Circ2d3Tan::
40    GccAna_Circ2d3Tan (const GccEnt_QualifiedLin&  Qualified1 ,
41                       const GccEnt_QualifiedLin&  Qualified2 ,
42                       const gp_Pnt2d&             Point3     ,
43                       const Standard_Real         Tolerance  ):
44
45    cirsol(1,2)     ,
46    qualifier1(1,2) ,
47    qualifier2(1,2) ,
48    qualifier3(1,2) ,
49    TheSame1(1,2)   ,
50    TheSame2(1,2)   ,
51    TheSame3(1,2)   ,
52    pnttg1sol(1,2)  ,
53    pnttg2sol(1,2)  ,
54    pnttg3sol(1,2)  ,
55    par1sol(1,2)    ,  
56    par2sol(1,2)    ,
57    par3sol(1,2)    ,
58    pararg1(1,2)    ,
59    pararg2(1,2)    ,
60    pararg3(1,2)    
61 {
62
63    gp_Dir2d dirx(1.0,0.0);
64    WellDone = Standard_False;
65    Standard_Real Tol = Abs(Tolerance);
66    NbrSol = 0;
67    if (!(Qualified1.IsEnclosed() ||
68          Qualified1.IsOutside() || Qualified1.IsUnqualified()) ||
69        !(Qualified2.IsEnclosed() ||
70          Qualified2.IsOutside() || Qualified2.IsUnqualified())) {
71      throw GccEnt_BadQualifier();
72      return;
73    }
74
75    pnttg3sol.Init(Point3);
76
77 //=========================================================================
78 //   Processing.                                                          +
79 //=========================================================================
80
81    gp_Lin2d L1  = Qualified1.Qualified();
82    gp_Lin2d L2  = Qualified2.Qualified();
83    gp_Pnt2d origin1(L1.Location());
84    gp_Dir2d dir1(L1.Direction());
85    gp_Dir2d normL1(-dir1.Y(),dir1.X());
86    gp_Pnt2d origin2(L2.Location());
87    gp_Dir2d dir2(L2.Direction());
88    gp_Dir2d normL2(-dir2.Y(),dir2.X());
89
90    GccAna_Lin2dBisec Bis1(L1,L2);
91    GccAna_LinPnt2dBisec Bis2(L1,Point3);
92    if (Bis1.IsDone() && Bis2.IsDone()) {
93      Standard_Integer nbsolution1 = Bis1.NbSolutions();
94      Handle(GccInt_Bisec) Sol2 = Bis2.ThisSolution();
95      for (Standard_Integer i = 1 ; i <=  nbsolution1; i++) {
96        const gp_Lin2d Sol1(Bis1.ThisSolution(i));
97        GccInt_IType typ2 = Sol2->ArcType();
98        IntAna2d_AnaIntersection Intp;
99        if (typ2 == GccInt_Lin) {
100          Intp.Perform(Sol1,Sol2->Line());
101        }
102        else if (typ2 == GccInt_Par) {
103          Intp.Perform(Sol1,IntAna2d_Conic(Sol2->Parabola()));
104        }
105        if (Intp.IsDone()) {
106          if (!Intp.IsEmpty()) {
107            for (Standard_Integer j = 1 ; j <= Intp.NbPoints() ; j++) {
108              gp_Pnt2d Center(Intp.Point(j).Value());
109              Standard_Real dist1 = L1.Distance(Center);
110              Standard_Real dist2 = L2.Distance(Center);
111              Standard_Real dist3 = Center.Distance(Point3);
112              Standard_Real Radius=0;
113              Standard_Integer nbsol3 = 0;
114              Standard_Boolean ok = Standard_False;
115              if (Qualified1.IsEnclosed()) {
116                if ((((origin1.X()-Center.X())*(-dir1.Y()))+
117                     ((origin1.Y()-Center.Y())*(dir1.X())))<=0){
118                  ok = Standard_True;
119                  Radius = dist1;
120                }
121              }
122              else if (Qualified1.IsOutside()) {
123                if ((((origin1.X()-Center.X())*(-dir1.Y()))+
124                     ((origin1.Y()-Center.Y())*(dir1.X())))>=0){
125                  ok = Standard_True;
126                  Radius = dist1;
127                }
128              }
129              else if (Qualified1.IsUnqualified()) {
130                ok = Standard_True;
131                Radius = dist1;
132              }
133              if (Qualified2.IsEnclosed()) {
134                if ((((origin2.X()-Center.X())*(-dir2.Y()))+
135                     ((origin2.Y()-Center.Y())*(dir2.X())))<=0){
136                  if (Abs(dist2-Radius) < Tol) { }
137                  else { ok = Standard_False; }
138                }
139              }
140              else if (Qualified2.IsOutside() && ok) {
141                if ((((origin2.X()-Center.X())*(-dir2.Y()))+
142                     ((origin2.Y()-Center.Y())*(dir2.X())))>=0){
143                  if (Abs(dist2-Radius) < Tol) { }
144                  else { ok = Standard_False; }
145                }
146              }
147              else if (Qualified2.IsUnqualified() && ok) {
148                if (Abs(dist2-Radius) < Tol) { }
149                else { ok = Standard_False; }
150              }
151              if (ok) {
152                if (Abs(dist3-Radius) < Tol) { nbsol3 = 1; }
153                else { ok = Standard_False; }
154              }
155              if (ok) {
156                for (Standard_Integer k = 1 ; k <= nbsol3 ; k++) {
157                  NbrSol++;
158                  cirsol(NbrSol) = gp_Circ2d(gp_Ax2d(Center,dirx),Radius);
159 //               =======================================================
160                  gp_Dir2d dc1(origin1.XY()-Center.XY());
161                  if (!Qualified1.IsUnqualified()) { 
162                    qualifier1(NbrSol) = Qualified1.Qualifier();
163                  }
164                  else if (dc1.Dot(normL1) > 0.0) {
165                    qualifier1(NbrSol) = GccEnt_outside;
166                  }
167                  else { qualifier1(NbrSol) = GccEnt_enclosed; }
168                  gp_Dir2d dc2(origin2.XY()-Center.XY());
169                  if (!Qualified2.IsUnqualified()) { 
170                    qualifier2(NbrSol) = Qualified2.Qualifier();
171                  }
172                  else if (dc2.Dot(normL2) > 0.0) {
173                    qualifier2(NbrSol) = GccEnt_outside;
174                  }
175                  else { qualifier2(NbrSol) = GccEnt_enclosed; }
176                  qualifier3(NbrSol) = GccEnt_noqualifier;
177                  TheSame1(NbrSol) = 0;
178                  gp_Dir2d dc(origin1.XY()-Center.XY());
179                  Standard_Real sign = dc.Dot(gp_Dir2d(-dir1.Y(),dir1.X()));
180                  dc = gp_Dir2d(sign*gp_XY(-dir1.Y(),dir1.X()));
181                  pnttg1sol(NbrSol) = gp_Pnt2d(Center.XY()+Radius*dc.XY());
182                  par1sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),
183                                                   pnttg1sol(NbrSol));
184                  pararg1(NbrSol)=ElCLib::Parameter(L1,pnttg1sol(NbrSol));
185                  TheSame2(NbrSol) = 0;
186                  dc = gp_Dir2d(origin2.XY()-Center.XY());
187                  sign = dc.Dot(gp_Dir2d(-dir2.Y(),dir2.X()));
188                  dc = gp_Dir2d(sign*gp_XY(-dir2.Y(),dir2.X()));
189                  pnttg2sol(NbrSol) = gp_Pnt2d(Center.XY()+Radius*dc.XY());
190                  par2sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),
191                                                   pnttg2sol(NbrSol));
192                  pararg2(NbrSol)=ElCLib::Parameter(L2,pnttg2sol(NbrSol));
193                  TheSame3(NbrSol) = 0;
194                  par3sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),
195                                                   pnttg3sol(NbrSol));
196                  pararg3(NbrSol) = 0.;
197                }
198              }
199            }
200          }
201          WellDone = Standard_True;
202        }
203      }
204    }
205  }
206