]> OCCT Git - occt.git/commitdiff
Cherry-pick from CR32747
authorjgv <jgv@opencascade.com>
Mon, 27 Dec 2021 08:15:47 +0000 (11:15 +0300)
committerjgv <jgv@opencascade.com>
Mon, 10 Jan 2022 09:41:25 +0000 (12:41 +0300)
src/IntWalk/IntWalk_IWalking_2.gxx
tests/hlr/exact_hlr/bug32747 [new file with mode: 0644]

index 17def91ce1d231c7c9a8ae6efff5ddd86236491a..2e5d7f0cdd2d319dec598d6144e47e70daf7d05e 100644 (file)
 #define No_Standard_OutOfRange
 #endif
 
+static void CutVectorByTolerances (gp_Vec2d&          theVector,
+                                   const math_Vector& theTolerance)
+{
+  if (Abs(theVector.X()) < theTolerance(1))
+    theVector.SetX (0.);
+  if (Abs(theVector.Y()) < theTolerance(2))
+    theVector.SetY (0.);
+}
 
 // _______________________________________________
 //
@@ -141,7 +149,7 @@ Standard_Boolean IntWalk_IWalking::Cadrage
     }
     BornSup(1) = BornInf(1);                     // limit the parameter
     UVap(1) = BornInf(1);
-    UVap(2) += Step*Duvy*StepSign;;
+    UVap(2) += Step*Duvy*StepSign;
     return Standard_True;
   }
   else if (supu) { // jag 940616
@@ -771,8 +779,13 @@ void IntWalk_IWalking::TestArretCadre
          Line->Value(j).ParametersOnS1(Uc,Vc);
        }
 
-       Scal = (Up-wd1[i].ustart) * (Uc-wd1[i].ustart) +
-              (Vp-wd1[i].vstart) * (Vc-wd1[i].vstart);
+        gp_Vec2d aVec1 (Up-wd1[i].ustart, Vp-wd1[i].vstart),
+          aVec2 (Uc-wd1[i].ustart, Vc-wd1[i].vstart);
+        CutVectorByTolerances (aVec1, tolerance);
+        CutVectorByTolerances (aVec2, tolerance);
+
+        Scal = aVec1 * aVec2;
+        
         // if a stop point is found: stop the line on this point.
        if (Scal < 0) { 
           Line->Cut(j);  nbp= Line->NbPoints();
@@ -791,8 +804,14 @@ void IntWalk_IWalking::TestArretCadre
        }
        else if (nbMultiplicities[i] > 0) {
           for (Standard_Integer k = N+1; k <= N + nbMultiplicities[i]; k++) {
-           Scal = (Up-Umult(k)) * (Uc-Umult(k)) +
-                  (Vp-Vmult(k)) * (Vc-Vmult(k));
+
+            aVec1.SetCoord (Up-Umult(k), Vp-Vmult(k)),
+            aVec2.SetCoord (Uc-Umult(k), Vc-Vmult(k));
+            CutVectorByTolerances (aVec1, tolerance);
+            CutVectorByTolerances (aVec2, tolerance);
+
+            Scal = aVec1 * aVec2;
+            
            if (Scal < 0) { 
              Line->Cut(j);  nbp= Line->NbPoints();
              Irang=i;
@@ -847,11 +866,13 @@ void IntWalk_IWalking::TestArretCadre
       // now the last point of the line and the last calculated point are compated.
       // there will be no need to "Cut"
 
-      Scal = (Up-wd1[i].ustart) * (UV(1)-wd1[i].ustart) +
-       //      (Vp-wd1[i].vstart) * (UV(2)-wd1[i].vstart);
-      // modified by NIZHNY-MKK  Fri Oct 27 12:29:41 2000
-       (Vp-wd1[i].vstart) * (UV(2)-wd1[i].vstart);
-
+      gp_Vec2d aVec1 (Up-wd1[i].ustart, Vp-wd1[i].vstart),
+        aVec2 (UV(1)-wd1[i].ustart, UV(2)-wd1[i].vstart);
+      CutVectorByTolerances (aVec1, tolerance);
+      CutVectorByTolerances (aVec2, tolerance);
+      
+      Scal = aVec1 * aVec2;
+      
       if (Scal < 0) { 
         Irang = i;
        UV(1) = wd1[Irang].ustart;
@@ -867,8 +888,14 @@ void IntWalk_IWalking::TestArretCadre
       }
       else if (nbMultiplicities[i] > 0) {
         for (Standard_Integer j = N+1; j <= N+nbMultiplicities[i]; j++) {
-         Scal = (Up-Umult(j)) * (UV(1)-Umult(j)) +
-                 (Vp-Vmult(j)) * (UV(2)-Vmult(j));
+
+          aVec1.SetCoord (Up-Umult(j), Vp-Vmult(j));
+          aVec2.SetCoord (UV(1)-Umult(j), UV(2)-Vmult(j));
+          CutVectorByTolerances (aVec1, tolerance);
+          CutVectorByTolerances (aVec2, tolerance);
+          
+          Scal = aVec1 * aVec2;
+          
          if (Scal < 0) { 
            Irang=i;
            UV(1) = wd1[Irang].ustart;
diff --git a/tests/hlr/exact_hlr/bug32747 b/tests/hlr/exact_hlr/bug32747
new file mode 100644 (file)
index 0000000..ae97d80
--- /dev/null
@@ -0,0 +1,10 @@
+puts "================================================"
+puts "OCC32747: Exact HLR algorithm gives wrong result"
+puts "================================================"
+puts ""
+
+set viewname "vfront"
+set length 34.3597
+
+restore [locate_data_file bug32747.brep] a
+COMPUTE_HLR $viewname $algotype