]> OCCT Git - occt-copy.git/commitdiff
0030747: Modeling Algorithms - 2d Curves concatenator doesn't properly process closed... CR30747
authoranv <anv@opencascade.com>
Mon, 27 May 2019 13:41:16 +0000 (16:41 +0300)
committeranv <anv@opencascade.com>
Thu, 6 Jun 2019 14:21:41 +0000 (17:21 +0300)
- Correct processing of closed curves was added to method Geom2dConvert_CompCurveToBSplineCurve::Add;
- Default value of After changed to true as it's is a more expected behavior.

src/Geom2dConvert/Geom2dConvert_CompCurveToBSplineCurve.cxx
src/Geom2dConvert/Geom2dConvert_CompCurveToBSplineCurve.hxx

index f68c1f4ddce4893ce8f918dac2e0b3b3c898e68d..ff05b3014818c343c440a46adae8d723ef093a8b 100644 (file)
@@ -83,60 +83,41 @@ Add(const Handle(Geom2d_BoundedCurve)& NewCurve,
     return Standard_True;
   }
 
-  myTol = Tolerance;
+  Standard_Real aSqTol = Tolerance * Tolerance;
 
   Standard_Integer LBs = Bs->NbPoles(), LCb = myCurve->NbPoles();
-  
-  // myCurve est elle fermee ?
-  if (myCurve->Pole(LCb).Distance(myCurve->Pole(1)) < myTol){
-    if(After){
-      // Ajout Apres ?
-      Standard_Real d1 = myCurve->Pole(LCb).Distance(Bs->Pole(1));
-      Standard_Real d2 = myCurve->Pole(LCb).Distance(Bs->Pole(LBs));
-      if (d2 < d1) {
-        Bs->Reverse();
-        d1 = d2;
-      }
-      if (d1 < myTol) {
-       Add(myCurve, Bs, Standard_True);
-       return Standard_True;
-      }
-    }
-    else{
-      // Ajout avant ?  
-      Standard_Real d1 = myCurve->Pole(1).Distance(Bs->Pole(1));
-      Standard_Real d2 = myCurve->Pole(1).Distance(Bs->Pole(LBs));
-      if (d1 < d2) {
-        Bs->Reverse();
-        d2 = d1;
-      }
-      if (d2 < myTol) {
-       Add(Bs, myCurve, Standard_False);
-       return Standard_True;
-      }
-    }
+
+  Standard_Boolean isBeforeReversed = myCurve->Pole(1).SquareDistance(Bs->Pole(1)) < aSqTol;
+  Standard_Boolean isBefore = (myCurve->Pole(1).SquareDistance(Bs->Pole(LBs)) < aSqTol) || isBeforeReversed;
+  Standard_Boolean isAfterReversed = myCurve->Pole(LCb).SquareDistance(Bs->Pole(LBs)) < aSqTol;
+  Standard_Boolean isAfter = (myCurve->Pole(LCb).SquareDistance(Bs->Pole(1)) < aSqTol) || isAfterReversed;
+
+  // myCurve and NewCurve together form a closed curve
+  if (isBefore && isAfter)
+  {
+    if (After) isBefore = Standard_False;
+    else       isAfter = Standard_False;
   }
-  // Ajout Apres ?
-  else {
 
-    Standard_Real d1 = myCurve->Pole(LCb).Distance(Bs->Pole(1));
-    Standard_Real d2 = myCurve->Pole(LCb).Distance(Bs->Pole(LBs));
-    if (( d1  < myTol) || ( d2 < myTol)) {
-      if (d2 < d1) {Bs->Reverse();}
-      Add(myCurve, Bs, Standard_True);
-      return Standard_True;
+  if (isAfter)
+  {
+    if (isAfterReversed)
+    {
+      Bs->Reverse();
     }
-  // Ajout avant ?  
-    else { 
-      d1 = myCurve->Pole(1).Distance(Bs->Pole(1));
-      d2 = myCurve->Pole(1).Distance(Bs->Pole(LBs));
-      if ( (d1 < myTol) || (d2 < myTol)) {
-       if (d1 < d2) {Bs->Reverse();}
-       Add(Bs, myCurve, Standard_False );
-       return Standard_True;
-      }
+    Add(myCurve, Bs, Standard_True);
+    return Standard_True;
+  }
+  else if (isBefore)
+  {
+    if (isBeforeReversed)
+    {
+      Bs->Reverse();
     }
-  }  
+    Add(Bs, myCurve, Standard_False);
+    return Standard_True;
+  }
+
   return Standard_False;
 }
 
index 78842835a1345ed7755f6d272822e10282009e7d..d732b5a85642c66a1797ed8c265d6a667957fd32 100644 (file)
@@ -49,7 +49,7 @@ public:
   //! Tolerance is used to check continuity and decrease
   //! Multiplicty at the common Knot
   //! After is usefull if BasisCurve is a closed curve .
-  Standard_EXPORT Standard_Boolean Add (const Handle(Geom2d_BoundedCurve)& NewCurve, const Standard_Real Tolerance, const Standard_Boolean After = Standard_False);
+  Standard_EXPORT Standard_Boolean Add (const Handle(Geom2d_BoundedCurve)& NewCurve, const Standard_Real Tolerance, const Standard_Boolean After = Standard_True);
   
   Standard_EXPORT Handle(Geom2d_BSplineCurve) BSplineCurve() const;