0031668: Visualization - WebGL sample doesn't work on Emscripten 1.39
[occt.git] / src / CPnts / CPnts_UniformDeflection.cxx
old mode 100755 (executable)
new mode 100644 (file)
index 4355ca7..8253d06
@@ -1,57 +1,54 @@
-//-------------------------------------------------------------------
-//                algorihme lieu a fleche constante
+// Copyright (c) 1995-1999 Matra Datavision
+// Copyright (c) 1999-2014 OPEN CASCADE SAS
 //
-// cas traites :  courbe parametree
-//               la courbe doit etre C2
-// on assure une fleche maxi
+// This file is part of Open CASCADE Technology software library.
 //
-// algorithme courbe parametree:
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
 //
-// 
-//   le calcul du pas d avancement est 
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
+
+//-------------------------------------------------------------------
+//                Algorithm concerns the constant arrow
+// cases processed : parameterized curve 
+//               the curve should be C2
+// provide a max arrow
+// algorithm of parameterized curve:
+//   calculation of the step of advancement is 
 //             du = sqrt(8*fleche*||P'(u)||/||P'(u)^P''(u)||
-//
-//   on calcule chaque point t.q. u+Du
-//
-//   on verifie si la fleche est effectivement respectee ,si oui on continue
-//   sinon on rectifie le pas
-//
-//   si du ne peut etre calculer (courbure nulle ,singularite sur la courbe) on
-//   prendra alors un pas constant pour atteindre le dernier point ou le depass//   er
-//
-//   le dernier point est reajuste selon les criteres suivants:
-//
-//     si le dernier parametre calcule <2*resolution,on recadre le dernier
-//     point trouve entre lui meme et le precedent et on rajoute le point
-//     de fin (eviter une concentration a la fin)
-//
-//     sinon si la distance (dernier point calcule ,point de fin)<fleche,on
-//     remplace le dernier point calcule par le point de fin
-//
-//     sinon on calcule une fleche max entre l avant dernier point calcule
-//     et le point de fin ;si cette fleche est superieure a la fleche on 
-//     remplace le dernier point par celui ci et le point de fin
-//
-//
-//    LES CONTROLES DE FLECHE ET DERNIER POINT NE SONT FAITS QUE SI
-//      withControl=true
-// 
-//   chaque iteration calcule au maximum 3 points
-//
-//         
+//   calculate each point such as u+Du
+//   check if the arrow is actually taken into account, if yes, continue
+//   otherwise correct the step
+//   si du cannot be calculated (null curvature, singularity on the curve) 
+//   take a constant step to reach the last point or to go past it
+//   The last point is readjusted by the following criteria:
+//     if the last calculated parameter is <2*resolution, reframe the last point found
+//     between itself and the previous point and add the end point 
+//     (avoid a concentration at the end)
+//     otherwise if the distance (last calculated point, end point)<arrow, 
+//     replace the last calculated point by the end point
+//     otherwise calculate max arrow between the last but one calculated point
+//     and the end point; if this arrow is greater than the arrow
+//     replace the last point by this one and the end point
+//    CONTROLS OF ARROW AND THE LAST POINT ARE DONE ONLY IF withControl=true
+//   each iteration calculates at maximum 3 points
 //-------------------------------------------------------------------------
 
-#include <CPnts_UniformDeflection.ixx>
-
-#include  <StdFail_NotDone.hxx>
-#include  <Standard_DomainError.hxx>
-#include  <Standard_OutOfRange.hxx>
-#include  <Standard_ConstructionError.hxx>
-
+#include <Adaptor2d_Curve2d.hxx>
+#include <Adaptor3d_Curve.hxx>
+#include <CPnts_UniformDeflection.hxx>
 #include <gp_Pnt.hxx>
-#include <gp_Vec.hxx>
 #include <gp_Pnt2d.hxx>
+#include <gp_Vec.hxx>
 #include <gp_Vec2d.hxx>
+#include <Standard_ConstructionError.hxx>
+#include <Standard_DomainError.hxx>
+#include <Standard_OutOfRange.hxx>
+#include <StdFail_NotDone.hxx>
 
 static inline void D03d(const Standard_Address C, const Standard_Real U,
                      gp_Pnt& P)
@@ -67,25 +64,6 @@ static  void D02d(const Standard_Address C, const Standard_Real U,
   PP.SetCoord(P.X(),P.Y(),0.);
 }
 
-static inline void D13d(const Standard_Address C, const Standard_Real U,
-                     gp_Pnt& P, gp_Vec& V1)
-{
-  ((Adaptor3d_Curve*)C)->D1(U,P,V1);
-}
-
-// Unused :
-#ifdef DEB
-static  void D12d(const Standard_Address C, const Standard_Real U,
-                     gp_Pnt& PP, gp_Vec& VV1)
-{
-  gp_Pnt2d P;
-  gp_Vec2d V1;
-  ((Adaptor2d_Curve2d*)C)->D1(U,P,V1);
-  PP.SetCoord(P.X(),P.Y(),0.);
-  VV1.SetCoord(V1.X(),V1.Y(),0.);
-}
-#endif
-
 static inline void D23d(const Standard_Address C, const Standard_Real U,
                      gp_Pnt& P, gp_Vec& V1, gp_Vec& V2)
 {
@@ -131,12 +109,12 @@ void CPnts_UniformDeflection::Perform()
     P = myPoints[myNbPoints] ;
     NormD1 = V1.Magnitude();
     if (NormD1 < myTolCur || V2.Magnitude() < myTolCur) {   
-      // singularite sur la tangente ou courbure nulle
+      // singularity on the tangent or null curvature
       myDu = Min(myDwmax, 1.5 * myDu);
     }
     else { 
       NormD2 = V2.CrossMagnitude(V1);
-      if (NormD2 / NormD1 < myDeflection) {  // collinearite des derivees
+      if (NormD2 / NormD1 < myDeflection) {  // collinearity of derivatives
        myDu = Min(myDwmax, 1.5 * myDu);            
       }
       else {
@@ -145,7 +123,7 @@ void CPnts_UniformDeflection::Perform()
       }
     }
     
-    // verifier si la fleche est respectee si WithControl
+    // check if the arrow is observed if WithControl
     
     if (myControl) {
       myDu = Min(myDu, myLastParam-myFirstParam);
@@ -165,9 +143,9 @@ void CPnts_UniformDeflection::Perform()
        V2 = gp_Vec(myPoints[myNbPoints], P1);
        NormD2 = V2.CrossMagnitude(V1) / NormD1;
        
-       // le depassement de fleche a partir duquel on redivise est arbitraire
-       // il faudra peut etre le reajuster (differencier le premier point des
-       // autres) ce test ne marche pas sur les points d inflexion
+       // passing of arrow starting from which the redivision is done is arbitrary
+       // probably it will be necessary to readjust it (differenciate the first point 
+       // from the others) this test does not work on the points of inflexion
        
        if (NormD2 > myDeflection / 5.0) {
          NormD2 = Max(NormD2, 1.1 * myDeflection);
@@ -180,7 +158,7 @@ void CPnts_UniformDeflection::Perform()
     myFinish = (myLastParam - myFirstParam < myTolCur) || (myDu == 0.);
   }
   if (myFinish) {
-    // le dernier point est corrige si control
+    // the last point is corrected if control
     if (myControl && (myNbPoints == 1) ) {
       Un1 = myParams[0];
       if (myLastParam - Un1 < 0.33*(myLastParam-myFirstParam)) {
@@ -220,7 +198,7 @@ void CPnts_UniformDeflection::Perform()
 
          if ((VV.CrossMagnitude(gp_Vec(P2, P)) / NormD1 < myDeflection) && 
              (Un1 >= myLastParam - myDwmax) ) {
-           // on supprime le point n
+           // point n is removed
            myParams[1]= myLastParam;
             myPoints[1] = P1 ;
          }