Warning, file /include/opencascade/BSplCLib_CacheParams.hxx was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef _BSplCLib_CacheParams_Headerfile
0015 #define _BSplCLib_CacheParams_Headerfile
0016
0017 #include <BSplCLib.hxx>
0018
0019 #include <algorithm>
0020 #include <cmath>
0021
0022
0023
0024
0025 struct BSplCLib_CacheParams
0026 {
0027 const int Degree;
0028 const bool IsPeriodic;
0029 const double FirstParameter;
0030 const double LastParameter;
0031
0032 const int SpanIndexMin;
0033 const int SpanIndexMax;
0034
0035 double SpanStart;
0036 double SpanLength;
0037 int SpanIndex;
0038
0039
0040
0041
0042
0043 BSplCLib_CacheParams(int theDegree,
0044 bool thePeriodic,
0045 const NCollection_Array1<double>& theFlatKnots)
0046 : Degree(theDegree),
0047 IsPeriodic(thePeriodic),
0048 FirstParameter(theFlatKnots.Value(theFlatKnots.Lower() + theDegree)),
0049 LastParameter(theFlatKnots.Value(theFlatKnots.Upper() - theDegree)),
0050 SpanIndexMin(theFlatKnots.Lower() + theDegree),
0051 SpanIndexMax(theFlatKnots.Upper() - theDegree - 1),
0052 SpanStart(0.0),
0053 SpanLength(0.0),
0054 SpanIndex(0)
0055 {
0056 }
0057
0058
0059
0060 double PeriodicNormalization(double theParameter) const noexcept
0061 {
0062 if (IsPeriodic)
0063 {
0064 const double aPeriod = LastParameter - FirstParameter;
0065 if (theParameter < FirstParameter)
0066 {
0067 const double aScale = std::trunc((FirstParameter - theParameter) / aPeriod);
0068 return theParameter + aPeriod * (aScale + 1.0);
0069 }
0070 if (theParameter > LastParameter)
0071 {
0072 const double aScale = std::trunc((theParameter - LastParameter) / aPeriod);
0073 return theParameter - aPeriod * (aScale + 1.0);
0074 }
0075 }
0076 return theParameter;
0077 }
0078
0079
0080
0081 bool IsCacheValid(double theParameter) const noexcept
0082 {
0083 const double aNewParam = PeriodicNormalization(theParameter);
0084 const double aDelta = aNewParam - SpanStart;
0085 if ((aDelta < 0.0 && SpanIndex != SpanIndexMin)
0086 || (aDelta >= SpanLength && SpanIndex != SpanIndexMax))
0087 {
0088 return false;
0089 }
0090
0091 if (SpanIndex == SpanIndexMax)
0092 return true;
0093
0094
0095
0096 const double anEps = Epsilon((std::min)(std::fabs(LastParameter), std::fabs(aNewParam)));
0097 const double aDeltaToNext = std::fabs(aDelta - SpanLength);
0098 return aDeltaToNext > anEps;
0099 }
0100
0101
0102
0103
0104 void LocateParameter(double& theParameter, const NCollection_Array1<double>& theFlatKnots)
0105 {
0106 SpanIndex = 0;
0107 BSplCLib::LocateParameter(Degree,
0108 theFlatKnots,
0109 BSplCLib::NoMults(),
0110 theParameter,
0111 IsPeriodic,
0112 SpanIndex,
0113 theParameter);
0114 SpanStart = theFlatKnots.Value(SpanIndex);
0115 SpanLength = theFlatKnots.Value(SpanIndex + 1) - SpanStart;
0116 }
0117
0118
0119 BSplCLib_CacheParams(const BSplCLib_CacheParams&) = delete;
0120 BSplCLib_CacheParams& operator=(const BSplCLib_CacheParams&) = delete;
0121 };
0122
0123 #endif