0024470: Wrong result done by General Fuse algorithm.
[occt.git] / src / IntPatch / IntPatch_ImpImpIntersection_6.gxx
diff --git a/src/IntPatch/IntPatch_ImpImpIntersection_6.gxx b/src/IntPatch/IntPatch_ImpImpIntersection_6.gxx
new file mode 100644 (file)
index 0000000..0c4db04
--- /dev/null
@@ -0,0 +1,181 @@
+// Created on: 1992-05-07
+// Created by: Jacques GOUSSARD
+// Copyright (c) 1992-1999 Matra Datavision
+// Copyright (c) 1999-2012 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// This library is free software; you can redistribute it and / or modify it
+// under the terms of the GNU Lesser General Public 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.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
+
+
+static 
+  Standard_Boolean TreatResultTorus(const IntSurf_Quadric& theQuad1,
+                                    const IntSurf_Quadric& theQuad2,
+                                    const IntAna_QuadQuadGeo& anInt,
+                                    Standard_Boolean& bEmpty,
+                                    IntPatch_SequenceOfLine& theSeqLin);
+
+//=======================================================================
+//function : IntCyTo
+//purpose  : 
+//=======================================================================
+Standard_Boolean IntCyTo(const IntSurf_Quadric& theQuad1,
+                         const IntSurf_Quadric& theQuad2,
+                         const Standard_Real theTolTang,
+                         const Standard_Boolean bReversed,
+                         Standard_Boolean& bEmpty,
+                         IntPatch_SequenceOfLine& theSeqLin)
+{
+  const gp_Cylinder aCyl = bReversed ? theQuad2.Cylinder() : theQuad1.Cylinder();
+  const gp_Torus aTorus = bReversed ? theQuad1.Torus() : theQuad2.Torus();
+  //
+  IntAna_QuadQuadGeo anInt(aCyl, aTorus, theTolTang);
+  Standard_Boolean bRet = 
+    TreatResultTorus(theQuad1, theQuad2, anInt, bEmpty, theSeqLin);
+  //
+  return bRet;
+}
+
+//=======================================================================
+//function : IntCoTo
+//purpose  : 
+//=======================================================================
+Standard_Boolean IntCoTo(const IntSurf_Quadric& theQuad1,
+                         const IntSurf_Quadric& theQuad2,
+                         const Standard_Real theTolTang,
+                         const Standard_Boolean bReversed,
+                         Standard_Boolean& bEmpty,
+                         IntPatch_SequenceOfLine& theSeqLin)
+{
+  const gp_Cone aCone = bReversed ? theQuad2.Cone() : theQuad1.Cone();
+  const gp_Torus aTorus = bReversed ? theQuad1.Torus() : theQuad2.Torus();
+  //
+  IntAna_QuadQuadGeo anInt(aCone, aTorus, theTolTang);
+  Standard_Boolean bRet = 
+    TreatResultTorus(theQuad1, theQuad2, anInt, bEmpty, theSeqLin);
+  //
+  return bRet;
+}
+
+//=======================================================================
+//function : IntSpTo
+//purpose  : 
+//=======================================================================
+Standard_Boolean IntSpTo(const IntSurf_Quadric& theQuad1,
+                         const IntSurf_Quadric& theQuad2,
+                         const Standard_Real theTolTang,
+                         const Standard_Boolean bReversed,
+                         Standard_Boolean& bEmpty,
+                         IntPatch_SequenceOfLine& theSeqLin)
+{
+  const gp_Sphere aSphere = bReversed ? theQuad2.Sphere() : theQuad1.Sphere();
+  const gp_Torus aTorus = bReversed ? theQuad1.Torus() : theQuad2.Torus();
+  //
+  IntAna_QuadQuadGeo anInt(aSphere, aTorus, theTolTang);
+  Standard_Boolean bRet = 
+    TreatResultTorus(theQuad1, theQuad2, anInt, bEmpty, theSeqLin);
+  //
+  return bRet;
+}
+
+//=======================================================================
+//function : IntToTo
+//purpose  : 
+//=======================================================================
+Standard_Boolean IntToTo(const IntSurf_Quadric& theQuad1,
+                         const IntSurf_Quadric& theQuad2,
+                         const Standard_Real theTolTang,
+                         Standard_Boolean& bSameSurf,
+                         Standard_Boolean& bEmpty,
+                         IntPatch_SequenceOfLine& theSeqLin)
+{
+  const gp_Torus aTorus1 = theQuad1.Torus();
+  const gp_Torus aTorus2 = theQuad2.Torus();
+  //
+  IntAna_QuadQuadGeo anInt(aTorus1, aTorus2, theTolTang);
+  Standard_Boolean bRet = anInt.IsDone();
+  if (bRet) {
+    if (anInt.TypeInter() == IntAna_Same) {
+      bEmpty = Standard_False;
+      bSameSurf = Standard_True;
+    } else {
+      bRet = TreatResultTorus(theQuad1, theQuad2, anInt, bEmpty, theSeqLin);
+    }
+  }
+  //
+  return bRet;
+}
+
+//=======================================================================
+//function : TreatResultTorus
+//purpose  : 
+//=======================================================================
+static Standard_Boolean TreatResultTorus(const IntSurf_Quadric& theQuad1,
+                                         const IntSurf_Quadric& theQuad2,
+                                         const IntAna_QuadQuadGeo& anInt,
+                                         Standard_Boolean& bEmpty,
+                                         IntPatch_SequenceOfLine& theSeqLin)
+{
+  Standard_Boolean bRet = anInt.IsDone();
+  //
+  if (!bRet) {
+    return bRet;
+  }
+  //
+  IntAna_ResultType typint = anInt.TypeInter();
+  Standard_Integer NbSol = anInt.NbSolutions();
+  bEmpty = Standard_False;
+  //
+  switch (typint) {
+  case IntAna_Empty :
+    bEmpty = Standard_True;
+    break;
+  //
+  case IntAna_Circle : {
+    Standard_Integer i;
+    IntSurf_TypeTrans trans1, trans2;
+    gp_Vec Tgt;
+    gp_Pnt ptref;
+    //
+    for (i = 1; i <= NbSol; ++i) {
+      gp_Circ aC = anInt.Circle(i);
+      if (theQuad1.TypeQuadric() == theQuad2.TypeQuadric()) {
+        AdjustToSeam(theQuad1.Torus(), aC);
+      }
+      ElCLib::D1(0., aC, ptref, Tgt);
+      Standard_Real qwe = Tgt.DotCross(theQuad2.Normale(ptref),
+                                       theQuad1.Normale(ptref));
+      if(qwe> 0.00000001) {
+        trans1 = IntSurf_Out;
+        trans2 = IntSurf_In;
+      }
+      else if(qwe< -0.00000001) {
+        trans1 = IntSurf_In;
+        trans2 = IntSurf_Out;
+      }
+      else { 
+        trans1=trans2=IntSurf_Undecided; 
+      }
+      //
+      Handle(IntPatch_GLine) glig = 
+        new IntPatch_GLine(aC, Standard_False, trans1, trans2);
+      theSeqLin.Append(glig);
+    }
+  }
+    break;
+  //
+  case IntAna_NoGeometricSolution:
+  default:
+    bRet = Standard_False;
+    break;
+  }
+  //
+  return bRet;
+}