]> OCCT Git - occt.git/commitdiff
Modeling, BSplineCache - Improve parameter validation logic #829
authorKirill Gavrilov <kirill@sview.ru>
Mon, 17 Nov 2025 09:58:40 +0000 (09:58 +0000)
committerdpasukhi <dpasukhi@opencascade.com>
Mon, 17 Nov 2025 11:14:05 +0000 (11:14 +0000)
- 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.

src/FoundationClasses/TKMath/BSplCLib/BSplCLib_CacheParams.hxx

index db01e8455c042b77af1d8e2a355bd3b0aacf97b9..e3193e40bd0cf7b797fcd8afbec887157c4208eb 100644 (file)
 #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