0027234: Code duplication: Convert_CompBezierCurvesToBSplineCurve* in ShapeConstruct
[occt.git] / src / Convert / Convert_CompBezierCurvesToBSplineCurve.cxx
index bec1f3b..24b766f 100644 (file)
 // Alternatively, this file may be used under the terms of Open CASCADE
 // commercial license or contractual agreement.
 
-#include <Convert_CompBezierCurvesToBSplineCurve.ixx>
 
-#include <Precision.hxx>
 #include <BSplCLib.hxx>
-#include <PLib.hxx>
-#include <gp_Pnt.hxx>
+#include <Convert_CompBezierCurvesToBSplineCurve.hxx>
 #include <gp.hxx>
+#include <gp_Pnt.hxx>
 #include <gp_Vec.hxx>
+#include <PLib.hxx>
+#include <Precision.hxx>
+#include <Standard_ConstructionError.hxx>
 #include <TColgp_HArray1OfPnt.hxx>
 
-
 //=======================================================================
 //function : Convert_CompBezierCurvesToBSplineCurve
 //purpose  : 
 //=======================================================================
-
-
 Convert_CompBezierCurvesToBSplineCurve::
 Convert_CompBezierCurvesToBSplineCurve(
                  const Standard_Real AngularTolerance) :
@@ -53,9 +51,10 @@ void  Convert_CompBezierCurvesToBSplineCurve::AddCurve
     P1 = mySequence.Last()->Value(mySequence.Last()->Upper());
     P2 = Poles(Poles.Lower());
 
-    // NYI
-  if ( !P1.IsEqual(P2,Precision::Confusion()))
-      cout << "Convert_CompBezierCurvesToBSplineCurve::Addcurve" << endl;;
+#ifdef OCCT_DEBUG
+    if (!P1.IsEqual(P2, Precision::Confusion()))
+      cout << "Convert_CompBezierCurvesToBSplineCurve::Addcurve" << endl;
+#endif
   }
   myDone = Standard_False;
   Handle(TColgp_HArray1OfPnt) HPoles = 
@@ -160,7 +159,7 @@ void Convert_CompBezierCurvesToBSplineCurve::Perform()
     myDegree = Max( myDegree, (mySequence(i))->Length() -1);
   }
 
-  Standard_Real D1, D2, Lambda, Det=0;
+  Standard_Real Det=0;
   gp_Pnt P1, P2, P3;
   Standard_Integer Deg, Inc, MaxDegree = myDegree;
   TColgp_Array1OfPnt Points(1, myDegree+1);
@@ -171,8 +170,8 @@ void Convert_CompBezierCurvesToBSplineCurve::Perform()
     Inc = myDegree - Deg;
     if ( Inc > 0) {
       BSplCLib::IncreaseDegree(myDegree, 
-                              mySequence(i)->Array1(), PLib::NoWeights(), 
-                              Points, PLib::NoWeights());
+                              mySequence(i)->Array1(), BSplCLib::NoWeights(), 
+                              Points, BSplCLib::NoWeights());
     }
     else {
       Points = mySequence(i)->Array1();
@@ -182,7 +181,7 @@ void Convert_CompBezierCurvesToBSplineCurve::Perform()
     if (i == LowerI) {
       // Processing of the initial node of the BSpline.
       for (Standard_Integer j = 1 ; j <= MaxDegree ; j++) {
-       CurvePoles.Append(Points(j));
+        CurvePoles.Append(Points(j));
       }
       CurveKnVals(1)         = 1.; // To begin the series.
       KnotsMultiplicities.Append(MaxDegree+1);
@@ -194,40 +193,37 @@ void Convert_CompBezierCurvesToBSplineCurve::Perform()
       P2 = Points(1);
       P3 = Points(2);
       gp_Vec V1(P1, P2), V2(P2, P3);
-      D1 = P1.SquareDistance(P2);
-      D2 = P3.SquareDistance(P2);
-      Lambda = Sqrt(D2/D1);
-//      cout << "D1, D2, Lambda : " << D1 << " " <<  D2 << " " << Lambda << endl;
 
       // Processing of the tangency between Bezier and the previous.
       // This allows to guarantee at least a C1 continuity if the tangents are  
       // coherent.
       
-      if (V1.Magnitude() > gp::Resolution() &&
-         V2.Magnitude() > gp::Resolution() &&
-         V1.IsParallel(V2, myAngular )) {
-       if(CurveKnVals(i-1) * Lambda > 10. * Epsilon(Det)) {
-         KnotsMultiplicities.Append(MaxDegree-1);
-         CurveKnVals(i) = CurveKnVals(i-1) * Lambda;
-         Det += CurveKnVals(i);
-       }
-       else {
-         CurvePoles.Append(Points(1));
-         KnotsMultiplicities.Append(MaxDegree);
-         CurveKnVals(i) = 1.0 ;
-         Det += CurveKnVals(i) ;
-       }
+      Standard_Real D1 = V1.SquareMagnitude();
+      Standard_Real D2 = V2.SquareMagnitude();
+      if (MaxDegree > 1 && //rln 20.06.99 work-around
+          D1 > gp::Resolution() && D2 > gp::Resolution() && V1.IsParallel(V2, myAngular ))
+      {
+          Standard_Real Lambda = Sqrt(D2/D1);
+          if(CurveKnVals(i-1) * Lambda > 10. * Epsilon(Det)) {
+            KnotsMultiplicities.Append(MaxDegree-1);
+            CurveKnVals(i) = CurveKnVals(i-1) * Lambda;
+          }
+          else {
+            CurvePoles.Append(Points(1));
+            KnotsMultiplicities.Append(MaxDegree);
+            CurveKnVals(i) = 1.0 ;
+          }
       }
       else {
-       CurvePoles.Append(Points(1));
-       KnotsMultiplicities.Append(MaxDegree);
+        CurvePoles.Append(Points(1));
+        KnotsMultiplicities.Append(MaxDegree);
         CurveKnVals(i) = 1.0 ;
-        Det += CurveKnVals(i) ;
       }
+      Det += CurveKnVals(i);
 
       // Store the poles.
       for (Standard_Integer j = 2 ; j <= MaxDegree ; j++) {
-       CurvePoles.Append(Points(j));
+        CurvePoles.Append(Points(j));
       }
 
     }