0030754: Coding - the array of weights should begin with Lower, not the constant...
[occt.git] / src / Geom / Geom_BSplineCurve.cxx
index 01a3a06..87e6c9f 100644 (file)
 
 #define No_Standard_OutOfRange
 
-#include <Geom_BSplineCurve.ixx>
-#include <gp.hxx>
-#include <ElCLib.hxx>
+
 #include <BSplCLib.hxx>
 #include <BSplCLib_KnotDistribution.hxx>
 #include <BSplCLib_MultDistribution.hxx>
-#include <Standard_NotImplemented.hxx>
+#include <ElCLib.hxx>
+#include <Geom_BSplineCurve.hxx>
+#include <Geom_Geometry.hxx>
+#include <Geom_UndefinedDerivative.hxx>
+#include <gp.hxx>
+#include <gp_Pnt.hxx>
+#include <gp_Trsf.hxx>
+#include <gp_Vec.hxx>
 #include <Standard_ConstructionError.hxx>
+#include <Standard_DimensionError.hxx>
+#include <Standard_DomainError.hxx>
+#include <Standard_NoSuchObject.hxx>
+#include <Standard_NotImplemented.hxx>
 #include <Standard_OutOfRange.hxx>
+#include <Standard_RangeError.hxx>
 #include <Standard_Real.hxx>
+#include <Standard_Type.hxx>
+
+IMPLEMENT_STANDARD_RTTIEXT(Geom_BSplineCurve,Geom_BoundedCurve)
 
 //=======================================================================
 //function : CheckCurveData
 //purpose  : Internal use only
 //=======================================================================
-
 static void CheckCurveData
 (const TColgp_Array1OfPnt&         CPoles,
  const TColStd_Array1OfReal&       CKnots,
@@ -53,36 +65,33 @@ static void CheckCurveData
  const Standard_Boolean            Periodic)
 {
   if (Degree < 1 || Degree > Geom_BSplineCurve::MaxDegree()) {
-    Standard_ConstructionError::Raise();  
+    throw Standard_ConstructionError("BSpline curve: invalid degree");
   }
   
-  if (CPoles.Length() < 2)                Standard_ConstructionError::Raise();
-  if (CKnots.Length() != CMults.Length()) Standard_ConstructionError::Raise();
+  if (CPoles.Length() < 2)                throw Standard_ConstructionError("BSpline curve: at least 2 poles required");
+  if (CKnots.Length() != CMults.Length()) throw Standard_ConstructionError("BSpline curve: Knot and Mult array size mismatch");
   
   for (Standard_Integer I = CKnots.Lower(); I < CKnots.Upper(); I++) {
     if (CKnots (I+1) - CKnots (I) <= Epsilon (Abs(CKnots (I)))) {
-      Standard_ConstructionError::Raise();
+      throw Standard_ConstructionError("BSpline curve: Knots interval values too close");
     }
   }
   
   if (CPoles.Length() != BSplCLib::NbPoles(Degree,Periodic,CMults))
-    Standard_ConstructionError::Raise();
+    throw Standard_ConstructionError("BSpline curve: # Poles and degree mismatch");
 }
 
-//=======================================================================
-//function : Rational
-//purpose  : check rationality of an array of weights
-//=======================================================================
-
-static Standard_Boolean Rational(const TColStd_Array1OfReal& W)
+//! Check rationality of an array of weights
+static Standard_Boolean Rational (const TColStd_Array1OfReal& theWeights)
 {
-  Standard_Integer i, n = W.Length();
-  Standard_Boolean rat = Standard_False;
-  for (i = 1; i < n; i++) {
-    rat =  Abs(W(i) - W(i+1)) > gp::Resolution();
-    if (rat) break;
+  for (Standard_Integer i = theWeights.Lower(); i < theWeights.Upper(); i++)
+  {
+    if (Abs (theWeights[i] - theWeights[i + 1]) > gp::Resolution())
+    {
+      return Standard_True;
+    }
   }
-  return rat;
+  return Standard_False;
 }
 
 //=======================================================================
@@ -125,12 +134,11 @@ Geom_BSplineCurve::Geom_BSplineCurve
 {
   // check
   
-  CheckCurveData (Poles,
-                 Knots,
-                 Mults,
-                 Degree,
-                 Periodic);
-
+  CheckCurveData(Poles,
+                 Knots,
+                 Mults,
+                 Degree,
+                 Periodic);
 
   // copy arrays
 
@@ -145,11 +153,6 @@ Geom_BSplineCurve::Geom_BSplineCurve
   mults->ChangeArray1() = Mults;
 
   UpdateKnots();
-  cachepoles = new TColgp_HArray1OfPnt(1,Degree + 1);
-  parametercache = 0.0e0 ;
-  spanlenghtcache = 0.0e0 ;
-  spanindexcache = 0 ;
-
 }
 
 //=======================================================================
@@ -174,19 +177,19 @@ Geom_BSplineCurve::Geom_BSplineCurve
 
   // check
   
-  CheckCurveData (Poles,
-                 Knots,
-                 Mults,
-                 Degree,
-                 Periodic);
+  CheckCurveData(Poles,
+                 Knots,
+                 Mults,
+                 Degree,
+                 Periodic);
 
   if (Weights.Length() != Poles.Length())
-    Standard_ConstructionError::Raise("Geom_BSplineCurve");
+    throw Standard_ConstructionError("Geom_BSplineCurve: Weights and Poles array size mismatch");
 
   Standard_Integer i;
   for (i = Weights.Lower(); i <= Weights.Upper(); i++) {
     if (Weights(i) <= gp::Resolution())  
-      Standard_ConstructionError::Raise("Geom_BSplineCurve");
+      throw Standard_ConstructionError("Geom_BSplineCurve: Weights values too small");
   }
   
   // check really rational
@@ -197,11 +200,9 @@ Geom_BSplineCurve::Geom_BSplineCurve
   
   poles =  new TColgp_HArray1OfPnt(1,Poles.Length());
   poles->ChangeArray1() = Poles;
-  cachepoles = new TColgp_HArray1OfPnt(1,Degree + 1);
   if (rational) {
     weights =  new TColStd_HArray1OfReal(1,Weights.Length());
     weights->ChangeArray1() = Weights;
-    cacheweights  = new TColStd_HArray1OfReal(1,Degree + 1);
   }
 
   knots = new TColStd_HArray1OfReal(1,Knots.Length());
@@ -211,9 +212,6 @@ Geom_BSplineCurve::Geom_BSplineCurve
   mults->ChangeArray1() = Mults;
 
   UpdateKnots();
-  parametercache = 0.0e0 ;
-  spanlenghtcache = 0.0e0 ;
-  spanindexcache = 0 ;
 }
 
 //=======================================================================
@@ -236,7 +234,7 @@ void Geom_BSplineCurve::IncreaseDegree  (const Standard_Integer Degree)
   if (Degree == deg) return;
   
   if (Degree < deg || Degree > Geom_BSplineCurve::MaxDegree()) {
-    Standard_ConstructionError::Raise();
+    throw Standard_ConstructionError("BSpline curve: IncreaseDegree: bad degree value");
   }
   Standard_Integer FromK1 = FirstUKnotIndex ();
   Standard_Integer ToK2   = LastUKnotIndex  ();
@@ -256,35 +254,21 @@ void Geom_BSplineCurve::IncreaseDegree  (const Standard_Integer Degree)
     new TColStd_HArray1OfInteger(1,nbknots);
 
   Handle(TColStd_HArray1OfReal) nweights;
-  
-  if (IsRational()) {
-    
+  if (IsRational())
+  {
     nweights = new TColStd_HArray1OfReal(1,npoles->Upper());
-    
-    BSplCLib::IncreaseDegree
-      (deg,Degree, periodic,
-       poles->Array1(),weights->Array1(),
-       knots->Array1(),mults->Array1(),
-       npoles->ChangeArray1(),nweights->ChangeArray1(),
-       nknots->ChangeArray1(),nmults->ChangeArray1());
   }
-  else {
-    BSplCLib::IncreaseDegree
-      (deg,Degree, periodic,
-       poles->Array1(),BSplCLib::NoWeights(),
-       knots->Array1(),mults->Array1(),
-       npoles->ChangeArray1(),
-       *((TColStd_Array1OfReal*) NULL),
-       nknots->ChangeArray1(),nmults->ChangeArray1());
-  }
-
+  BSplCLib::IncreaseDegree (deg, Degree, periodic,
+                            poles->Array1(), !nweights.IsNull() ? &weights->Array1() : BSplCLib::NoWeights(),
+                            knots->Array1(), mults->Array1(),
+                            npoles->ChangeArray1(), !nweights.IsNull() ? &nweights->ChangeArray1() : BSplCLib::NoWeights(),
+                            nknots->ChangeArray1(),nmults->ChangeArray1());
   deg     = Degree;
   poles   = npoles;
   weights = nweights;
   knots   = nknots;
   mults   = nmults;
   UpdateKnots();
-  
 }
 
 //=======================================================================
@@ -370,8 +354,8 @@ void  Geom_BSplineCurve::InsertKnots(const TColStd_Array1OfReal& Knots,
 
   if (!BSplCLib::PrepareInsertKnots(deg,periodic,
                                    knots->Array1(),mults->Array1(),
-                                   Knots,Mults,nbpoles,nbknots,Epsilon,Add))
-    Standard_ConstructionError::Raise("Geom_BSplineCurve::InsertKnots");
+                                   Knots,&Mults,nbpoles,nbknots,Epsilon,Add))
+    throw Standard_ConstructionError("Geom_BSplineCurve::InsertKnots");
 
   if (nbpoles == poles->Length()) return;
 
@@ -384,34 +368,24 @@ void  Geom_BSplineCurve::InsertKnots(const TColStd_Array1OfReal& Knots,
     nmults = new TColStd_HArray1OfInteger(1,nbknots);
   }
 
-  if (rational) {
-    Handle(TColStd_HArray1OfReal) nweights = 
-      new TColStd_HArray1OfReal(1,nbpoles);
-    BSplCLib::InsertKnots(deg,periodic,
-                         poles->Array1(), weights->Array1(),
-                         knots->Array1(), mults->Array1(),
-                         Knots, Mults,
-                         npoles->ChangeArray1(), nweights->ChangeArray1(),
-                         nknots->ChangeArray1(), nmults->ChangeArray1(),
-                         Epsilon, Add);
-    weights = nweights;
-  }
-  else {
-    BSplCLib::InsertKnots(deg,periodic,
-                         poles->Array1(), BSplCLib::NoWeights(),
-                         knots->Array1(), mults->Array1(),
-                         Knots, Mults,
-                         npoles->ChangeArray1(),
-                         *((TColStd_Array1OfReal*) NULL),
-                         nknots->ChangeArray1(), nmults->ChangeArray1(),
-                         Epsilon, Add);
+  Handle(TColStd_HArray1OfReal) nweights;
+  if (rational)
+  {
+    nweights = new TColStd_HArray1OfReal(1,nbpoles);
   }
 
+  BSplCLib::InsertKnots (deg, periodic,
+                         poles->Array1(), !nweights.IsNull() ? &weights->Array1() : BSplCLib::NoWeights(),
+                         knots->Array1(), mults->Array1(),
+                         Knots, &Mults,
+                         npoles->ChangeArray1(), !nweights.IsNull() ? &nweights->ChangeArray1() : BSplCLib::NoWeights(),
+                         nknots->ChangeArray1(), nmults->ChangeArray1(),
+                         Epsilon, Add);
+  weights = nweights;
   poles = npoles;
   knots = nknots;
   mults = nmults;
   UpdateKnots();
-
 }
 
 //=======================================================================
@@ -429,10 +403,10 @@ Standard_Boolean  Geom_BSplineCurve::RemoveKnot(const Standard_Integer Index,
   Standard_Integer I2  = LastUKnotIndex  ();
 
   if ( !periodic && (Index <= I1 || Index >= I2) ) {
-    Standard_OutOfRange::Raise();
+    throw Standard_OutOfRange("BSpline curve: RemoveKnot: index out of range");
   }
   else if ( periodic  && (Index < I1 || Index > I2)) {
-    Standard_OutOfRange::Raise();
+    throw Standard_OutOfRange("BSpline curve: RemoveKnot: index out of range");
   }
   
   const TColgp_Array1OfPnt   & oldpoles   = poles->Array1();
@@ -451,31 +425,23 @@ Standard_Boolean  Geom_BSplineCurve::RemoveKnot(const Standard_Integer Index,
     nmults = new TColStd_HArray1OfInteger(1,knots->Length()-1);
   }
 
-  if (IsRational()) {
-    Handle(TColStd_HArray1OfReal) nweights = 
-      new TColStd_HArray1OfReal(1,npoles->Length());
-    if (!BSplCLib::RemoveKnot
-       (Index, M, deg, periodic,
-        poles->Array1(),weights->Array1(), 
-        knots->Array1(),mults->Array1(),
-        npoles->ChangeArray1(), nweights->ChangeArray1(),
-        nknots->ChangeArray1(),nmults->ChangeArray1(),
-        Tolerance))
-      return Standard_False;
-    weights = nweights;
+  Handle(TColStd_HArray1OfReal) nweights;
+  if (IsRational())
+  {
+    nweights = new TColStd_HArray1OfReal(1,npoles->Length());
   }
-  else {
-    if (!BSplCLib::RemoveKnot
-       (Index, M, deg, periodic,
-        poles->Array1(), BSplCLib::NoWeights(),
-        knots->Array1(),mults->Array1(),
-        npoles->ChangeArray1(),
-        *((TColStd_Array1OfReal*) NULL),
-        nknots->ChangeArray1(),nmults->ChangeArray1(),
-        Tolerance))
-      return Standard_False;
+
+  if (!BSplCLib::RemoveKnot (Index, M, deg, periodic,
+                             poles->Array1(), !nweights.IsNull() ? &weights->Array1() : BSplCLib::NoWeights(),
+                             knots->Array1(),mults->Array1(),
+                             npoles->ChangeArray1(), !nweights.IsNull() ? &nweights->ChangeArray1() : BSplCLib::NoWeights(),
+                             nknots->ChangeArray1(),nmults->ChangeArray1(),
+                             Tolerance))
+  {
+    return Standard_False;
   }
-  
+
+  weights = nweights;
   poles = npoles;
   knots = nknots;
   mults = nmults;
@@ -522,10 +488,11 @@ Standard_Real Geom_BSplineCurve::ReversedParameter
 //=======================================================================
 
 void Geom_BSplineCurve::Segment(const Standard_Real U1,
-                               const Standard_Real U2)
+                                const Standard_Real U2,
+                                const Standard_Real theTolerance)
 {
-  Standard_DomainError_Raise_if ( U2 < U1,
-                                "Geom_BSplineCurve::Segment");
+  if (U2 < U1)
+    throw Standard_DomainError("Geom_BSplineCurve::Segment");
   
   Standard_Real NewU1, NewU2;
   Standard_Real U,DU=0,aDDU=0;
@@ -539,9 +506,9 @@ void Geom_BSplineCurve::Segment(const Standard_Real U1,
   if (periodic) {
     Standard_Real Period = LastParameter() - FirstParameter();
     DU = U2 - U1;
-    while (DU > Period)
-      DU -= Period;
-    if (DU <= Epsilon(Period))
+    if (DU - Period > Precision::PConfusion())
+      throw Standard_DomainError("Geom_BSplineCurve::Segment");
+    if (DU > Period)
       DU = Period;
     aDDU = DU;
   }
@@ -570,7 +537,7 @@ void Geom_BSplineCurve::Segment(const Standard_Real U1,
   AbsUMax = Max(AbsUMax, Max(Abs(FirstParameter()),Abs(LastParameter())));
 //  Modified by Sergey KHROMOV - Fri Apr 11 12:15:40 2003 End
 
-  Standard_Real Eps = 100. * Epsilon(AbsUMax);
+  Standard_Real Eps = Max(Epsilon(AbsUMax), theTolerance);
 
   InsertKnots( Knots, Mults, Eps);
 
@@ -598,7 +565,7 @@ void Geom_BSplineCurve::Segment(const Standard_Real U1,
 
   BSplCLib::LocateParameter(deg,knots->Array1(),mults->Array1(),
                            NewU2,periodic,FromU1,ToU2,index2,U);
-  if ( Abs(knots->Value(index2+1)-U) <= Eps)
+  if ( Abs(knots->Value(index2+1)-U) <= Eps || index2 == index1)
     index2++;
   
   Standard_Integer nbknots = index2 - index1 + 1;
@@ -682,20 +649,20 @@ void Geom_BSplineCurve::SetKnot
 (const Standard_Integer Index,
  const Standard_Real K)
 {
-  if (Index < 1 || Index > knots->Length())     Standard_OutOfRange::Raise();
+  if (Index < 1 || Index > knots->Length())     throw Standard_OutOfRange("BSpline curve: SetKnot: Index and #knots mismatch");
   Standard_Real DK = Abs(Epsilon (K));
   if (Index == 1) { 
-    if (K >= knots->Value(2) - DK) Standard_ConstructionError::Raise();
+    if (K >= knots->Value(2) - DK) throw Standard_ConstructionError("BSpline curve: SetKnot: K out of range");
   }
   else if (Index == knots->Length()) {
     if (K <= knots->Value (knots->Length()-1) + DK)  {
-      Standard_ConstructionError::Raise();
+      throw Standard_ConstructionError("BSpline curve: SetKnot: K out of range");
     }
   }
   else {
     if (K <= knots->Value(Index-1) + DK ||
        K >= knots->Value(Index+1) - DK ) {
-      Standard_ConstructionError::Raise();
+      throw Standard_ConstructionError("BSpline curve: SetKnot: K out of range");
     }
   }
   if (K != knots->Value (Index)) {
@@ -782,14 +749,15 @@ void Geom_BSplineCurve::SetPeriodic ()
 
 void Geom_BSplineCurve::SetOrigin(const Standard_Integer Index)
 {
-  Standard_NoSuchObject_Raise_if( !periodic,
-                                "Geom_BSplineCurve::SetOrigin");
+  if (!periodic)
+    throw Standard_NoSuchObject("Geom_BSplineCurve::SetOrigin");
+
   Standard_Integer i,k;
   Standard_Integer first = FirstUKnotIndex();
   Standard_Integer last  = LastUKnotIndex();
 
-  Standard_DomainError_Raise_if( (Index < first) || (Index > last),
-                               "Geom_BSplineCurve::SetOrigine");
+  if ((Index < first) || (Index > last))
+    throw Standard_DomainError("Geom_BSplineCurve::SetOrigin");
 
   Standard_Integer nbknots = knots->Length();
   Standard_Integer nbpoles = poles->Length();
@@ -871,8 +839,8 @@ void Geom_BSplineCurve::SetOrigin(const Standard_Integer Index)
 void Geom_BSplineCurve::SetOrigin(const Standard_Real U,
                                  const Standard_Real Tol)
 {
-  Standard_NoSuchObject_Raise_if( !periodic,
-                                "Geom_BSplineCurve::SetOrigin");
+  if (!periodic)
+    throw Standard_NoSuchObject("Geom_BSplineCurve::SetOrigin");
   //U est il dans la period.
   Standard_Real uf = FirstParameter(), ul = LastParameter();
   Standard_Real u = U, period = ul - uf;
@@ -930,27 +898,16 @@ void Geom_BSplineCurve::SetNotPeriodic ()
       = new TColStd_HArray1OfInteger(1,NbKnots);
     
     Handle(TColStd_HArray1OfReal) nweights;
-    
-    if (IsRational()) {
-      
+    if (IsRational())
+    {
       nweights = new TColStd_HArray1OfReal(1,NbPoles);
-      
-      BSplCLib::Unperiodize
-       (deg,mults->Array1(),knots->Array1(),poles->Array1(),
-        weights->Array1(),nmults->ChangeArray1(),
-        nknots->ChangeArray1(),npoles->ChangeArray1(),
-        nweights->ChangeArray1());
-      
-    }
-    else {
-      
-      BSplCLib::Unperiodize
-       (deg,mults->Array1(),knots->Array1(),poles->Array1(),
-        BSplCLib::NoWeights(),nmults->ChangeArray1(),
-        nknots->ChangeArray1(),npoles->ChangeArray1(),
-        *((TColStd_Array1OfReal*) NULL));
-      
     }
+
+    BSplCLib::Unperiodize (deg,
+                           mults->Array1(), knots->Array1(), poles->Array1(),
+                           !nweights.IsNull() ? &weights->Array1() : BSplCLib::NoWeights(),
+                           nmults->ChangeArray1(), nknots->ChangeArray1(), npoles->ChangeArray1(),
+                           !nweights.IsNull() ? &nweights->ChangeArray1() : BSplCLib::NoWeights());
     poles   = npoles;
     weights = nweights;
     mults   = nmults;
@@ -971,10 +928,9 @@ void Geom_BSplineCurve::SetPole
 (const Standard_Integer Index,
  const gp_Pnt& P)
 {
-  if (Index < 1 || Index > poles->Length()) Standard_OutOfRange::Raise();
+  if (Index < 1 || Index > poles->Length()) throw Standard_OutOfRange("BSpline curve: SetPole: index and #pole mismatch");
   poles->SetValue (Index, P);
   maxderivinvok = 0;
-  InvalidateCache() ;
 }
 
 //=======================================================================
@@ -1000,9 +956,9 @@ void Geom_BSplineCurve::SetWeight
 (const Standard_Integer Index,
  const Standard_Real W)
 {
-  if (Index < 1 || Index > poles->Length())   Standard_OutOfRange::Raise();
+  if (Index < 1 || Index > poles->Length())   throw Standard_OutOfRange("BSpline curve: SetWeight: Index and #pole mismatch");
 
-  if (W <= gp::Resolution ())     Standard_ConstructionError::Raise();
+  if (W <= gp::Resolution ())     throw Standard_ConstructionError("BSpline curve: SetWeight: Weight too small");
 
 
   Standard_Boolean rat = IsRational() || (Abs(W - 1.) > gp::Resolution());
@@ -1023,7 +979,6 @@ void Geom_BSplineCurve::SetWeight
     rational = !weights.IsNull();
   }
   maxderivinvok = 0;
-  InvalidateCache() ;
 }
 
 //=======================================================================
@@ -1032,27 +987,26 @@ void Geom_BSplineCurve::SetWeight
 //=======================================================================
 
 void Geom_BSplineCurve::MovePoint(const Standard_Real U,
-                                 const gp_Pnt& P,
-                                 const Standard_Integer Index1,
-                                 const Standard_Integer Index2,
-                                 Standard_Integer& FirstModifiedPole,
-                                 Standard_Integer& LastmodifiedPole)
+                                  const gp_Pnt& P,
+                                  const Standard_Integer Index1,
+                                  const Standard_Integer Index2,
+                                  Standard_Integer& FirstModifiedPole,
+                                  Standard_Integer& LastmodifiedPole)
 {
   if (Index1 < 1 || Index1 > poles->Length() || 
       Index2 < 1 || Index2 > poles->Length() || Index1 > Index2) {
-    Standard_OutOfRange::Raise();
+    throw Standard_OutOfRange("BSpline curve: MovePoint: Index and #pole mismatch");
   }
   TColgp_Array1OfPnt npoles(1, poles->Length());
   gp_Pnt P0;
   D0(U, P0);
   gp_Vec Displ(P0, P);
-  BSplCLib::MovePoint(U, Displ, Index1, Index2, deg, rational, poles->Array1(), 
-                     weights->Array1(), flatknots->Array1(), 
-                     FirstModifiedPole, LastmodifiedPole, npoles);
+  BSplCLib::MovePoint (U, Displ, Index1, Index2, deg, poles->Array1(),
+                       rational ? &weights->Array1() : BSplCLib::NoWeights(), flatknots->Array1(),
+                       FirstModifiedPole, LastmodifiedPole, npoles);
   if (FirstModifiedPole) {
     poles->ChangeArray1() = npoles;
     maxderivinvok = 0;
-    InvalidateCache() ;
   }
 }
 
@@ -1061,14 +1015,13 @@ void Geom_BSplineCurve::MovePoint(const Standard_Real U,
 //purpose  : 
 //=======================================================================
 
-void Geom_BSplineCurve::
-MovePointAndTangent(const Standard_Real U,
-                   const gp_Pnt&       P,
-                   const gp_Vec&       Tangent,
-                   const Standard_Real    Tolerance,
-                   const Standard_Integer StartingCondition,
-                   const Standard_Integer EndingCondition,
-                   Standard_Integer&      ErrorStatus) 
+void Geom_BSplineCurve::MovePointAndTangent(const Standard_Real    U,
+                                            const gp_Pnt&          P,
+                                            const gp_Vec&          Tangent,
+                                            const Standard_Real    Tolerance,
+                                            const Standard_Integer StartingCondition,
+                                            const Standard_Integer EndingCondition,
+                                            Standard_Integer&      ErrorStatus) 
 {
   Standard_Integer ii ;
   if (IsPeriodic()) {
@@ -1086,26 +1039,23 @@ MovePointAndTangent(const Standard_Real U,
      delta_derivative) ;
   gp_Vec delta(P0, P);
   for (ii = 1 ; ii <= 3 ; ii++) {
-    delta_derivative.SetCoord(ii, 
-                             Tangent.Coord(ii)- delta_derivative.Coord(ii)) ;
+    delta_derivative.SetCoord(ii, Tangent.Coord(ii)-delta_derivative.Coord(ii));
   }
   BSplCLib::MovePointAndTangent(U,
-                               delta,
-                               delta_derivative,
-                               Tolerance,
-                               deg,
-                               rational,
-                               StartingCondition,
-                               EndingCondition,
-                               poles->Array1(), 
-                               weights->Array1(), 
-                               flatknots->Array1(), 
-                               new_poles,
-                               ErrorStatus) ;
+                                delta,
+                                delta_derivative,
+                                Tolerance,
+                                deg,
+                                StartingCondition,
+                                EndingCondition,
+                                poles->Array1(), 
+                                rational ? &weights->Array1() : BSplCLib::NoWeights(),
+                                flatknots->Array1(), 
+                                new_poles,
+                                ErrorStatus) ;
   if (!ErrorStatus) {
     poles->ChangeArray1() = new_poles;
     maxderivinvok = 0;
-    InvalidateCache() ;
   }
 }
 
@@ -1119,11 +1069,11 @@ void Geom_BSplineCurve::UpdateKnots()
   rational = !weights.IsNull();
 
   Standard_Integer MaxKnotMult = 0;
-  BSplCLib::KnotAnalysis (deg, 
-               periodic,
-               knots->Array1(), 
-               mults->Array1(), 
-               knotSet, MaxKnotMult);
+  BSplCLib::KnotAnalysis(deg, 
+                         periodic,
+                         knots->Array1(), 
+                         mults->Array1(), 
+                         knotSet, MaxKnotMult);
   
   if (knotSet == GeomAbs_Uniform && !periodic)  {
     flatknots = knots;
@@ -1132,10 +1082,10 @@ void Geom_BSplineCurve::UpdateKnots()
     flatknots = new TColStd_HArray1OfReal 
       (1, BSplCLib::KnotSequenceLength(mults->Array1(),deg,periodic));
 
-    BSplCLib::KnotSequence (knots->Array1(), 
-                           mults->Array1(),
-                           deg,periodic,
-                           flatknots->ChangeArray1());
+    BSplCLib::KnotSequence(knots->Array1(), 
+                           mults->Array1(),
+                           deg,periodic,
+                           flatknots->ChangeArray1());
   }
   
   if (MaxKnotMult == 0)  smooth = GeomAbs_CN;
@@ -1148,36 +1098,6 @@ void Geom_BSplineCurve::UpdateKnots()
       default :  smooth = GeomAbs_C3;   break;
     }
   }
-  InvalidateCache() ;
-}
-
-//=======================================================================
-//function : Invalidate the Cache
-//purpose  : as the name says
-//=======================================================================
-
-void Geom_BSplineCurve::InvalidateCache() 
-{
-  validcache = 0 ;
-}
-
-//=======================================================================
-//function : check if the Cache is valid
-//purpose  : as the name says
-//=======================================================================
-
-Standard_Boolean Geom_BSplineCurve::IsCacheValid
-(const Standard_Real  U)  const 
-{
-  //Roman Lygin 26.12.08, performance improvements
-  //1. avoided using NewParameter = (U - parametercache) / spanlenghtcache
-  //to check against [0, 1), as division is CPU consuming
-  //2. minimized use of if, as branching is also CPU consuming
-  Standard_Real aDelta = U - parametercache;
-
-  return ( validcache &&
-      (aDelta >= 0.0e0) &&
-      ((aDelta < spanlenghtcache) || (spanindexcache == flatknots->Upper() - deg)) );
 }
 
 //=======================================================================
@@ -1200,83 +1120,3 @@ void Geom_BSplineCurve::PeriodicNormalization(Standard_Real&  Parameter) const
   }
 }
 
-//=======================================================================
-//function : Validate the Cache
-//purpose  : that is compute the cache so that it is valid
-//=======================================================================
-
-void Geom_BSplineCurve::ValidateCache(const Standard_Real  Parameter) 
-{
-  Standard_Real NewParameter ;
-  Standard_Integer LocalIndex = 0 ;
-  //
-  // check if the degree did not change
-  //
-  if (cachepoles->Upper() < deg + 1)
-    cachepoles = new TColgp_HArray1OfPnt(1,deg + 1);
-  if (rational)
-  {
-    if (cacheweights.IsNull() || cacheweights->Upper() < deg + 1)
-     cacheweights  = new TColStd_HArray1OfReal(1,deg + 1);
-  }
-  else if (!cacheweights.IsNull())
-    cacheweights.Nullify();
-
-  BSplCLib::LocateParameter(deg,
-                           (flatknots->Array1()),
-                           (BSplCLib::NoMults()),
-                           Parameter,
-                           periodic,
-                           LocalIndex,
-                           NewParameter);
-  spanindexcache = LocalIndex ;
-  if (Parameter == flatknots->Value(LocalIndex + 1)) {
-    
-    LocalIndex += 1 ;
-    parametercache = flatknots->Value(LocalIndex) ;
-    if (LocalIndex == flatknots->Upper() - deg) {
-      //
-      // for the last span if the parameter is outside of 
-      // the domain of the curve than use the last knot
-      // and normalize with the last span Still set the
-      // spanindexcache to flatknots->Upper() - deg so that
-      // the IsCacheValid will know for sure we are extending
-      // the Bspline 
-      //
-      
-      spanlenghtcache = flatknots->Value(LocalIndex - 1) - parametercache ;
-    }
-    else {
-      spanlenghtcache = flatknots->Value(LocalIndex + 1) - parametercache ;
-    }
-  }
-  else {
-    parametercache = flatknots->Value(LocalIndex) ;
-    spanlenghtcache = flatknots->Value(LocalIndex + 1) - parametercache ;
-  }
-  
-  if  (rational) {
-    BSplCLib::BuildCache(parametercache,
-                        spanlenghtcache,
-                        periodic,
-                        deg,
-                        (flatknots->Array1()),
-                        poles->Array1(),
-                        weights->Array1(),
-                        cachepoles->ChangeArray1(),
-                        cacheweights->ChangeArray1()) ;
-  }
-  else {
-    BSplCLib::BuildCache(parametercache,
-                        spanlenghtcache,
-                        periodic,
-                        deg,
-                        (flatknots->Array1()),
-                        poles->Array1(),
-                        *((TColStd_Array1OfReal*) NULL),
-                        cachepoles->ChangeArray1(),
-                        *((TColStd_Array1OfReal*) NULL)) ;
-  }
-  validcache = 1 ;
-}
-