0022312: Translation of french commentaries in OCCT files
[occt.git] / src / GccAna / GccAna_Lin2dTanPar.cxx
1 // File GccAna_Lin2dTanPar.cxx, REG 08/07/91
2
3 //========================================================================
4 //    CREATION of a LINE TANGENT to a CIRCLE or PASSING by a POINT  +
5 //                     and PARALLEL to a STRAIGHT DROITE.                        +
6 //========================================================================
7
8 #include <GccAna_Lin2dTanPar.ixx>
9
10 #include <ElCLib.hxx>
11 #include <StdFail_NotDone.hxx>
12 #include <gp_XY.hxx>
13 #include <gp_Dir2d.hxx>
14 #include <gp_Vec2d.hxx>
15 #include <gp_Circ2d.hxx>
16 #include <Standard_OutOfRange.hxx>
17 #include <GccEnt_BadQualifier.hxx>
18
19 //========================================================================
20 //   Passing by a point :                                              +
21 //   Create the straight line with origin ThePoint and                             + 
22 //                          direction Lin1.Direction().                    +
23 //========================================================================
24
25 GccAna_Lin2dTanPar::
26    GccAna_Lin2dTanPar (const gp_Pnt2d& ThePoint  ,
27                        const gp_Lin2d& Lin1      ):
28    linsol(1,1),
29    qualifier1(1,1) ,
30    pnttg1sol(1,1),
31    par1sol(1,1),
32    pararg1(1,1)
33 {
34
35    linsol(1) = gp_Lin2d(ThePoint,Lin1.Direction());
36 // ===============================================
37    qualifier1(1) = GccEnt_noqualifier;
38    pnttg1sol(1) = ThePoint;
39    par1sol(1) = 0.;
40    pararg1(1) = 0.;
41    NbrSol = 1;
42    WellDone = Standard_True;
43 }
44
45 //========================================================================
46 //   Tangent to a circle :                                               +
47 //   Create following the qualifier the straight line                    +
48 //          - with origin P1 (P1 is a point of intersection between C1 and +
49 //                       a straight line passing by the center of C1 and  +
50 //                         direction the normal to Lin1).                 +
51 //                         the choice of the point of intersection depends +
52 //                         on the qualifier.                            +
53 //          - with direction the direction of Lin1.                         +
54 //========================================================================
55
56 GccAna_Lin2dTanPar::
57    GccAna_Lin2dTanPar (const GccEnt_QualifiedCirc& Qualified1,
58                        const gp_Lin2d&             Lin1      ):
59    linsol(1,2),
60    qualifier1(1,2) ,
61    pnttg1sol(1,2),
62    par1sol(1,2),
63    pararg1(1,2)
64 {
65
66    WellDone = Standard_False;
67    Standard_Integer signe = 0;
68    Standard_Integer nbsol = 0;
69    NbrSol = 0;
70    if (!(Qualified1.IsEnclosed() || Qualified1.IsEnclosing() || 
71          Qualified1.IsOutside() || Qualified1.IsUnqualified())) {
72      GccEnt_BadQualifier::Raise();
73      return;
74    }
75    gp_Circ2d C1 = Qualified1.Qualified();
76    Standard_Real xdir = (Lin1.Direction()).X();
77    Standard_Real ydir = (Lin1.Direction()).Y();
78
79    if (Qualified1.IsEnclosed()) { GccEnt_BadQualifier::Raise(); }
80 // ============================
81    else if (Qualified1.IsEnclosing()) {
82 // ==================================
83      nbsol = 1;
84      signe = 1;
85      qualifier1(1) = GccEnt_enclosing;
86    }
87    else if (Qualified1.IsOutside()) {
88 // ===================================
89      nbsol = 1;
90      signe = -1;
91      qualifier1(1) = GccEnt_outside;
92    }
93    else {
94      nbsol = 2;
95      signe = -1;
96      qualifier1(1) = GccEnt_outside;
97      qualifier1(2) = GccEnt_enclosing;
98    }
99    gp_XY xy(-C1.Radius()*ydir,C1.Radius()*xdir);
100    for (Standard_Integer j = 1 ; j <= nbsol ; j++) {
101      signe = -signe;
102      NbrSol++;
103      linsol(NbrSol) = gp_Lin2d(gp_Pnt2d((C1.Location().XY()).Added(signe*xy)),
104 //   =========================================================================
105                                Lin1.Direction());
106 //                             =================
107      pnttg1sol(NbrSol) = gp_Pnt2d((C1.Location().XY()).Added(signe*xy));
108      par1sol(NbrSol) = 0.;
109      pararg1(NbrSol)=ElCLib::Parameter(C1,pnttg1sol(NbrSol));
110      WellDone = Standard_True;
111    }
112  }
113
114 Standard_Boolean GccAna_Lin2dTanPar::
115    IsDone () const { return WellDone; }
116
117 Standard_Integer GccAna_Lin2dTanPar::NbSolutions () const 
118 {
119   if (!WellDone) 
120     StdFail_NotDone::Raise();
121   return NbrSol;
122 }
123
124 gp_Lin2d GccAna_Lin2dTanPar::ThisSolution (const Standard_Integer Index) const
125 {
126   if (!WellDone) { StdFail_NotDone::Raise(); }
127   else if (Index <= 0 || Index > NbrSol) { Standard_OutOfRange::Raise(); }
128   return linsol(Index);
129 }
130
131 void GccAna_Lin2dTanPar::
132   WhichQualifier(const Standard_Integer Index   ,
133                        GccEnt_Position& Qualif1 ) const
134 {
135   if (!WellDone) { StdFail_NotDone::Raise(); }
136    else if (Index <= 0 ||Index > NbrSol) { Standard_OutOfRange::Raise(); }
137    else {
138      Qualif1 = qualifier1(Index);
139    }
140 }
141
142 void GccAna_Lin2dTanPar::
143    Tangency1 (const Standard_Integer Index,
144               Standard_Real& ParSol,
145               Standard_Real& ParArg,
146               gp_Pnt2d& Pnt) const {
147    if (!WellDone) { StdFail_NotDone::Raise(); }
148    else if (Index <= 0 ||Index > NbrSol) { Standard_OutOfRange::Raise(); }
149    else {
150      ParSol = par1sol(Index);
151      ParArg = pararg1(Index);
152      Pnt    = gp_Pnt2d(pnttg1sol(Index));
153    }
154  }