From 1a246afa2e14e0523e574602e76c862b4875c4e7 Mon Sep 17 00:00:00 2001 From: Kirill Gavrilov Date: Mon, 17 Nov 2025 09:58:40 +0000 Subject: [PATCH] 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. --- .../TKMath/BSplCLib/BSplCLib_CacheParams.hxx | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/FoundationClasses/TKMath/BSplCLib/BSplCLib_CacheParams.hxx b/src/FoundationClasses/TKMath/BSplCLib/BSplCLib_CacheParams.hxx index db01e8455c..e3193e40bd 100644 --- a/src/FoundationClasses/TKMath/BSplCLib/BSplCLib_CacheParams.hxx +++ b/src/FoundationClasses/TKMath/BSplCLib/BSplCLib_CacheParams.hxx @@ -15,6 +15,10 @@ #define _BSplCLib_CacheParams_Headerfile #include +#include + +#include +#include //! 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 -- 2.39.5