]> OCCT Git - occt.git/commitdiff
0027358: ShapeAnalysis_Curve::GetSamplePoints iteration logic isn't robust
authorrazmyslovich <razmyslovich@volumegraphics.com>
Mon, 12 Sep 2016 10:52:36 +0000 (12:52 +0200)
committerbugmaster <bugmaster@opencascade.com>
Thu, 17 Aug 2017 12:47:39 +0000 (15:47 +0300)
The iterating logic in ShapeAnalysis_Curve::GetSamplePoints() is made more robust: instead of iterative incrementing parameter by adding step, parameter at each point is calculated independently from index.
This avoids possible accumulation of numeric errors, and ensures that generated points are equally spaced and their quantity is respected in all cases.

src/ShapeAnalysis/ShapeAnalysis_Curve.cxx

index e33ae0eb041268954c8012ded8554d9b30b7580e..d97d1f452ec3a5db023cffde2c151ab885ad3ca1 100644 (file)
@@ -1070,9 +1070,8 @@ Standard_Boolean ShapeAnalysis_Curve::GetSamplePoints (const Handle(Geom_Curve)&
 
   GeomAdaptor_Curve GAC(curve);
   Standard_Real step = ( last - first ) / (Standard_Real)( nbp - 1 );
-  Standard_Real par = first, stop = last - 0.5 * step;
-  for ( ; par < stop; par += step )
-    seq.Append(GAC.Value(par));
+  for (Standard_Integer i = 0; i < nbp - 1; ++i)
+    seq.Append(GAC.Value(first + step * i));
   seq.Append(GAC.Value(last));
   return Standard_True;
 }
@@ -1093,9 +1092,8 @@ Standard_Boolean ShapeAnalysis_Curve::GetSamplePoints (const Handle(Geom2d_Curve
   //-- Attention aux bsplines rationnelles de degree 3. (bouts de cercles entre autres)
   if (nbs > 2) nbs*=4;
   Standard_Real step = ( last - first ) / (Standard_Real)( nbs - 1 );
-  Standard_Real par = first, stop = last - 0.5 * step;
-  for ( ; par < stop; par += step )
-    seq.Append(C.Value(par));
+  for (Standard_Integer i = 0; i < nbs - 1; ++i)
+    seq.Append(C.Value(first + step * i));
   seq.Append(C.Value(last));
   return Standard_True;
 /*