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