1 // Created on: 1996-11-08
2 // Created by: Jean Claude VAUTHIER
3 // Copyright (c) 1996-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <Adaptor2d_Curve2d.hxx>
19 #include <Adaptor3d_Curve.hxx>
20 #include <GCPnts_TangentialDeflection.hxx>
22 #include <gp_Pnt2d.hxx>
24 #include <gp_Vec2d.hxx>
26 #include <Precision.hxx>
27 #include <Standard_ConstructionError.hxx>
28 #include <Standard_OutOfRange.hxx>
29 #include <TColStd_Array1OfReal.hxx>
31 inline static void D0 (const Adaptor3d_Curve& C, const Standard_Real U, gp_Pnt& P)
36 inline static void D2 (const Adaptor3d_Curve& C, const Standard_Real U,
37 gp_Pnt& P, gp_Vec& V1, gp_Vec& V2)
43 static void D0 (const Adaptor2d_Curve2d& C, const Standard_Real U, gp_Pnt& PP)
49 PP.SetCoord (X, Y, 0.0);
52 static void D2 (const Adaptor2d_Curve2d& C, const Standard_Real U,
53 gp_Pnt& PP, gp_Vec& VV1, gp_Vec& VV2)
60 PP.SetCoord (X, Y, 0.0);
62 VV1.SetCoord (X, Y, 0.0);
64 VV2.SetCoord (X, Y, 0.0);
67 static Standard_Real EstimAngl(const gp_Pnt& P1, const gp_Pnt& Pm, const gp_Pnt& P2)
69 gp_Vec V1(P1, Pm), V2(Pm, P2);
70 Standard_Real L = V1.Magnitude() * V2.Magnitude();
72 if(L > gp::Resolution())
74 return V1.CrossMagnitude(V2)/L;
83 // Return number of interval of continuity on which theParam is located.
84 // Last parameter is used to increase search speed.
85 static Standard_Integer getIntervalIdx(const Standard_Real theParam,
86 TColStd_Array1OfReal& theIntervs,
87 const Standard_Integer thePreviousIdx)
89 Standard_Integer anIdx;
90 for(anIdx = thePreviousIdx; anIdx < theIntervs.Upper(); anIdx++)
92 if (theParam >= theIntervs(anIdx) &&
93 theParam <= theIntervs(anIdx + 1)) // Inside of anIdx interval.
101 //=======================================================================
102 //function : CPnts_TangentialDeflection
104 //=======================================================================
106 GCPnts_TangentialDeflection::GCPnts_TangentialDeflection () { }
108 //=======================================================================
109 //function : AddPoint
111 //=======================================================================
113 Standard_Integer GCPnts_TangentialDeflection::AddPoint
114 (const gp_Pnt& thePnt,
115 const Standard_Real theParam,
116 const Standard_Boolean theIsReplace)
118 const Standard_Real tol = Precision::PConfusion();
119 Standard_Integer index = -1;
120 const Standard_Integer nb = parameters.Length();
121 for ( Standard_Integer i = 1; index == -1 && i <= nb; i++ )
123 Standard_Real dist = parameters.Value( i ) - theParam;
124 if ( fabs( dist ) <= tol )
129 points.ChangeValue(i) = thePnt;
130 parameters.ChangeValue(i) = theParam;
133 else if ( dist > tol )
135 points.InsertBefore( i, thePnt );
136 parameters.InsertBefore( i, theParam );
142 points.Append( thePnt );
143 parameters.Append( theParam );
144 index = parameters.Length();
149 //=======================================================================
150 //function : ArcAngularStep
152 //=======================================================================
153 Standard_Real GCPnts_TangentialDeflection::ArcAngularStep(
154 const Standard_Real theRadius,
155 const Standard_Real theLinearDeflection,
156 const Standard_Real theAngularDeflection,
157 const Standard_Real theMinLength)
159 Standard_ConstructionError_Raise_if(theRadius < 0.0, "Negative radius");
161 const Standard_Real aPrecision = Precision::Confusion();
163 Standard_Real Du = 0.0, aMinSizeAng = 0.0;
164 if (theRadius > aPrecision)
166 Du = Max(1.0 - (theLinearDeflection / theRadius), 0.0);
168 // It is not suitable to consider min size greater than 1/4 arc len.
169 if (theMinLength > aPrecision)
170 aMinSizeAng = Min(theMinLength / theRadius, M_PI_2);
173 Du = Max(Min(Du, theAngularDeflection), aMinSizeAng);
177 #include <Geom_BezierCurve.hxx>
178 #include <Geom_BSplineCurve.hxx>
179 #include <gp_Circ.hxx>
180 #include <GCPnts_DistFunction.hxx>
181 #define TheCurve Adaptor3d_Curve
182 #define Handle_TheBezierCurve Handle(Geom_BezierCurve)
183 #define Handle_TheBSplineCurve Handle(Geom_BSplineCurve)
184 #define TheMaxCurvLinDist GCPnts_DistFunction
185 #define TheMaxCurvLinDistMV GCPnts_DistFunctionMV
186 #include <GCPnts_TangentialDeflection.gxx>
187 #undef Handle_TheBezierCurve
188 #undef Handle_TheBSplineCurve
190 #undef TheMaxCurvLinDist
191 #undef TheMaxCurvLinDistMV
194 #include <Geom2d_BezierCurve.hxx>
195 #include <Geom2d_BSplineCurve.hxx>
196 #include <gp_Circ2d.hxx>
197 #include <GCPnts_DistFunction2d.hxx>
198 #define TheCurve Adaptor2d_Curve2d
199 #define Handle_TheBezierCurve Handle(Geom2d_BezierCurve)
200 #define Handle_TheBSplineCurve Handle(Geom2d_BSplineCurve)
201 #define TheMaxCurvLinDist GCPnts_DistFunction2d
202 #define TheMaxCurvLinDistMV GCPnts_DistFunction2dMV
203 #include <GCPnts_TangentialDeflection.gxx>
204 #undef Handle_TheBezierCurve
205 #undef Handle_TheBSplineCurve
207 #undef TheMaxCurvLinDist
208 #undef TheMaxCurvLinDistMV