0024002: Overall code and build procedure refactoring -- automatic
[occt.git] / src / GccAna / GccAna_Circ2d3Tan_8.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//
d5f74e42 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
973c2be1 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
7fd59977 15
16#include <ElCLib.hxx>
42cf5bc1 17#include <GccAna_Circ2d3Tan.hxx>
7fd59977 18#include <GccAna_Lin2dBisec.hxx>
42cf5bc1 19#include <GccAna_LinPnt2dBisec.hxx>
7fd59977 20#include <GccAna_Pnt2dBisec.hxx>
42cf5bc1 21#include <GccEnt_BadQualifier.hxx>
22#include <GccEnt_QualifiedCirc.hxx>
23#include <GccEnt_QualifiedLin.hxx>
7fd59977 24#include <GccInt_Bisec.hxx>
25#include <GccInt_IType.hxx>
42cf5bc1 26#include <gp_Circ2d.hxx>
27#include <gp_Dir2d.hxx>
28#include <gp_Lin2d.hxx>
29#include <gp_Pnt2d.hxx>
30#include <IntAna2d_AnaIntersection.hxx>
7fd59977 31#include <IntAna2d_Conic.hxx>
42cf5bc1 32#include <IntAna2d_IntPoint.hxx>
7fd59977 33#include <Precision.hxx>
42cf5bc1 34#include <Standard_OutOfRange.hxx>
35#include <StdFail_NotDone.hxx>
36
7fd59977 37//=========================================================================
0d969553 38// Creation of a circle tangent to a straight line and two points. +
7fd59977 39//=========================================================================
7fd59977 40GccAna_Circ2d3Tan::
41 GccAna_Circ2d3Tan (const GccEnt_QualifiedLin& Qualified1,
42 const gp_Pnt2d& Point2 ,
43 const gp_Pnt2d& Point3 ,
44 const Standard_Real Tolerance ):
45
46 cirsol(1,2) ,
47 qualifier1(1,2) ,
48 qualifier2(1,2) ,
49 qualifier3(1,2) ,
50 TheSame1(1,2) ,
51 TheSame2(1,2) ,
52 TheSame3(1,2) ,
53 pnttg1sol(1,2) ,
54 pnttg2sol(1,2) ,
55 pnttg3sol(1,2) ,
56 par1sol(1,2) ,
57 par2sol(1,2) ,
58 par3sol(1,2) ,
59 pararg1(1,2) ,
60 pararg2(1,2) ,
61 pararg3(1,2)
62{
63
64 WellDone = Standard_False;
65 Standard_Real Tol = Abs(Tolerance);
66 gp_Dir2d dirx(1.0,0.0);
67 NbrSol = 0;
68 if (!(Qualified1.IsEnclosed() ||
69 Qualified1.IsOutside() || Qualified1.IsUnqualified())) {
70 GccEnt_BadQualifier::Raise();
71 return;
72 }
73
74//=========================================================================
0d969553 75// Processing. +
7fd59977 76//=========================================================================
77
78 gp_Lin2d L1 = Qualified1.Qualified();
79 gp_Pnt2d origin1(L1.Location());
80 gp_Dir2d dir1(L1.Direction());
81 gp_Dir2d normL1(-dir1.Y(),dir1.X());
82
83 if (Point2.IsEqual(Point3,Precision::Confusion())) {
84 WellDone = Standard_False;
85 return ;
86 }
87
88 GccAna_Pnt2dBisec Bis1(Point2,Point3);
89 GccAna_LinPnt2dBisec Bis2(L1,Point2);
90 if (Bis1.IsDone() && Bis2.IsDone()) {
91 gp_Lin2d linint1(Bis1.ThisSolution());
92 Handle(GccInt_Bisec) Sol2 = Bis2.ThisSolution();
93 GccInt_IType typ2 = Sol2->ArcType();
0797d9d3 94#ifdef OCCT_DEBUG
7fd59977 95 gp_Lin2d linintb(Bis1.ThisSolution());
96#else
97 Bis1.ThisSolution() ;
98#endif
99 IntAna2d_AnaIntersection Intp;
100 if (typ2 == GccInt_Lin) {
101 gp_Lin2d linint2(Sol2->Line());
102 Intp.Perform (linint1,linint2);
103 }
104 else if (typ2 == GccInt_Par) {
105 Intp.Perform (linint1,IntAna2d_Conic(Sol2->Parabola()));
106 }
107 if (Intp.IsDone()) {
108 if ((!Intp.IsEmpty())&&(!Intp.ParallelElements())&&
109 (!Intp.IdenticalElements())) {
110 for (Standard_Integer j = 1 ; j <= Intp.NbPoints() ; j++) {
111 gp_Pnt2d Center(Intp.Point(j).Value());
112 Standard_Real dist1 = L1.Distance(Center);
113 Standard_Real dist2 = Center.Distance(Point2);
6e6cd5d9 114
7fd59977 115 Standard_Real Radius=0;
7fd59977 116 Standard_Integer nbsol3 = 0;
117 Standard_Boolean ok = Standard_False;
f2fd3809 118 Standard_Real difference = (((origin1.X()-Center.X())*(-dir1.Y())) + ((origin1.Y()-Center.Y())*(dir1.X())));
119 if ((Qualified1.IsEnclosed() && difference <= 0) ||
120 (Qualified1.IsOutside() && difference >= 0) ||
121 (Qualified1.IsUnqualified()))
122 {
123 ok = Standard_True;
f2fd3809 124 Radius = dist1;
125 }
7fd59977 126 if (ok) {
f2fd3809 127 if (Abs(dist2-Radius)<=Tol) {
7fd59977 128 nbsol3 = 1;
129 }
130 else { ok = Standard_False; }
131 }
132 if (ok) {
133 for (Standard_Integer k = 1 ; k <= nbsol3 ; k++) {
134 NbrSol++;
135 cirsol(NbrSol) = gp_Circ2d(gp_Ax2d(Center,dirx),Radius);
136// =======================================================
137 gp_Dir2d dc1(origin1.XY()-Center.XY());
138 if (!Qualified1.IsUnqualified()) {
139 qualifier1(NbrSol) = Qualified1.Qualifier();
140 }
141 else if (dc1.Dot(normL1) > 0.0) {
142 qualifier1(NbrSol) = GccEnt_outside;
143 }
144 else { qualifier1(NbrSol) = GccEnt_enclosed; }
145 qualifier2(NbrSol) = GccEnt_noqualifier;
146 qualifier3(NbrSol) = GccEnt_noqualifier;
147 TheSame1(NbrSol) = 0;
148 gp_Dir2d dc(origin1.XY()-Center.XY());
149 Standard_Real sign = dc.Dot(gp_Dir2d(-dir1.Y(),dir1.X()));
150 dc = gp_Dir2d(sign*gp_XY(-dir1.Y(),dir1.X()));
151 pnttg1sol(NbrSol) = gp_Pnt2d(Center.XY()+Radius*dc.XY());
152 par1sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),
153 pnttg1sol(NbrSol));
154 pararg1(NbrSol)=ElCLib::Parameter(L1,pnttg1sol(NbrSol));
155 TheSame2(NbrSol) = 0;
156 pnttg2sol(NbrSol) = Point2;
157 par2sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),
158 pnttg2sol(NbrSol));
159 pararg2(NbrSol) = 0.;
160 TheSame3(NbrSol) = 0;
161 pnttg3sol(NbrSol) = Point3;
162 par3sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),
163 pnttg3sol(NbrSol));
164 pararg3(NbrSol) = 0.;
165 }
166 }
167 }
168 }
169 WellDone = Standard_True;
170 }
171 }
172 }
173