0024510: Remove unused local variables
[occt.git] / src / GccAna / GccAna_Lin2dTanObl.cxx
CommitLineData
b311480e 1// Copyright (c) 1995-1999 Matra Datavision
973c2be1 2// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 3//
973c2be1 4// This file is part of Open CASCADE Technology software library.
b311480e 5//
973c2be1 6// This library is free software; you can redistribute it and / or modify it
7// under the terms of the GNU Lesser General Public 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.
b311480e 11//
973c2be1 12// Alternatively, this file may be used under the terms of Open CASCADE
13// commercial license or contractual agreement.
7fd59977 14
15//=========================================================================
0d969553
Y
16// CREATION of a STRAIGHT LINE TANGENT to a CIRCLE or PASSING by a POINT +
17// and MAKING ANGLE A with a STRAIGHT LINE. +
7fd59977 18//=========================================================================
19
20#include <GccAna_Lin2dTanObl.ixx>
21
22#include <ElCLib.hxx>
23#include <StdFail_NotDone.hxx>
24#include <gp_XY.hxx>
25#include <gp_Dir2d.hxx>
26#include <gp_Vec2d.hxx>
27#include <gp_Circ2d.hxx>
28#include <IntAna2d_AnaIntersection.hxx>
29#include <IntAna2d_IntPoint.hxx>
30#include <Standard_OutOfRange.hxx>
31#include <GccEnt_BadQualifier.hxx>
32
33//=========================================================================
0d969553
Y
34// Creation of a straight line passing by a point : ThePoint +
35// making an angle : TheAngle +
36// with straight line : TheLine. +
37// Subject the straight line (ThePoint,TheLine.Location()) to a rotation +
38// by angle TheAngle ==> D1. +
39// create straight line passing through ThePoint of direction D1. +
7fd59977 40//=========================================================================
41
42GccAna_Lin2dTanObl::
43 GccAna_Lin2dTanObl (const gp_Pnt2d& ThePoint ,
44 const gp_Lin2d& TheLine ,
45 const Standard_Real TheAngle ):
46 linsol(1,1) ,
47 qualifier1(1,1),
48 pnttg1sol(1,1) ,
49 pntint2sol(1,1),
50 par1sol(1,1) ,
51 par2sol(1,1) ,
52 pararg1(1,1) ,
53 pararg2(1,1)
54{
55
56 Standard_Real Cosa = TheLine.Direction().X();
57 Standard_Real Sina = TheLine.Direction().Y();
58 linsol(1) = gp_Lin2d(ThePoint,
59// ==============================
60 gp_Dir2d(Cosa*Cos(TheAngle)-Sina*Sin(TheAngle),
61// ===============================================
62 Sina*Cos(TheAngle)+Sin(TheAngle)*Cosa));
63// =======================================
64 qualifier1(1) = GccEnt_noqualifier;
65 pnttg1sol(1) = ThePoint;
66 IntAna2d_AnaIntersection Intp(linsol(1),TheLine);
67 if (Intp.IsDone()) {
68 if (!Intp.IsEmpty()) {
69 for (Standard_Integer i = 1 ; i <= Intp.NbPoints() ; i++) {
70 pntint2sol(1) = Intp.Point(i).Value();
71 }
72 }
73 par1sol(1)=ElCLib::Parameter(linsol(1),pnttg1sol(1));
74 par2sol(1)=ElCLib::Parameter(linsol(1),pntint2sol(1));
75 pararg1(1)=0.;
76 pararg2(1)=ElCLib::Parameter(TheLine,pntint2sol(1));
77 NbrSol = 1;
78 WellDone = Standard_True;
79 }
80 else {
81 WellDone = Standard_False;
82 NbrSol=0;
83 }
84 }
85
86//=========================================================================
0d969553
Y
87// Creation of a straight line tangent to a circle : Qualified1 (C1) +
88// making angle : TheAngle +
89// with a straight line : TheLine. +
90// Subject the straight line (C1.Location,TheLine.Location()) to a +
91// rotation by angle TheAngle or -TheAngle ==> D1. +
92// create the straight line passing by C1 of direction D1. +
7fd59977 93//=========================================================================
94
95GccAna_Lin2dTanObl::
96 GccAna_Lin2dTanObl (const GccEnt_QualifiedCirc& Qualified1 ,
97 const gp_Lin2d& TheLine ,
98 const Standard_Real TheAngle ):
99 linsol(1,2) ,
100 qualifier1(1,2) ,
101 pnttg1sol(1,2),
102 pntint2sol(1,2),
103 par1sol(1,2),
104 par2sol(1,2),
105 pararg1(1,2),
106 pararg2(1,2)
107{
108
109 WellDone = Standard_False;
110 NbrSol = 0;
111 if (!(Qualified1.IsEnclosed() || Qualified1.IsEnclosing() ||
112 Qualified1.IsOutside() || Qualified1.IsUnqualified())) {
113 GccEnt_BadQualifier::Raise();
114 return;
115 }
116 Standard_Real Cosa = TheLine.Direction().X();
117 Standard_Real Sina = TheLine.Direction().Y();
118 if (Qualified1.IsEnclosed()) {
119// ============================
120 GccEnt_BadQualifier::Raise();
121 }
122 else {
123 gp_Circ2d C1 = Qualified1.Qualified();
124 Standard_Real R1 = C1.Radius();
125 if (Qualified1.IsEnclosing()) {
126// =============================
127 gp_XY xy(Cos(TheAngle)*Cosa-Sin(TheAngle)*Sina,
128 Cos(TheAngle)*Sina+Sin(TheAngle)*Cosa);
129 pnttg1sol(1) = gp_Pnt2d(C1.Location().XY()+R1*gp_XY(xy.Y(),-xy.X()));
130 linsol(1) = gp_Lin2d(pnttg1sol(1),gp_Dir2d(xy));
131// ===============================================
132 qualifier1(1) = Qualified1.Qualifier();
133 IntAna2d_AnaIntersection Intp(linsol(1),TheLine);
134 NbrSol = 1;
135 WellDone = Standard_True;
136 if (Intp.IsDone()) {
137 if (!Intp.IsEmpty()) {
138 for (Standard_Integer i = 1 ; i <= Intp.NbPoints() ; i++) {
139 pntint2sol(1) = Intp.Point(i).Value();
140 }
141 }
142 }
143 }
144 else if (Qualified1.IsOutside()) {
145// ================================
146 gp_XY xy(Cos(TheAngle)*Cosa-Sin(TheAngle)*Sina,
147 Cos(TheAngle)*Sina+Sin(TheAngle)*Cosa);
148 pnttg1sol(1) = gp_Pnt2d(C1.Location().XY()+R1*gp_XY(-xy.Y(),xy.X()));
149 linsol(1) = gp_Lin2d(pnttg1sol(1),gp_Dir2d(xy));
150// ===============================================
151 qualifier1(1) = Qualified1.Qualifier();
152 IntAna2d_AnaIntersection Intp(linsol(1),TheLine);
153 WellDone = Standard_True;
154 NbrSol = 1;
155 if (Intp.IsDone()) {
156 if (!Intp.IsEmpty()) {
157 for (Standard_Integer i = 1 ; i <= Intp.NbPoints() ; i++) {
158 pntint2sol(1) = Intp.Point(i).Value();
159 }
160 }
161 }
162 }
163 else if (Qualified1.IsUnqualified()) {
164// ====================================
165 gp_XY xy(Cos(TheAngle)*Cosa-Sin(TheAngle)*Sina,
166 Cos(TheAngle)*Sina+Sin(TheAngle)*Cosa);
167 pnttg1sol(1) = gp_Pnt2d(C1.Location().XY()+R1*gp_XY(xy.Y(),-xy.X()));
168 linsol(1) = gp_Lin2d(pnttg1sol(1),gp_Dir2d(xy));
169// ===============================================
170 qualifier1(1) = GccEnt_enclosing;
171 IntAna2d_AnaIntersection Intp(linsol(1),TheLine);
172 WellDone = Standard_True;
173 NbrSol=1;
174 if (Intp.IsDone()) {
175 if (!Intp.IsEmpty()) {
176 for (Standard_Integer i = 1 ; i <= Intp.NbPoints() ; i++) {
177 pntint2sol(1) = Intp.Point(i).Value();
178 }
179 }
180 }
181 pnttg1sol(2) = gp_Pnt2d(C1.Location().XY()+R1*gp_XY(-xy.Y(),xy.X()));
182 linsol(2) = gp_Lin2d(pnttg1sol(2),gp_Dir2d(xy));
183// ===============================================
184 qualifier1(2) = GccEnt_outside;
185 Intp = IntAna2d_AnaIntersection(linsol(1),TheLine);
186 NbrSol++;
187 WellDone = Standard_True;
188 if (Intp.IsDone()) {
189 if (!Intp.IsEmpty()) {
190 for (Standard_Integer i = 1 ; i <= Intp.NbPoints() ; i++) {
191 pntint2sol(2) = Intp.Point(i).Value();
192 }
193 }
194 }
195 }
196 for (Standard_Integer index = 1; index <= NbrSol; index++) {
197 par1sol(index)=ElCLib::Parameter(linsol(index),pnttg1sol(index));
198 pararg1(index)=ElCLib::Parameter(C1,pnttg1sol(index));
199 par2sol(index)=ElCLib::Parameter(linsol(index),pntint2sol(index));
200 pararg2(index)=ElCLib::Parameter(TheLine,pntint2sol(index));
201 }
202 }
203 }
204
205Standard_Boolean GccAna_Lin2dTanObl::
206 IsDone () const { return WellDone; }
207
208Standard_Integer GccAna_Lin2dTanObl::
209 NbSolutions () const
210{
211 if (!WellDone) StdFail_NotDone::Raise();
212 return NbrSol;
213}
214
215gp_Lin2d GccAna_Lin2dTanObl::
216 ThisSolution (const Standard_Integer Index) const
217{
218 if (!WellDone)
219 StdFail_NotDone::Raise();
220 if (Index <= 0 || Index > NbrSol)
221 Standard_OutOfRange::Raise();
222
223 return linsol(Index);
224}
225
226void GccAna_Lin2dTanObl::
227 WhichQualifier(const Standard_Integer Index ,
228 GccEnt_Position& Qualif1 ) const
229{
230 if (!WellDone) { StdFail_NotDone::Raise(); }
231 else if (Index <= 0 ||Index > NbrSol) { Standard_OutOfRange::Raise(); }
232 else {
233 Qualif1 = qualifier1(Index);
234 }
235}
236
237void GccAna_Lin2dTanObl::
238 Tangency1 (const Standard_Integer Index,
239 Standard_Real& ParSol,
240 Standard_Real& ParArg,
241 gp_Pnt2d& PntSol) const{
242 if (!WellDone) { StdFail_NotDone::Raise(); }
243 else if (Index <= 0 ||Index > NbrSol) { Standard_OutOfRange::Raise(); }
244 else {
245 ParSol = par1sol(Index);
246 ParArg = pararg1(Index);
247 PntSol = gp_Pnt2d(pnttg1sol(Index));
248 }
249 }
250
251void GccAna_Lin2dTanObl::
252 Intersection2 (const Standard_Integer Index,
253 Standard_Real& ParSol,
254 Standard_Real& ParArg,
255 gp_Pnt2d& PntSol) const{
256 if (!WellDone) { StdFail_NotDone::Raise(); }
257 else if (Index <= 0 ||Index > NbrSol) { Standard_OutOfRange::Raise(); }
258 else {
259 ParSol = par2sol(Index);
260 ParArg = pararg2(Index);
261 PntSol = gp_Pnt2d(pntint2sol(Index));
262 }
263 }
264
265