0029915: Porting to VC 2017 : Regressions in Modeling Algorithms on VC 2017
[occt.git] / src / Geom2dGcc / Geom2dGcc_Circ2dTanCenGeo.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
578ce4be 15
42cf5bc1 16#include <Extrema_ExtPC2d.hxx>
17#include <Extrema_POnCurv2d.hxx>
18#include <GccEnt_BadQualifier.hxx>
19#include <Geom2dGcc_Circ2dTanCenGeo.hxx>
20#include <Geom2dGcc_CurveTool.hxx>
21#include <Geom2dGcc_QCurve.hxx>
7fd59977 22#include <gp.hxx>
23#include <gp_Ax2d.hxx>
42cf5bc1 24#include <gp_Circ2d.hxx>
25#include <gp_Pnt2d.hxx>
7fd59977 26#include <gp_Vec2d.hxx>
42cf5bc1 27#include <Standard_Failure.hxx>
28#include <Standard_OutOfRange.hxx>
29#include <StdFail_NotDone.hxx>
7fd59977 30#include <TColStd_Array1OfInteger.hxx>
31#include <TColStd_Array1OfReal.hxx>
578ce4be 32
7fd59977 33//=========================================================================
34// Creation d un cercle tangent a une courbe centre en un point. +
35//=========================================================================
578ce4be 36Geom2dGcc_Circ2dTanCenGeo::
37Geom2dGcc_Circ2dTanCenGeo (const Geom2dGcc_QCurve& Qualified1,
38 const gp_Pnt2d& Pcenter ,
39 const Standard_Real Tolerance ):
7fd59977 40
41//========================================================================
42// Initialisation des champs. +
43//========================================================================
894dba72 44 WellDone(Standard_False),
45 NbrSol(0),
46 cirsol(1, 2),
47 qualifier1(1, 2),
48 pnttg1sol(1, 2),
49 par1sol(1, 2),
50 pararg1(1, 2)
7fd59977 51{
7fd59977 52 Standard_Real Tol = Abs(Tolerance);
53 TColgp_Array1OfPnt2d pTan(1,2);
54 TColStd_Array1OfInteger Index(1,2);
55 TColStd_Array1OfReal theDist2(1,2);
56 TColStd_Array1OfReal theParam(1,2);
57 theDist2(1) = RealLast();
58 theDist2(2) = 0.;
59 Standard_Integer i = 1;
60 Standard_Integer nbsol = 0;
61 gp_Dir2d dirx(1.0,0.0);
62 Standard_Real thePar;
578ce4be 63 Geom2dAdaptor_Curve curve = Qualified1.Qualified();
894dba72 64 Extrema_ExtPC2d distmin(Pcenter, curve, Geom2dGcc_CurveTool::FirstParameter(curve),
65 Geom2dGcc_CurveTool::LastParameter(curve), Tol);
9775fa61 66 if (!distmin.IsDone() ) { throw Standard_Failure(); }
7fd59977 67 Standard_Integer nbext = distmin.NbExt();
9775fa61 68 if(nbext==0) { throw Standard_Failure(); }
7fd59977 69 while (i<=nbext) {
70 thePar = distmin.Point(i).Parameter();
894dba72 71 if (distmin.SquareDistance(i)<theDist2(1)) {
578ce4be 72 theDist2(1) = distmin.SquareDistance(i);
73 theParam(1) = thePar;
74 pTan(1) = distmin.Point(i).Value();
7fd59977 75 }
894dba72 76 if (distmin.SquareDistance(i)>theDist2(2)) {
578ce4be 77 theDist2(2) = distmin.SquareDistance(i);
78 theParam(2) = thePar;
79 pTan(2) = distmin.Point(i).Value();
7fd59977 80 }
81 i++;
82 }
83 if (Index(1) == Index(2)) { nbsol = 1; }
84 else { nbsol = 2; }
85 for (i = 1 ; i <= nbsol; i++) {
86 gp_Pnt2d point1;
87 gp_Vec2d Tan1;
578ce4be 88 Geom2dGcc_CurveTool::D1(curve,theParam(i),point1,Tan1);
7fd59977 89 Standard_Real normetan1 = Tan1.Magnitude();
90 gp_Vec2d Vec1(point1,Pcenter);
91 Standard_Real normevec1 = Vec1.Magnitude();
92 Standard_Real dot1;
93 if (normevec1 >= gp::Resolution() && normetan1 >= gp::Resolution()) {
94 dot1 = Vec1.Dot(Tan1)/(normevec1*normetan1);
95 }
96 else { dot1 = 0.; }
97 Tol = 1.e-12;
98 if (dot1 <= Tol) {
99 Standard_Real Angle1 = Vec1.Angle(Tan1);
100 if (Qualified1.IsUnqualified()||
578ce4be 101 (Qualified1.IsEnclosing()&&Angle1<=0.)||
102 (Qualified1.IsOutside() && Angle1 >= 0.) ||
103 (Qualified1.IsEnclosed() && Angle1 <= 0.)) {
104 NbrSol++;
105 cirsol(NbrSol) = gp_Circ2d(gp_Ax2d(Pcenter,dirx),sqrt (theDist2(i)));
106 qualifier1(NbrSol) = Qualified1.Qualifier();
107 pararg1(NbrSol) = theParam(i);
108 par1sol(NbrSol) = 0.;
109 pnttg1sol(NbrSol) = pTan(i);
110 WellDone = Standard_True;
7fd59977 111 }
112 }
113 }
114}
115
116
117
118//=========================================================================
119
120
578ce4be 121Standard_Boolean Geom2dGcc_Circ2dTanCenGeo::
122IsDone () const { return WellDone; }
7fd59977 123
578ce4be 124Standard_Integer Geom2dGcc_Circ2dTanCenGeo::
125NbSolutions () const { return NbrSol; }
7fd59977 126
578ce4be 127gp_Circ2d Geom2dGcc_Circ2dTanCenGeo::
128ThisSolution (const Standard_Integer Index) const
7fd59977 129{
9775fa61 130 if (Index > NbrSol || Index <= 0) throw Standard_OutOfRange();
7fd59977 131
132 return cirsol(Index);
133}
134
578ce4be 135void Geom2dGcc_Circ2dTanCenGeo::
136WhichQualifier(const Standard_Integer Index ,
137 GccEnt_Position& Qualif1 ) const
7fd59977 138{
9775fa61 139 if (!WellDone) { throw StdFail_NotDone(); }
140 else if (Index <= 0 ||Index > NbrSol) { throw Standard_OutOfRange(); }
7fd59977 141 else {
142 Qualif1 = qualifier1(Index);
143 }
144}
145
578ce4be 146void Geom2dGcc_Circ2dTanCenGeo::
147Tangency1 (const Standard_Integer Index,
148 Standard_Real& ParSol,
149 Standard_Real& ParArg,
150 gp_Pnt2d& PntSol) const{
151 if (!WellDone) {
9775fa61 152 throw StdFail_NotDone();
578ce4be 153 }
154 else if (Index <= 0 ||Index > NbrSol) {
9775fa61 155 throw Standard_OutOfRange();
578ce4be 156 }
157 else {
158 PntSol = gp_Pnt2d(pnttg1sol(Index));
159 ParSol = par1sol(Index);
160 ParArg = pararg1(Index);
161 }
162}
7fd59977 163