Test for 0022778: Bug in BRepMesh
[occt.git] / src / GccAna / GccAna_Circ2d3Tan_8.cxx
CommitLineData
b311480e 1// Copyright (c) 1995-1999 Matra Datavision
2// Copyright (c) 1999-2012 OPEN CASCADE SAS
3//
4// The content of this file is subject to the Open CASCADE Technology Public
5// License Version 6.5 (the "License"). You may not use the content of this file
6// except in compliance with the License. Please obtain a copy of the License
7// at http://www.opencascade.org and read it completely before using this file.
8//
9// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11//
12// The Original Code and all software distributed under the License is
13// distributed on an "AS IS" basis, without warranty of any kind, and the
14// Initial Developer hereby disclaims all such warranties, including without
15// limitation, any warranties of merchantability, fitness for a particular
16// purpose or non-infringement. Please see the License for the specific terms
17// and conditions governing the rights and limitations under the License.
18
7fd59977 19
7fd59977 20
21#include <GccAna_Circ2d3Tan.jxx>
22
23#include <ElCLib.hxx>
24#include <IntAna2d_AnaIntersection.hxx>
25#include <IntAna2d_IntPoint.hxx>
26#include <gp_Lin2d.hxx>
27#include <gp_Circ2d.hxx>
28#include <gp_Dir2d.hxx>
29#include <GccAna_LinPnt2dBisec.hxx>
30#include <GccAna_Lin2dBisec.hxx>
31#include <GccAna_Pnt2dBisec.hxx>
32#include <GccInt_Bisec.hxx>
33#include <GccInt_IType.hxx>
34#include <IntAna2d_Conic.hxx>
35#include <GccEnt_BadQualifier.hxx>
36#include <Precision.hxx>
37//=========================================================================
0d969553 38// Creation of a circle tangent to a straight line and two points. +
7fd59977 39//=========================================================================
40
41GccAna_Circ2d3Tan::
42 GccAna_Circ2d3Tan (const GccEnt_QualifiedLin& Qualified1,
43 const gp_Pnt2d& Point2 ,
44 const gp_Pnt2d& Point3 ,
45 const Standard_Real Tolerance ):
46
47 cirsol(1,2) ,
48 qualifier1(1,2) ,
49 qualifier2(1,2) ,
50 qualifier3(1,2) ,
51 TheSame1(1,2) ,
52 TheSame2(1,2) ,
53 TheSame3(1,2) ,
54 pnttg1sol(1,2) ,
55 pnttg2sol(1,2) ,
56 pnttg3sol(1,2) ,
57 par1sol(1,2) ,
58 par2sol(1,2) ,
59 par3sol(1,2) ,
60 pararg1(1,2) ,
61 pararg2(1,2) ,
62 pararg3(1,2)
63{
64
65 WellDone = Standard_False;
66 Standard_Real Tol = Abs(Tolerance);
67 gp_Dir2d dirx(1.0,0.0);
68 NbrSol = 0;
69 if (!(Qualified1.IsEnclosed() ||
70 Qualified1.IsOutside() || Qualified1.IsUnqualified())) {
71 GccEnt_BadQualifier::Raise();
72 return;
73 }
74
75//=========================================================================
0d969553 76// Processing. +
7fd59977 77//=========================================================================
78
79 gp_Lin2d L1 = Qualified1.Qualified();
80 gp_Pnt2d origin1(L1.Location());
81 gp_Dir2d dir1(L1.Direction());
82 gp_Dir2d normL1(-dir1.Y(),dir1.X());
83
84 if (Point2.IsEqual(Point3,Precision::Confusion())) {
85 WellDone = Standard_False;
86 return ;
87 }
88
89 GccAna_Pnt2dBisec Bis1(Point2,Point3);
90 GccAna_LinPnt2dBisec Bis2(L1,Point2);
91 if (Bis1.IsDone() && Bis2.IsDone()) {
92 gp_Lin2d linint1(Bis1.ThisSolution());
93 Handle(GccInt_Bisec) Sol2 = Bis2.ThisSolution();
94 GccInt_IType typ2 = Sol2->ArcType();
95#ifdef DEB
96 gp_Lin2d linintb(Bis1.ThisSolution());
97#else
98 Bis1.ThisSolution() ;
99#endif
100 IntAna2d_AnaIntersection Intp;
101 if (typ2 == GccInt_Lin) {
102 gp_Lin2d linint2(Sol2->Line());
103 Intp.Perform (linint1,linint2);
104 }
105 else if (typ2 == GccInt_Par) {
106 Intp.Perform (linint1,IntAna2d_Conic(Sol2->Parabola()));
107 }
108 if (Intp.IsDone()) {
109 if ((!Intp.IsEmpty())&&(!Intp.ParallelElements())&&
110 (!Intp.IdenticalElements())) {
111 for (Standard_Integer j = 1 ; j <= Intp.NbPoints() ; j++) {
112 gp_Pnt2d Center(Intp.Point(j).Value());
113 Standard_Real dist1 = L1.Distance(Center);
114 Standard_Real dist2 = Center.Distance(Point2);
6e6cd5d9 115
7fd59977 116 Standard_Real Radius=0;
117 Standard_Integer nbsol1 = 0;
118// Standard_Integer nbsol2 = 0;
119 Standard_Integer nbsol3 = 0;
120 Standard_Boolean ok = Standard_False;
f2fd3809 121 Standard_Real difference = (((origin1.X()-Center.X())*(-dir1.Y())) + ((origin1.Y()-Center.Y())*(dir1.X())));
122 if ((Qualified1.IsEnclosed() && difference <= 0) ||
123 (Qualified1.IsOutside() && difference >= 0) ||
124 (Qualified1.IsUnqualified()))
125 {
126 ok = Standard_True;
127 nbsol1 = 1;
128 Radius = dist1;
129 }
7fd59977 130 if (ok) {
f2fd3809 131 if (Abs(dist2-Radius)<=Tol) {
7fd59977 132 nbsol3 = 1;
133 }
134 else { ok = Standard_False; }
135 }
136 if (ok) {
137 for (Standard_Integer k = 1 ; k <= nbsol3 ; k++) {
138 NbrSol++;
139 cirsol(NbrSol) = gp_Circ2d(gp_Ax2d(Center,dirx),Radius);
140// =======================================================
141 gp_Dir2d dc1(origin1.XY()-Center.XY());
142 if (!Qualified1.IsUnqualified()) {
143 qualifier1(NbrSol) = Qualified1.Qualifier();
144 }
145 else if (dc1.Dot(normL1) > 0.0) {
146 qualifier1(NbrSol) = GccEnt_outside;
147 }
148 else { qualifier1(NbrSol) = GccEnt_enclosed; }
149 qualifier2(NbrSol) = GccEnt_noqualifier;
150 qualifier3(NbrSol) = GccEnt_noqualifier;
151 TheSame1(NbrSol) = 0;
152 gp_Dir2d dc(origin1.XY()-Center.XY());
153 Standard_Real sign = dc.Dot(gp_Dir2d(-dir1.Y(),dir1.X()));
154 dc = gp_Dir2d(sign*gp_XY(-dir1.Y(),dir1.X()));
155 pnttg1sol(NbrSol) = gp_Pnt2d(Center.XY()+Radius*dc.XY());
156 par1sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),
157 pnttg1sol(NbrSol));
158 pararg1(NbrSol)=ElCLib::Parameter(L1,pnttg1sol(NbrSol));
159 TheSame2(NbrSol) = 0;
160 pnttg2sol(NbrSol) = Point2;
161 par2sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),
162 pnttg2sol(NbrSol));
163 pararg2(NbrSol) = 0.;
164 TheSame3(NbrSol) = 0;
165 pnttg3sol(NbrSol) = Point3;
166 par3sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),
167 pnttg3sol(NbrSol));
168 pararg3(NbrSol) = 0.;
169 }
170 }
171 }
172 }
173 WellDone = Standard_True;
174 }
175 }
176 }
177