Modeling, BSplineCache - Improve parameter validation logic #829

- Enhanced the parameter validation logic in BSplCLib_CacheParams to ensure correct handling of edge cases.
- Added checks for floating point precision when determining if the next knot should be used.
- Improved code readability by restructuring the return conditions.
This commit is contained in:
Kirill Gavrilov
2025-11-17 09:58:40 +00:00
committed by dpasukhi
parent c2375c78a6
commit 1a246afa2e

View File

@@ -15,6 +15,10 @@
#define _BSplCLib_CacheParams_Headerfile
#include <BSplCLib.hxx>
#include <Standard_Real.hxx>
#include <algorithm>
#include <cmath>
//! Simple structure containing parameters describing parameterization
//! of a B-spline curve or a surface in one direction (U or V),
@@ -80,8 +84,23 @@ struct BSplCLib_CacheParams
{
Standard_Real aNewParam = PeriodicNormalization(theParameter);
Standard_Real aDelta = aNewParam - SpanStart;
return ((aDelta >= 0.0 || SpanIndex == SpanIndexMin)
&& (aDelta < SpanLength || SpanIndex == SpanIndexMax));
if (!((aDelta >= 0.0 || SpanIndex == SpanIndexMin)
&& (aDelta < SpanLength || SpanIndex == SpanIndexMax)))
{
return false;
}
if (SpanIndex == SpanIndexMax)
return true;
// from BSplCLib::LocateParameter() check hitting of the next knot
// within double floating point precision
const double anEps = Epsilon((std::min)(std::fabs(LastParameter), std::fabs(aNewParam)));
const double aDeltaToNext = std::fabs(aDelta - SpanLength);
if (aDeltaToNext <= anEps)
return false; // next knot should be used instead
return true;
}
//! Computes span for the specified parameter