0032832: Coding - get rid of unused headers [FairCurve to GeomAPI]
[occt.git] / src / GccAna / GccAna_Circ2dTanOnRad_1.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_Circ2dTanOnRad.hxx>
18 #include <GccEnt_BadQualifier.hxx>
19 #include <GccEnt_QualifiedLin.hxx>
20 #include <gp_Circ2d.hxx>
21 #include <gp_Dir2d.hxx>
22 #include <gp_Lin2d.hxx>
23 #include <gp_Pnt2d.hxx>
24 #include <IntAna2d_AnaIntersection.hxx>
25 #include <IntAna2d_IntPoint.hxx>
26 #include <Standard_NegativeValue.hxx>
27 #include <TColStd_Array1OfInteger.hxx>
28
29 //=========================================================================
30 //   Circle tangent to straight line  Qualified1 (L1)                         +
31 //          center on straight line OnLine                                  +
32 //          of radius Radius.                                              +
33 //                                                                        +
34 //  Initialize the table of solutions cirsol and all fields.              + 
35 //  Elimine depending on the qualifier the cases not being solutions.     +
36 //  Create L1para : parallel to L1 in the direction required by the       +
37 //                  qualifier at distance Radius.                         +
38 //  Point P of intersection between L1para and OnLine will give the center point +
39 //  of the solution.                                                +
40 //  Create solutions cirsol with center P and radius Radius.          +
41 //  Fill the fields.                                                +
42 //=========================================================================
43 GccAna_Circ2dTanOnRad::
44    GccAna_Circ2dTanOnRad (const GccEnt_QualifiedLin& Qualified1,
45                           const gp_Lin2d&            OnLine    ,
46                           const Standard_Real        Radius    ,
47                           const Standard_Real        Tolerance ):
48    cirsol(1,2)     ,
49    qualifier1(1,2) ,
50    TheSame1(1,2)   ,
51    pnttg1sol(1,2)  ,
52    pntcen3(1,2)    ,
53    par1sol(1,2)    ,
54    pararg1(1,2)    ,
55    parcen3(1,2)    
56 {
57
58    Standard_Real Tol =Abs(Tolerance);
59    gp_Dir2d dirx(1.0,0.0);
60    WellDone = Standard_False;
61    NbrSol = 0;
62    if (!(Qualified1.IsEnclosed() ||
63          Qualified1.IsOutside() || Qualified1.IsUnqualified())) {
64      throw GccEnt_BadQualifier();
65      return;
66    }
67    Standard_Integer nbsol = 0;
68    TColStd_Array1OfInteger eps(1,2);
69    gp_Lin2d L1 = Qualified1.Qualified();
70    gp_Pnt2d origin1(L1.Location());
71    gp_Dir2d dir1(L1.Direction());
72    gp_Dir2d normL1(-dir1.Y(),dir1.X());
73
74    if (Radius < 0.0) { throw Standard_NegativeValue(); }
75    else if ((OnLine.Direction()).IsParallel(dir1,Tol)) {
76      WellDone = Standard_True;
77    }
78    else {
79      if (Qualified1.IsEnclosed()) {
80 //   ============================
81        eps(1) = -1;
82        nbsol = 1;
83      }
84      else if (Qualified1.IsOutside()) {
85 //   ================================
86        eps(1) = 1;
87        nbsol = 1;
88      }
89      else {
90 //   ====
91        eps(1) = 1;
92        eps(2) = -1;
93        nbsol = 2;
94      }
95      Standard_Real dx1 = dir1.X();
96      Standard_Real dy1 = dir1.Y();
97      Standard_Real lx1 = origin1.X();
98      Standard_Real ly1 = origin1.Y();
99      for (Standard_Integer j = 1 ; j <= nbsol ; j++) {
100        gp_Lin2d L1para(gp_Pnt2d(lx1+eps(j)*Radius*dy1,ly1-eps(j)*Radius*dx1),
101                        dir1);
102        IntAna2d_AnaIntersection Intp(OnLine,L1para);
103        if (Intp.IsDone()) {
104          if (!Intp.IsEmpty()) {
105            for (Standard_Integer i = 1 ; i <= Intp.NbPoints() ; i++) {
106              NbrSol++;
107              gp_Pnt2d Center(Intp.Point(i).Value());
108              cirsol(NbrSol)=gp_Circ2d(gp_Ax2d(Center,dirx),Radius);
109 //           =====================================================
110              gp_Dir2d dc1(origin1.XY()-Center.XY());
111              if (!Qualified1.IsUnqualified()) { 
112                qualifier1(NbrSol) = Qualified1.Qualifier();
113              }
114              else if (dc1.Dot(normL1) > 0.0) {  
115                qualifier1(NbrSol) = GccEnt_outside; 
116              }
117              else { qualifier1(NbrSol) = GccEnt_enclosed; }
118              TheSame1(NbrSol) = 0;
119              if (gp_Vec2d(Center,origin1).Dot(gp_Dir2d(-dy1,dx1))>0.0) {
120                pnttg1sol(NbrSol)=gp_Pnt2d(Center.XY()+Radius*gp_XY(-dy1,dx1));
121                pntcen3(NbrSol) = cirsol(1).Location();
122              }
123              else {
124                pnttg1sol(NbrSol)=gp_Pnt2d(Center.XY()-Radius*gp_XY(-dy1,dx1));
125                pntcen3(NbrSol) = cirsol(1).Location();
126              }
127              par1sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),
128                                               pnttg1sol(NbrSol));
129              pararg1(NbrSol)=ElCLib::Parameter(L1,pnttg1sol(NbrSol));
130              parcen3(NbrSol)=ElCLib::Parameter(OnLine,pntcen3(NbrSol));
131            }
132          }
133          WellDone = Standard_True;
134        }
135      }
136    }
137  }