0031035: Coding - uninitialized class fields reported by Visual Studio Code Analysis
[occt.git] / src / Geom2dGcc / Geom2dGcc_Lin2dTanOblIter.cxx
1 // Created on: 1991-12-20
2 // Created by: Remi GILET
3 // Copyright (c) 1991-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 // CREATION D UNE LIGNE TANGENTE A UNE COURBE ET PARALLELE A UNE DROITE. +
19 //========================================================================
20
21 #include <GccEnt_BadQualifier.hxx>
22 #include <Geom2dGcc_CurveTool.hxx>
23 #include <Geom2dGcc_FunctionTanObl.hxx>
24 #include <Geom2dGcc_IsParallel.hxx>
25 #include <Geom2dGcc_Lin2dTanOblIter.hxx>
26 #include <Geom2dGcc_QCurve.hxx>
27 #include <gp_Circ2d.hxx>
28 #include <gp_Dir2d.hxx>
29 #include <gp_Lin2d.hxx>
30 #include <gp_Pnt2d.hxx>
31 #include <gp_Vec2d.hxx>
32 #include <gp_XY.hxx>
33 #include <IntAna2d_AnaIntersection.hxx>
34 #include <IntAna2d_IntPoint.hxx>
35 #include <math_FunctionRoot.hxx>
36 #include <StdFail_NotDone.hxx>
37
38 Geom2dGcc_Lin2dTanOblIter::
39 Geom2dGcc_Lin2dTanOblIter (const Geom2dGcc_QCurve&  Qualified1 ,
40                            const gp_Lin2d&          TheLin     ,
41                            const Standard_Real      Param1     ,
42                            const Standard_Real      TolAng     ,
43                            const Standard_Real      Angle      )
44 : par2sol(0.0),
45   pararg2(0.0)
46 {
47
48   par1sol = 0.;
49   pararg1 = 0.;
50   WellDone = Standard_False;
51   if (!(Qualified1.IsEnclosed() || Qualified1.IsEnclosing() || 
52     Qualified1.IsOutside() || Qualified1.IsUnqualified())) {
53       throw GccEnt_BadQualifier();
54       return;
55   }
56   Paral2 = Standard_False;
57   Geom2dAdaptor_Curve Cu1 = Qualified1.Qualified();
58   Standard_Real U1 = Geom2dGcc_CurveTool::FirstParameter(Cu1);
59   Standard_Real U2 = Geom2dGcc_CurveTool::LastParameter(Cu1);
60   gp_Dir2d Dir(TheLin.Direction());
61   Standard_Real A = Dir.X();
62   Standard_Real B = Dir.Y();
63   gp_Dir2d TheDirection(Dir);
64   if (Abs(Angle) > Abs(TolAng)) {
65     if (Abs(Abs(Angle)-M_PI) <= Abs(TolAng)) {
66       Paral2 = Standard_True;
67       TheDirection = Dir.Reversed();
68     }
69     else if (Abs(Angle-M_PI/2) <= Abs(TolAng)) { TheDirection=gp_Dir2d(-B,A); }
70     else if (Abs(Angle+M_PI/2) <= Abs(TolAng)) { TheDirection=gp_Dir2d(B,-A); }
71     else {
72       TheDirection=gp_Dir2d(A*Cos(Angle)-B*Sin(Angle),
73         A*Sin(Angle)+B*Cos(Angle));
74     }
75   }
76   else { Paral2 = Standard_True; }
77   Geom2dGcc_FunctionTanObl func(Cu1,TheDirection);
78   math_FunctionRoot sol(func,Param1,
79     Geom2dGcc_CurveTool::EpsX(Cu1,Abs(TolAng)),U1,U2,100);
80   if (sol.IsDone()) {
81     Standard_Real Usol = sol.Root();
82     gp_Pnt2d Origine;
83     gp_Vec2d Vect1,Vect2;
84     Geom2dGcc_CurveTool::D2(Cu1,Usol,Origine,Vect1,Vect2);
85     Standard_Real sign1 = Vect1.XY().Dot(TheDirection.XY());
86     Standard_Real sign2 = Vect2.XY().Crossed(TheDirection.XY());
87     if (Qualified1.IsUnqualified() || 
88       (Qualified1.IsEnclosing() && sign2<=0.) ||
89       (Qualified1.IsOutside() && sign1 <= 0. && sign2 >= 0.) ||
90       (Qualified1.IsEnclosed() && sign1 >= 0. && sign2 >= 0.)) {
91         WellDone = Standard_True;
92         linsol = gp_Lin2d(Origine,TheDirection);
93         pnttg1sol = Origine;
94         qualifier1 = Qualified1.Qualifier();
95         pararg1 = Usol;
96         par1sol = 0.;
97         if (!Paral2) {
98           IntAna2d_AnaIntersection Intp(linsol,TheLin);
99           if (Intp.IsDone() && !Intp.IsEmpty()) {
100             if (Intp.NbPoints()==1) {
101               pntint2sol = Intp.Point(1).Value();
102               par2sol = gp_Vec2d(linsol.Direction()).
103                 Dot(gp_Vec2d(linsol.Location(),pntint2sol));
104               pararg2 = gp_Vec2d(TheLin.Direction()).
105                 Dot(gp_Vec2d(TheLin.Location(),pntint2sol));
106             }
107           }
108         }
109     }
110   }
111 }
112
113 Standard_Boolean Geom2dGcc_Lin2dTanOblIter::
114 IsDone () const { return WellDone; }
115
116 gp_Lin2d Geom2dGcc_Lin2dTanOblIter::ThisSolution () const 
117 {       
118   if (!WellDone) throw StdFail_NotDone();
119
120   return linsol;
121 }
122
123 void Geom2dGcc_Lin2dTanOblIter:: 
124 WhichQualifier (GccEnt_Position& Qualif1) const
125 {
126   if (!WellDone) { throw StdFail_NotDone(); }
127   else {
128     Qualif1 = qualifier1;
129   }
130 }
131
132 Standard_Boolean Geom2dGcc_Lin2dTanOblIter::
133 IsParallel2 () const { return Paral2; }
134
135 void Geom2dGcc_Lin2dTanOblIter::
136 Tangency1 (Standard_Real& ParSol    ,
137            Standard_Real& ParArg    ,
138            gp_Pnt2d& PntSol) const {
139              if (!WellDone) { throw StdFail_NotDone(); }
140              else {
141                ParSol = par1sol;
142                ParArg = pararg1;
143                PntSol = gp_Pnt2d(pnttg1sol);
144              }
145 }
146
147 void Geom2dGcc_Lin2dTanOblIter::
148 Intersection2 (Standard_Real&     ParSol ,
149                Standard_Real&     ParArg ,
150                gp_Pnt2d& PntSol ) const {
151                  if (!WellDone) { throw StdFail_NotDone(); }
152                  else if (Paral2) { throw Geom2dGcc_IsParallel(); }
153                  else {
154                    PntSol = pntint2sol;
155                    ParSol = par2sol;
156                    ParArg = pararg2;
157                  }
158 }
159