0026173: Wrong result of ChFi3d_ChBuilder algorithm: incorrect processing of G1 junct...
[occt.git] / src / ChFi3d / ChFi3d.cxx
index 37a04f6..0c05b9e 100644 (file)
 // Alternatively, this file may be used under the terms of Open CASCADE
 // commercial license or contractual agreement.
 
-#include <ChFi3d.ixx>
-#include <ChFi3d_Builder_0.hxx>
-#include <BRepAdaptor_Surface.hxx>
-#include <BRepAdaptor_Curve2d.hxx>
-#include <BRepAdaptor_Curve.hxx>
-#include <BRep_Tool.hxx>
 
+#include <BRep_Tool.hxx>
+#include <BRepAdaptor_Curve.hxx>
+#include <BRepAdaptor_Curve2d.hxx>
+#include <BRepAdaptor_Surface.hxx>
+#include <ChFi3d.hxx>
+#include <ChFi3d_Builder_0.hxx>
 #include <gp_Pnt.hxx>
-#include <gp_Vec.hxx>
 #include <gp_Pnt2d.hxx>
+#include <gp_Vec.hxx>
 #include <gp_Vec2d.hxx>
 #include <Precision.hxx>
 #include <TopExp_Explorer.hxx>
 #include <TopoDS.hxx>
-
+#include <TopoDS_Edge.hxx>
 
 //=======================================================================
 //function : ConcaveSide
 //purpose  : calculate the concave face at the neighborhood of the border of
 //           2 faces.
 //=======================================================================
-
 Standard_Integer ChFi3d::ConcaveSide(const BRepAdaptor_Surface& S1, 
                                     const BRepAdaptor_Surface& S2, 
                                     const TopoDS_Edge& E, 
@@ -53,8 +52,8 @@ Standard_Integer ChFi3d::ConcaveSide(const BRepAdaptor_Surface& S1,
   gp_Pnt pt, pt1, pt2; gp_Vec tgE, tgE1, tgE2, ns1, ns2, dint1, dint2;
   TopoDS_Face F1 = S1.Face();
   TopoDS_Face F2 = S2.Face();
-  F1.Orientation(TopAbs_FORWARD);
-  F2.Orientation(TopAbs_FORWARD);
+  //F1.Orientation(TopAbs_FORWARD);
+  //F2.Orientation(TopAbs_FORWARD);
   
   CE.D1(par,pt,tgE);
   tgE.Normalize();
@@ -101,9 +100,13 @@ Standard_Integer ChFi3d::ConcaveSide(const BRepAdaptor_Surface& S1,
   S1.D1(p2d1.X(),p2d1.Y(),pt1,DU1,DV1);
   ns1 = DU1.Crossed(DV1);
   ns1.Normalize();
+  if (F1.Orientation() == TopAbs_REVERSED)
+    ns1.Reverse();
   S2.D1(p2d2.X(),p2d2.Y(),pt2,DU2,DV2);
   ns2 = DU2.Crossed(DV2);
   ns2.Normalize();
+  if (F2.Orientation() == TopAbs_REVERSED)
+    ns2.Reverse();
 
   dint1 = ns1.Crossed(tgE1);
   dint2 = ns2.Crossed(tgE2);
@@ -130,11 +133,15 @@ Standard_Integer ChFi3d::ConcaveSide(const BRepAdaptor_Surface& S1,
       DV1 += ( DV1 * dint1 < 0) ? -DDV : DDV;
       ns1 = DU1.Crossed(DV1);
       ns1.Normalize();
+      if (F1.Orientation() == TopAbs_REVERSED)
+        ns1.Reverse();
       S2.D2(p2d2.X(),p2d2.Y(),pt2,DU2,DV2,DDU,DDV,DDUV);
       DU2 += ( DU2 * dint2 < 0) ? -DDU : DDU;
       DV2 += ( DV2 * dint2 < 0) ? -DDV : DDV;
       ns2 = DU2.Crossed(DV2);
       ns2.Normalize();
+      if (F2.Orientation() == TopAbs_REVERSED)
+        ns2.Reverse();
       
       dint1 = ns1.Crossed(tgE1);
       dint2 = ns2.Crossed(tgE2);
@@ -172,8 +179,12 @@ Standard_Integer ChFi3d::ConcaveSide(const BRepAdaptor_Surface& S1,
       p2d2.SetX(p2d2.X() + u); p2d2.SetY(p2d2.Y() + v);
       S1.D1(p2d1.X(),p2d1.Y(),pt1,DU1,DV1);
       ns1 = DU1.Crossed(DV1);
+      if (F1.Orientation() == TopAbs_REVERSED)
+        ns1.Reverse();
       S2.D1(p2d2.X(),p2d2.Y(),pt2,DU2,DV2);
       ns2 = DU2.Crossed(DV2);
+      if (F2.Orientation() == TopAbs_REVERSED)
+        ns2.Reverse();
       gp_Vec vref(pt1,pt2);
       if(ns1.Dot(vref) < 0.){
        Or1 = TopAbs_REVERSED;