]> OCCT Git - occt.git/commitdiff
0030752: Canonical recognition - converts bspline curve into huge ellipse CR30752
authorika <ika@opencascade.com>
Wed, 5 Jun 2024 16:19:44 +0000 (17:19 +0100)
committerika <ika@opencascade.com>
Tue, 13 Aug 2024 11:48:13 +0000 (12:48 +0100)
Add additional check for very thin result ellipse during conversion curve to ellipse.

src/GeomConvert/GeomConvert_CurveToAnaCurve.cxx

index 3038e88dfa7f1c38f0f0ce0ae3cce640fc2a5f3c..85e4091ce6d01475d947d486b87d3c6a28bd211e 100644 (file)
@@ -16,6 +16,7 @@
 
 
 #include <ElCLib.hxx>
+#include <Extrema_ExtPC.hxx>
 #include <gce_MakeCirc.hxx>
 #include <Geom_BezierCurve.hxx>
 #include <Geom_BSplineCurve.hxx>
@@ -24,6 +25,7 @@
 #include <Geom_Ellipse.hxx>
 #include <Geom_Line.hxx>
 #include <Geom_TrimmedCurve.hxx>
+#include <GeomAdaptor_Curve.hxx>
 #include <gp_Ax2.hxx>
 #include <gp_Ax3.hxx>
 #include <gp_Circ.hxx>
@@ -622,6 +624,33 @@ if (Q2 > 0 && Q1*Q3 < 0) {
     cl = ElCLib::InPeriod(cl, cm, cm + PI2);
 
     res = gell;
+
+    // reverse test for 20 points for cases of very thin and long ellipse (#30752)
+    if ((1 - anEllipse.Eccentricity()) < tol)
+    {
+      GeomAdaptor_Curve anAdpt(c3d);
+      Extrema_ExtPC aProj;
+      aProj.Initialize(anAdpt, c1, c2);
+      Standard_Real aTol2 = tol * tol;
+      Standard_Real aDelta = (cl - cf) / 20;
+      for (int aPntId = 1; aPntId <= 20; aPntId++)
+      {
+        gp_Pnt anEllPnt = res->Value(cf + aPntId * aDelta);
+        aProj.Perform(anEllPnt);
+        if (aProj.IsDone())
+        {
+          Standard_Real anExtDist = aProj.SquareDistance(1);
+          for (int anExtInd = 2; anExtInd <= aProj.NbExt(); anExtInd++)
+          {
+            Standard_Real aDist = aProj.SquareDistance(anExtInd);
+            if (anExtDist < aDist)
+              aDist = anExtDist;
+          }
+          if (anExtDist > aTol2)
+            return NULL;  // not done
+        }
+      }
+    }
   }
 }
 /*