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 // Return number of interval of continuity on which theParam is located.
68 // Last parameter is used to increase search speed.
69 static Standard_Integer getIntervalIdx(const Standard_Real theParam,
70 TColStd_Array1OfReal& theIntervs,
71 const Standard_Integer thePreviousIdx)
73 Standard_Integer anIdx;
74 for(anIdx = thePreviousIdx; anIdx < theIntervs.Upper(); anIdx++)
76 if (theParam >= theIntervs(anIdx) &&
77 theParam <= theIntervs(anIdx + 1)) // Inside of anIdx interval.
85 //=======================================================================
86 //function : CPnts_TangentialDeflection
88 //=======================================================================
90 GCPnts_TangentialDeflection::GCPnts_TangentialDeflection () { }
92 //=======================================================================
95 //=======================================================================
97 Standard_Integer GCPnts_TangentialDeflection::AddPoint
98 (const gp_Pnt& thePnt,
99 const Standard_Real theParam,
100 const Standard_Boolean theIsReplace)
102 const Standard_Real tol = Precision::PConfusion();
103 Standard_Integer index = -1;
104 const Standard_Integer nb = parameters.Length();
105 for ( Standard_Integer i = 1; index == -1 && i <= nb; i++ )
107 Standard_Real dist = parameters.Value( i ) - theParam;
108 if ( fabs( dist ) <= tol )
113 points.ChangeValue(i) = thePnt;
114 parameters.ChangeValue(i) = theParam;
117 else if ( dist > tol )
119 points.InsertBefore( i, thePnt );
120 parameters.InsertBefore( i, theParam );
126 points.Append( thePnt );
127 parameters.Append( theParam );
128 index = parameters.Length();
133 //=======================================================================
134 //function : ArcAngularStep
136 //=======================================================================
137 Standard_Real GCPnts_TangentialDeflection::ArcAngularStep(
138 const Standard_Real theRadius,
139 const Standard_Real theLinearDeflection,
140 const Standard_Real theAngularDeflection,
141 const Standard_Real theMinLength)
143 Standard_ConstructionError_Raise_if(theRadius < 0.0, "Negative radius");
145 const Standard_Real aPrecision = Precision::Confusion();
147 Standard_Real Du = 0.0, aMinSizeAng = 0.0;
148 if (theRadius > aPrecision)
150 Du = Max(1.0 - (theLinearDeflection / theRadius), 0.0);
152 // It is not suitable to consider min size greater than 1/4 arc len.
153 if (theMinLength > aPrecision)
154 aMinSizeAng = Min(theMinLength / theRadius, M_PI_2);
157 Du = Max(Min(Du, theAngularDeflection), aMinSizeAng);
161 #include <Geom_BezierCurve.hxx>
162 #include <Geom_BSplineCurve.hxx>
163 #include <gp_Circ.hxx>
164 #define TheCurve Adaptor3d_Curve
165 #define Handle_TheBezierCurve Handle(Geom_BezierCurve)
166 #define Handle_TheBSplineCurve Handle(Geom_BSplineCurve)
167 #include <GCPnts_TangentialDeflection.gxx>
168 #undef Handle_TheBezierCurve
169 #undef Handle_TheBSplineCurve
173 #include <Geom2d_BezierCurve.hxx>
174 #include <Geom2d_BSplineCurve.hxx>
175 #include <gp_Circ2d.hxx>
176 #define TheCurve Adaptor2d_Curve2d
177 #define Handle_TheBezierCurve Handle(Geom2d_BezierCurve)
178 #define Handle_TheBSplineCurve Handle(Geom2d_BSplineCurve)
179 #include <GCPnts_TangentialDeflection.gxx>
180 #undef Handle_TheBezierCurve
181 #undef Handle_TheBSplineCurve