const Standard_Integer aNbp = lastP - firstP + 1;
+ // The first parameter should always be zero according to all the logic below,
+ // so division by any value will give zero anyway, so it should never be scaled
+ // to avoid case when there is only one parameter in the array thus division by zero happens.
+ TheParameters(firstP) = 0.0;
if (aNbp == 2) {
- TheParameters(firstP) = 0.0;
TheParameters(lastP) = 1.0;
}
else if (Par == Approx_ChordLength || Par == Approx_Centripetal)
if (nbP3d == 0) mynbP3d = 1;
if (nbP2d == 0) mynbP2d = 1;
- TheParameters(firstP) = 0.0;
dist = 0.0;
TColgp_Array1OfPnt tabP(1, mynbP3d);
TColgp_Array1OfPnt tabPP(1, mynbP3d);
TheParameters(i) = TheParameters(i - 1) + Sqrt(dist);
}
}
- for (i = firstP; i <= lastP; i++) TheParameters(i) /= TheParameters(lastP);
+ for (i = firstP + 1; i <= lastP; i++) TheParameters(i) /= TheParameters(lastP);
}
else {
- for (i = firstP; i <= lastP; i++) {
+ for (i = firstP + 1; i <= lastP; i++) {
TheParameters(i) = (Standard_Real(i) - firstP) /
(Standard_Real(lastP - Standard_Real(firstP)));
}
//
// this should be always invertible if ii is correctly computed
//
- Factor = (Parameter - FlatKnots(ii - qq + pp + 1))
- / (FlatKnots(ii + pp) - FlatKnots(ii - qq + pp + 1)) ;
+ const Standard_Real aScale = (FlatKnots(ii + pp) - FlatKnots(ii - qq + pp + 1));
+ if (Abs (aScale) < gp::Resolution())
+ {
+ return 2;
+ }
+
+ Factor = (Parameter - FlatKnots(ii - qq + pp + 1)) / aScale;
Saved = Factor * BsplineBasis(1,pp) ;
BsplineBasis(1,pp) *= (1.0e0 - Factor) ;
BsplineBasis(1,pp) += BsplineBasis(1,qq) ;
}
for (pp = 1 ; pp <= qq - 1 ; pp++) {
- Inverse = 1.0e0 / (FlatKnots(ii + pp) - FlatKnots(ii - qq + pp + 1)) ;
+ const Standard_Real aScale = (FlatKnots(ii + pp) - FlatKnots(ii - qq + pp + 1));
+ if (Abs (aScale) < gp::Resolution())
+ {
+ return 2;
+ }
+
+ Inverse = 1.0e0 / aScale;
Factor = (Parameter - FlatKnots(ii - qq + pp + 1)) * Inverse ;
Saved = Factor * BsplineBasis(1,pp) ;
BsplineBasis(1,pp) *= (1.0e0 - Factor) ;