OCC22322 Improvement of Extrema performance
authorASH <>
Thu, 19 May 2011 10:50:52 +0000 (10:50 +0000)
committerbugmaster <bugmaster@opencascade.com>
Mon, 5 Mar 2012 15:28:47 +0000 (19:28 +0400)
33 files changed:
src/BRepExtrema/BRepExtrema.cdl
src/BRepExtrema/BRepExtrema_DistShapeShape.cxx
src/BRepExtrema/BRepExtrema_DistShapeShape.hxx [new file with mode: 0644]
src/BRepExtrema/BRepExtrema_DistanceSS.cxx
src/BRepExtrema/BRepExtrema_DistanceSS.hxx [new file with mode: 0644]
src/BRepExtrema/BRepExtrema_ExtCC.cxx
src/BRepExtrema/BRepExtrema_ExtCC.hxx [new file with mode: 0644]
src/BRepExtrema/BRepExtrema_ExtCF.cxx
src/BRepExtrema/BRepExtrema_ExtCF.hxx [new file with mode: 0644]
src/BRepExtrema/BRepExtrema_ExtFF.cxx
src/BRepExtrema/BRepExtrema_ExtFF.hxx [new file with mode: 0644]
src/BRepExtrema/BRepExtrema_ExtPC.cxx
src/BRepExtrema/BRepExtrema_ExtPC.hxx [new file with mode: 0644]
src/BRepExtrema/BRepExtrema_ExtPF.cxx
src/BRepExtrema/BRepExtrema_ExtPF.hxx [new file with mode: 0644]
src/BRepExtrema/BRepExtrema_Poly.cxx
src/BRepExtrema/BRepExtrema_Poly.hxx [new file with mode: 0644]
src/BRepExtrema/BRepExtrema_SeqOfSolution.hxx [new file with mode: 0644]
src/BRepExtrema/BRepExtrema_SolutionElem.hxx [new file with mode: 0644]
src/BRepExtrema/BRepExtrema_SupportType.hxx [new file with mode: 0644]
src/BRepExtrema/FILES [new file with mode: 0644]
src/Bnd/Bnd.cdl
src/Bnd/Bnd_Sphere.cdl [new file with mode: 0644]
src/Bnd/Bnd_Sphere.cxx [new file with mode: 0644]
src/Bnd/Bnd_Sphere.lxx [new file with mode: 0644]
src/Extrema/Extrema.cdl
src/Extrema/Extrema_ExtPS.cdl
src/Extrema/Extrema_ExtPS.cxx
src/Extrema/Extrema_GenExtPS.cdl
src/Extrema/Extrema_GenExtPS.cxx
src/Extrema/Extrema_HUBTreeOfSphere.cxx [new file with mode: 0644]
src/Extrema/Extrema_HUBTreeOfSphere.hxx [new file with mode: 0644]
src/Extrema/FILES [new file with mode: 0644]

index ca56352..35efe3c 100755 (executable)
@@ -1,8 +1,7 @@
--- File:       BRepExtrema.cdl
--- Created:    Fri Dec  3 15:48:19 1993
--- Author:     Christophe MARION
---             <cma@sdsun1>
----Copyright:   Matra Datavision 1993
+-- File:      BRepExtrema.cdl
+-- Created:   Fri Dec  3 15:48:19 1993
+-- Author:    Christophe MARION
+---Copyright: Matra Datavision 1993
 
 package BRepExtrema
 
@@ -27,37 +26,37 @@ is
     ----------------------------------------------------------
     --  Extrema between two Shapes with triangulation.
     ----------------------------------------------------------
-    class Poly;
+    imported Poly;
 
 
     ----------------------------------------------------------
     --  Extrema between a Point and an Edge.
     ----------------------------------------------------------
-    class ExtPC;
+    imported ExtPC;
 
 
     ----------------------------------------------------------
     --  Extrema between two Edges.
     ----------------------------------------------------------
-    class ExtCC;
+    imported ExtCC;
 
 
     ----------------------------------------------------------
     --  Extrema between a Point and a Face.
     ----------------------------------------------------------
-    class ExtPF;
+    imported ExtPF;
 
 
     ----------------------------------------------------------
     --  Extrema between an Edge  and a Face.
     ----------------------------------------------------------
-    class ExtCF;
+    imported ExtCF;
 
 
     ----------------------------------------------------------
     --  Extrema between two Faces.
     ----------------------------------------------------------
-    class ExtFF;
+    imported ExtFF;
 
 
     ----------------------------------------------------------
@@ -73,8 +72,7 @@ is
     --             IsInFace => The solution is inside a Face.    
      
     ----------------------------------------------------------
-    enumeration SupportType is IsVertex, IsOnEdge, IsInFace end SupportType;
-
+    imported SupportType;
 
 
     ----------------------------------------------------------
@@ -82,39 +80,21 @@ is
     -- between two shapes and  the corresponding couples of solution points.  
     
     ----------------------------------------------------------
-    class DistShapeShape;
-
-
+    imported DistShapeShape;
 
 
     ----------------------------------------------------------
     --  This class is used to store a solution on a Shape. 
     --  (used only by class DistShapeShape)
     ----------------------------------------------------------
-    class SolutionElem;          
-
+    imported SolutionElem;
 
 
     ----------------------------------------------------------
     -- This sequence is used to store all the solution on each Shape.
     ----------------------------------------------------------
-    class SeqOfSolution instantiates Sequence from TCollection 
-       ( SolutionElem  from  BRepExtrema); 
-
-
-    
-
-
-    ----------------------------------------------------------
-    -- This class is used to compute minimum distance between two elementary
-    -- Shapes ( Vertex, Edge, Face ) (used only by class DistShapeShape)
-    ----------------------------------------------------------
-      private class DistanceSS from BRepExtrema;
-
-
-
-
-
+    imported SeqOfSolution;
 
+    imported DistanceSS;
 
 end BRepExtrema;
index 168e181..90ac2bf 100755 (executable)
@@ -1,18 +1,16 @@
-// File:       BRepExtrema_DistShapeShape.cxx
-// Created:    Mon Apr 22 17:03:37 1996
-// Modified :   Mps(10-04-97) portage WNT 
-// Author:     Maria PUMBORIOS
-// Author:      Herve LOUESSARD 
-//             <mps@sgi64>
-
-#include <BRepExtrema_DistShapeShape.ixx>
+// File:        BRepExtrema_DistShapeShape.cxx
+// Created:     Mon Apr 22 17:03:37 1996
+// Modified: Mps(10-04-97) portage WNT
+// Author:      Maria PUMBORIOS
+// Author:   Herve LOUESSARD
+
+#include <BRepExtrema_DistShapeShape.hxx>
+
 #include <Standard_OStream.hxx>
 #include <TopTools_IndexedMapOfShape.hxx>
 #include <BRepBndLib.hxx>
 #include <Bnd_Box.hxx>
 #include <TopExp.hxx>
-#include <TCollection.hxx>
-#include <Standard_Real.hxx>
 #include <BRepExtrema_DistanceSS.hxx>
 #include <TopoDS.hxx>
 #include <TopAbs.hxx>
 #include <TopoDS_Face.hxx>
 #include <TopAbs_ShapeEnum.hxx>
 #include <Precision.hxx>
-#include <BRepExtrema_SeqOfSolution.hxx>
-#include <BRepExtrema_SolutionElem.hxx>
 #include <Bnd_SeqOfBox.hxx>
 #include <BRepExtrema_UnCompatibleShape.hxx>
 #include <BRep_Tool.hxx>
 #include <BRepClass3d_SolidClassifier.hxx>
+#include <StdFail_NotDone.hxx>
 
 static void Decomposition(const TopoDS_Shape&         S,
                           TopTools_IndexedMapOfShape& MapV,
                           TopTools_IndexedMapOfShape& MapE,
                           TopTools_IndexedMapOfShape& MapF)
 {
-   MapV.Clear();
-   MapE.Clear();
-   MapF.Clear();
-   TopExp::MapShapes(S,TopAbs_VERTEX,MapV);
-   TopExp::MapShapes(S,TopAbs_EDGE,MapE);
-   TopExp::MapShapes(S,TopAbs_FACE,MapF);
+  MapV.Clear();
+  MapE.Clear();
+  MapF.Clear();
+  TopExp::MapShapes(S,TopAbs_VERTEX,MapV);
+  TopExp::MapShapes(S,TopAbs_EDGE,MapE);
+  TopExp::MapShapes(S,TopAbs_FACE,MapF);
 }
 
 static void BoxCalculation(const TopTools_IndexedMapOfShape& Map,
                            Bnd_SeqOfBox&                     SBox)
 { 
-   Standard_Integer i = 0;
-   for(i = 1; i <= Map.Extent(); i++) {
-     Bnd_Box box;
-     BRepBndLib::Add( Map(i), box);
-     SBox.Append(box);
-   }
+  for (Standard_Integer i = 1; i <= Map.Extent(); i++)
+  {
+    Bnd_Box box;
+    BRepBndLib::Add(Map(i), box);
+    SBox.Append(box);
+  }
 }
 
-static Standard_Real DistanceInitiale(const TopoDS_Vertex V1,
+inline Standard_Real DistanceInitiale(const TopoDS_Vertex V1,
                                       const TopoDS_Vertex V2)
 {
-  gp_Pnt P1,P2;
-  P1= BRep_Tool::Pnt(V1);
-  P2= BRep_Tool::Pnt(V2); 
-  return(P1.Distance(P2));  
+  return (BRep_Tool::Pnt(V1).Distance(BRep_Tool::Pnt(V2)));
 } 
 
 //=======================================================================
@@ -71,39 +65,40 @@ void BRepExtrema_DistShapeShape::DistanceMapMap(const TopTools_IndexedMapOfShape
                                                 const Bnd_SeqOfBox&               LBox1,
                                                 const Bnd_SeqOfBox&               LBox2)
 {
-  Standard_Integer i = 0, j = 0;
-  Bnd_Box box1, box2;
-  TopoDS_Shape S1, S2;
-  BRepExtrema_SeqOfSolution  seq1, seq2;
-
-  Standard_Integer n1 = Map1.Extent();
-  Standard_Integer n2 = Map2.Extent();
-  for(i = 1; i <= n1; i++) {
-    box1= LBox1.Value(i);
-    S1= TopoDS_Shape (Map1(i)); 
-    for(j = 1; j <= n2; j++) {
-      box2= LBox2.Value(j);
-      S2 = TopoDS_Shape (Map2(j));
+  Standard_Integer i, j;
+  BRepExtrema_SeqOfSolution seq1, seq2;
+
+  const Standard_Integer n1 = Map1.Extent();
+  const Standard_Integer n2 = Map2.Extent();
+  for (i = 1; i <= n1; i++)
+  {
+    const Bnd_Box &box1 = LBox1.Value(i);
+    const TopoDS_Shape &S1 = Map1(i);
+    for (j = 1; j <= n2; j++)
+    {
+      const Bnd_Box &box2= LBox2.Value(j);
+      const TopoDS_Shape &S2 = Map2(j);
+
       BRepExtrema_DistanceSS  dist(S1,S2,box1,box2,myDistRef,myEps);
-      if(dist.IsDone())
-        if(dist.DistValue() < (myDistRef-myEps)) {
-          ListeDeSolutionShape1.Clear();
-          ListeDeSolutionShape2.Clear();
+      if (dist.IsDone())
+        if(dist.DistValue() < (myDistRef-myEps))
+        {
+          mySolutionsShape1.Clear();
+          mySolutionsShape2.Clear();
           seq1= dist.Seq1Value();
           seq2= dist.Seq2Value();
-          ListeDeSolutionShape1.Append(seq1);
-          ListeDeSolutionShape2.Append(seq2);
+          mySolutionsShape1.Append(seq1);
+          mySolutionsShape2.Append(seq2);
           myDistRef=dist.DistValue();
         }
-        else if(fabs (dist.DistValue()-myDistRef)< myEps ) {
+        else if(fabs(dist.DistValue()-myDistRef) < myEps)
+        {
           seq1= dist.Seq1Value();
           seq2= dist.Seq2Value();
-          ListeDeSolutionShape1.Append(seq1);
-          ListeDeSolutionShape2.Append(seq2);
-          //  Modified by Sergey KHROMOV - Tue Mar  6 12:15:39 2001 Begin
+          mySolutionsShape1.Append(seq1);
+          mySolutionsShape2.Append(seq2);
           if (myDistRef > dist.DistValue())
             myDistRef=dist.DistValue();
-          //  Modified by Sergey KHROMOV - Tue Mar  6 12:15:37 2001 End
         }
     }
   }
@@ -115,8 +110,14 @@ void BRepExtrema_DistShapeShape::DistanceMapMap(const TopTools_IndexedMapOfShape
 //=======================================================================
 
 BRepExtrema_DistShapeShape::BRepExtrema_DistShapeShape()
+: myDistRef(0.),
+  myDistValue(0.),
+  myIsDone(Standard_False),
+  myInnerSol(Standard_False),
+  myEps(Precision::Confusion()),
+  myFlag(Extrema_ExtFlag_MINMAX),
+  myAlgo(Extrema_ExtAlgo_Grad)
 {
-  myEps = Precision::Confusion();
 }
 
 //=======================================================================
@@ -124,9 +125,17 @@ BRepExtrema_DistShapeShape::BRepExtrema_DistShapeShape()
 //purpose  : 
 //=======================================================================
 BRepExtrema_DistShapeShape::BRepExtrema_DistShapeShape(const TopoDS_Shape& Shape1,
-                                                      const TopoDS_Shape& Shape2)
+                                                       const TopoDS_Shape& Shape2,
+                                                       const Extrema_ExtFlag F,
+                                                       const Extrema_ExtAlgo A)
+: myDistRef(0.),
+  myDistValue(0.),
+  myIsDone(Standard_False),
+  myInnerSol(Standard_False),
+  myEps(Precision::Confusion()),
+  myFlag(F),
+  myAlgo(A)
 {
-  myEps = Precision::Confusion();
   LoadS1(Shape1);
   LoadS2(Shape2);
   Perform();
@@ -138,25 +147,23 @@ BRepExtrema_DistShapeShape::BRepExtrema_DistShapeShape(const TopoDS_Shape& Shape
 //=======================================================================
 
 BRepExtrema_DistShapeShape::BRepExtrema_DistShapeShape(const TopoDS_Shape& Shape1,
-                                                      const TopoDS_Shape& Shape2,
-                                                      const Standard_Real theDeflection)
+                                                       const TopoDS_Shape& Shape2,
+                                                       const Standard_Real theDeflection,
+                                                       const Extrema_ExtFlag F,
+                                                       const Extrema_ExtAlgo A)
+: myDistRef(0.),
+  myDistValue(0.),
+  myIsDone(Standard_False),
+  myInnerSol(Standard_False),
+  myEps(theDeflection),
+  myFlag(F),
+  myAlgo(A)
 {
-  myEps = theDeflection;
   LoadS1(Shape1);
   LoadS2(Shape2);
   Perform();
 }
 
-//=======================================================================
-//function : SetDeflection
-//purpose  : 
-//=======================================================================
-
-void BRepExtrema_DistShapeShape::SetDeflection(const Standard_Real theDeflection)
-{
-  myEps = theDeflection;
-}
-
 //=======================================================================
 //function : LoadS1
 //purpose  : 
@@ -188,143 +195,110 @@ Standard_Boolean BRepExtrema_DistShapeShape::Perform()
 {
   myIsDone=Standard_False;
   myInnerSol=Standard_False;
-  ListeDeSolutionShape1.Clear();
-  ListeDeSolutionShape2.Clear();
-  
-  if( myShape1.IsNull() || myShape2.IsNull() )
+  mySolutionsShape1.Clear();
+  mySolutionsShape2.Clear();
+
+  if ( myShape1.IsNull() || myShape2.IsNull() )
     return Standard_False;
 
+  TopoDS_Vertex V;
   Bnd_SeqOfBox BV1, BV2, BE1, BE2, BF1, BF2;
-  Standard_Real tol = 0.001;
-  gp_Pnt P;
-  Standard_Integer nbv1,nbv2;
-
-  // traitement des solides
-  TopAbs_ShapeEnum Type1 = myShape1.ShapeType();
-  TopAbs_ShapeEnum Type2 = myShape2.ShapeType();
-  if((Type1==TopAbs_SOLID) || (Type1 == TopAbs_COMPSOLID)) {
+  const Standard_Real tol = 0.001;
+
+  // Treatment of solids
+  const TopAbs_ShapeEnum Type1 = myShape1.ShapeType();
+  if ((Type1==TopAbs_SOLID) || (Type1 == TopAbs_COMPSOLID))
+  {
     BRepClass3d_SolidClassifier Classi(myShape1);
-    nbv2=myMapV2.Extent();
-    nbv1=0;
-    while ( (nbv1<nbv2) && (! myInnerSol))
+    const Standard_Integer nbv2 = myMapV2.Extent();
+    Standard_Integer nbv1 = 0;
+    do
     {
       nbv1++;
-      TopoDS_Vertex V2 = TopoDS::Vertex(myMapV2(nbv1));
-      P=BRep_Tool::Pnt(V2);
+      V = TopoDS::Vertex(myMapV2(nbv1));
+      const gp_Pnt &P = BRep_Tool::Pnt(V);
       Classi.Perform(P,tol);
-      if(Classi.State()==TopAbs_IN) {
+      if (Classi.State()==TopAbs_IN)
+      {
         myInnerSol = Standard_True;
-        myNbSolution = 1;
-        myDistRef = 0;
+        myDistRef = 0.;
         myIsDone = Standard_True; 
-        BRepExtrema_SolutionElem Sol(0,P,BRepExtrema_IsVertex,V2);
-        ListeDeSolutionShape1.Append(Sol);
-        ListeDeSolutionShape2.Append(Sol);
+        BRepExtrema_SolutionElem Sol(0,P,BRepExtrema_IsVertex,V);
+        mySolutionsShape1.Append(Sol);
+        mySolutionsShape2.Append(Sol);
       }  
     }
+    while ( (nbv1<nbv2) && (!myInnerSol) );
   }
   
-  if(((Type2==TopAbs_SOLID)||(Type2==TopAbs_COMPSOLID))&&(!myInnerSol)) {
+  const TopAbs_ShapeEnum Type2 = myShape2.ShapeType();
+  if (((Type2==TopAbs_SOLID) || (Type2==TopAbs_COMPSOLID)) && (!myInnerSol))
+  {
     BRepClass3d_SolidClassifier Classi(myShape2);
-    nbv1= myMapV1.Extent();
-    nbv2=0;
-    while ((nbv2<nbv1) && (! myInnerSol))
+    const Standard_Integer nbv1 = myMapV1.Extent();
+    Standard_Integer nbv2 = 0;
+    do
     {
       nbv2++;
-      TopoDS_Vertex V1=TopoDS::Vertex(myMapV1(nbv2));
-      P=BRep_Tool::Pnt(V1);
+      V = TopoDS::Vertex(myMapV1(nbv2));
+      const gp_Pnt &P = BRep_Tool::Pnt(V);
       Classi.Perform(P,tol);
       if (Classi.State()==TopAbs_IN) {
         myInnerSol = Standard_True;
-        myNbSolution = 1;
         myDistRef = 0;
         myIsDone = Standard_True; 
-        BRepExtrema_SolutionElem Sol (0,P,BRepExtrema_IsVertex,V1);
-        ListeDeSolutionShape1.Append(Sol);
-        ListeDeSolutionShape2.Append(Sol);
+        BRepExtrema_SolutionElem Sol (0,P,BRepExtrema_IsVertex,V);
+        mySolutionsShape1.Append(Sol);
+        mySolutionsShape2.Append(Sol);
       }
     }
+    while ( (nbv2<nbv1) && (!myInnerSol) );
   }
   
-  if (!myInnerSol) {  
-    BoxCalculation( myMapV1,BV1);
-    BoxCalculation( myMapE1,BE1);
-    BoxCalculation( myMapF1,BF1);
-    BoxCalculation( myMapV2,BV2);
-    BoxCalculation( myMapE2,BE2);
-    BoxCalculation( myMapF2,BF2);
+  if (!myInnerSol)
+  {
+    BoxCalculation(myMapV1,BV1);
+    BoxCalculation(myMapE1,BE1);
+    BoxCalculation(myMapF1,BF1);
+    BoxCalculation(myMapV2,BV2);
+    BoxCalculation(myMapE2,BE2);
+    BoxCalculation(myMapF2,BF2);
     
-    if (myMapV1.Extent()!=0 && myMapV2.Extent()!=0) {
+    if (myMapV1.Extent() && myMapV2.Extent())
+    {
       TopoDS_Vertex V1 = TopoDS::Vertex(myMapV1(1));
       TopoDS_Vertex V2 = TopoDS::Vertex(myMapV2(1));
-      myDistRef = DistanceInitiale(V1, V2);  
+      myDistRef = DistanceInitiale(V1, V2);
     }
     else
-      myDistRef= 1.e30;
-    
-    DistanceMapMap( myMapV1, myMapV2, BV1, BV2);
-    DistanceMapMap( myMapV1, myMapE2, BV1, BE2);
-    DistanceMapMap( myMapE1, myMapV2, BE1, BV2);
-    DistanceMapMap( myMapV1, myMapF2, BV1, BF2);
-    DistanceMapMap( myMapF1, myMapV2, BF1, BV2);
-    DistanceMapMap( myMapE1, myMapE2, BE1, BE2);
-    DistanceMapMap( myMapE1, myMapF2, BE1, BF2);
-    DistanceMapMap( myMapF1, myMapE2, BF1, BE2);
-    
+      myDistRef= 1.e30; //szv:!!!
+
+    DistanceMapMap(myMapV1, myMapV2, BV1, BV2);
+    DistanceMapMap(myMapV1, myMapE2, BV1, BE2);
+    DistanceMapMap(myMapE1, myMapV2, BE1, BV2);
+    DistanceMapMap(myMapV1, myMapF2, BV1, BF2);
+    DistanceMapMap(myMapF1, myMapV2, BF1, BV2);
+    DistanceMapMap(myMapE1, myMapE2, BE1, BE2);
+    DistanceMapMap(myMapE1, myMapF2, BE1, BF2);
+    DistanceMapMap(myMapF1, myMapE2, BF1, BE2);
+
     if( (fabs(myDistRef)) > myEps )
       DistanceMapMap(myMapF1,myMapF2,BF1,BF2);
     
     //  Modified by Sergey KHROMOV - Tue Mar  6 11:55:03 2001 Begin
-    Standard_Integer i = 0;
-    for(i = 1; i <= ListeDeSolutionShape1.Length(); i++)
-      if (ListeDeSolutionShape1.Value(i).Dist() > myDistRef + myEps) {
-        ListeDeSolutionShape1.Remove(i);
-        ListeDeSolutionShape2.Remove(i);
+    Standard_Integer i = 1;
+    for (; i <= mySolutionsShape1.Length(); i++)
+      if (mySolutionsShape1.Value(i).Dist() > myDistRef + myEps)
+      {
+        mySolutionsShape1.Remove(i);
+        mySolutionsShape2.Remove(i);
       }
     //  Modified by Sergey KHROMOV - Tue Mar  6 11:55:04 2001 End
-    myNbSolution = ListeDeSolutionShape1.Length();
-    if( myNbSolution > 0 )
-      myIsDone = Standard_True;
-    else
-      myIsDone = Standard_False;
+    myIsDone = ( mySolutionsShape1.Length() > 0 );
   }
   return myIsDone;
 }
 
-//=======================================================================
-//function : 
-//purpose  : 
-//=======================================================================
-
-Standard_Boolean BRepExtrema_DistShapeShape:: InnerSolution () const 
-{ 
-  return (myInnerSol);
-}
-
-//=======================================================================
-//function : IsDone
-//purpose  : 
-//=======================================================================
-
-Standard_Boolean BRepExtrema_DistShapeShape::IsDone() const 
-{ 
-  return (myIsDone);
-}
-
-//=======================================================================
-//function : NbSolution
-//purpose  : 
-//=======================================================================
-
-Standard_Integer BRepExtrema_DistShapeShape::NbSolution() const 
-{ 
-  if (myIsDone == Standard_False) {
-    StdFail_NotDone::Raise
-      ("BRepExtrema_DistShapeShape::NbSolution: There's no solution ");
-  }  
-  return (myNbSolution);
-}
-
 //=======================================================================
 //function : Value
 //purpose  : 
@@ -332,83 +306,10 @@ Standard_Integer BRepExtrema_DistShapeShape::NbSolution() const
 
 Standard_Real BRepExtrema_DistShapeShape::Value() const 
 { 
-  if (myIsDone == Standard_False) {
-    StdFail_NotDone::Raise
-      ("BRepExtrema_DistShapeShape::Value: There's no solution ");
-  }  
-  return (myDistRef);
-}
+  if (!myIsDone)
+    StdFail_NotDone::Raise("BRepExtrema_DistShapeShape::Value: There's no solution ");
 
-//=======================================================================
-//function : PointOnShape1
-//purpose  : 
-//=======================================================================
-
-gp_Pnt BRepExtrema_DistShapeShape::PointOnShape1(const Standard_Integer N) const 
-{ 
-  if (myIsDone == Standard_False)
-     { StdFail_NotDone::Raise
-       ("BRepExtrema_DistShapeShape::PointOnShape1: There's no solution ");
-     } 
-  if ((N<1)||(N>myNbSolution))
-     { Standard_OutOfRange::Raise
-       ("BRepExtrema_DistShapeShape::PointOnShape1:  Nth solution doesn't exist ");
-     } 
-  return ((ListeDeSolutionShape1.Value(N)).Point());
-}
-
-//=======================================================================
-//function : PointOnShape2
-//purpose  : 
-//=======================================================================
-
-gp_Pnt BRepExtrema_DistShapeShape::PointOnShape2(const Standard_Integer N) const 
-{ 
-  if (myIsDone == Standard_False)
-     { StdFail_NotDone::Raise
-       ("BRepExtrema_DistShapeShape::PointOnShape2: There's no solution ");
-     } 
-  if ((N<1)||(N>myNbSolution))
-     { Standard_OutOfRange::Raise
-       ("BRepExtrema_DistShapeShape::PointOnShape2:  Nth solution doesn't exist ");
-     } 
-  return ((ListeDeSolutionShape2.Value(N)).Point());
-}
-
-//=======================================================================
-//function : SupportTypeShape1
-//purpose  : 
-//=======================================================================
-
-BRepExtrema_SupportType BRepExtrema_DistShapeShape::SupportTypeShape1(const Standard_Integer N) const 
-{ 
-  if (myIsDone == Standard_False)
-     { StdFail_NotDone::Raise
-       ("BRepExtrema_DistShapeShape::SupportTypeShape1: There's no solution ");
-     } 
-  if ((N<1)||(N>myNbSolution))
-     { Standard_OutOfRange::Raise
-       ("BRepExtrema_DistShapeShape::SupportTypeShape1:  Nth solution doesn't exist ");
-     } 
- return ((ListeDeSolutionShape1.Value(N)).SupportKind());
-}
-
-//=======================================================================
-//function : SupportTypeShape2
-//purpose  : 
-//=======================================================================
-
-BRepExtrema_SupportType BRepExtrema_DistShapeShape::SupportTypeShape2(const Standard_Integer N) const 
-{ 
-  if (myIsDone == Standard_False)
-     { StdFail_NotDone::Raise
-       ("BRepExtrema_DistShapeShape::SupportTypeShape2: There's no solution ");
-     } 
-  if ((N<1)||(N>myNbSolution))
-     { Standard_OutOfRange::Raise
-       ("BRepExtrema_DistShapeShape::SupportTypeShape2:  Nth solution doesn't exist ");
-     } 
- return ((ListeDeSolutionShape2.Value(N)).SupportKind());
+  return myDistRef;
 }
 
 //=======================================================================
@@ -416,30 +317,19 @@ BRepExtrema_SupportType BRepExtrema_DistShapeShape::SupportTypeShape2(const Stan
 //purpose  : 
 //=======================================================================
 
-TopoDS_Shape BRepExtrema_DistShapeShape::SupportOnShape1(const Standard_Integer N) const 
+TopoDS_Shape BRepExtrema_DistShapeShape::SupportOnShape1(const Standard_Integer N) const
 { 
-  BRepExtrema_SupportType Type;
-  TopoDS_Shape a_shape;
-  if (myIsDone == Standard_False)
-     { StdFail_NotDone::Raise
-       ("BRepExtrema_DistShapeShape::SupportOnShape1: There's no solution ");
-     } 
-  if ((N<1)||(N>myNbSolution))
-     { Standard_OutOfRange::Raise
-       ("BRepExtrema_DistShapeShape::SupportOnShape1:  Nth solution doesn't exist ");
-     } 
-  Type = ((ListeDeSolutionShape1.Value(N)).SupportKind());  
-  switch ( Type)
-   { case BRepExtrema_IsVertex : a_shape=ListeDeSolutionShape1.Value(N).Vertex();
-                                 break;
-     case BRepExtrema_IsOnEdge : a_shape=ListeDeSolutionShape1.Value(N).Edge();
-                                 break;       
-     case BRepExtrema_IsInFace : a_shape=ListeDeSolutionShape1.Value(N).Face();
-                                 break;        
-     default :{} 
-   }
-  return a_shape ;
+  if (!myIsDone)
+    StdFail_NotDone::Raise("BRepExtrema_DistShapeShape::SupportOnShape1: There's no solution ");
+
+  const BRepExtrema_SolutionElem &sol = mySolutionsShape1.Value(N);
+  switch (sol.SupportKind())
+  {
+    case BRepExtrema_IsVertex : return sol.Vertex();
+    case BRepExtrema_IsOnEdge : return sol.Edge();
+    case BRepExtrema_IsInFace : return sol.Face();
+  }
+  return TopoDS_Shape();
 }
 
 //=======================================================================
@@ -449,28 +339,17 @@ TopoDS_Shape BRepExtrema_DistShapeShape::SupportOnShape1(const Standard_Integer
 
 TopoDS_Shape BRepExtrema_DistShapeShape::SupportOnShape2(const Standard_Integer N) const 
 { 
-  BRepExtrema_SupportType Type;   
-  TopoDS_Shape a_shape ;
-  
-  if (myIsDone == Standard_False)
-     { StdFail_NotDone::Raise
-       ("BRepExtrema_DistShapeShape::SupportOnShape2: There's no solution ");
-     } 
-  if ((N<1)||(N>myNbSolution))
-     { Standard_OutOfRange::Raise
-       ("BRepExtrema_DistShapeShape::SupportOnShape2:  Nth solution doesn't exist ");
-     } 
-  Type = ((ListeDeSolutionShape2.Value(N)).SupportKind());  
-  switch ( Type)
-   { case BRepExtrema_IsVertex : a_shape=ListeDeSolutionShape2.Value(N).Vertex();
-                                 break;
-     case BRepExtrema_IsOnEdge : a_shape=ListeDeSolutionShape2.Value(N).Edge();
-                                 break;       
-     case BRepExtrema_IsInFace : a_shape=ListeDeSolutionShape2.Value(N).Face();
-                                 break;        
-     default :{} 
-   } 
-  return a_shape ;
+  if (!myIsDone)
+    StdFail_NotDone::Raise("BRepExtrema_DistShapeShape::SupportOnShape2: There's no solution ");
+
+  const BRepExtrema_SolutionElem &sol = mySolutionsShape2.Value(N);
+  switch (sol.SupportKind())
+  {
+    case BRepExtrema_IsVertex : return sol.Vertex();
+    case BRepExtrema_IsOnEdge : return sol.Edge();
+    case BRepExtrema_IsInFace : return sol.Face();
+  }
+  return TopoDS_Shape();
 }
 
 //=======================================================================
@@ -480,24 +359,15 @@ TopoDS_Shape BRepExtrema_DistShapeShape::SupportOnShape2(const Standard_Integer
 
 void BRepExtrema_DistShapeShape::ParOnEdgeS1(const Standard_Integer N, Standard_Real& t) const 
 { 
-  BRepExtrema_SupportType Type;
-  if (myIsDone == Standard_False)
-     { StdFail_NotDone::Raise
-       ("BRepExtrema_DistShapeShape::ParOnEdgeS1: There's no solution ");
-     } 
-  if ((N<1)||(N>myNbSolution))
-     { Standard_OutOfRange::Raise
-       ("BRepExtrema_DistShapeShape::ParOnEdgeS1:  Nth solution doesn't exist ");
-     } 
-
-  Type = ((ListeDeSolutionShape1.Value(N)).SupportKind());  
-  if (Type != BRepExtrema_IsOnEdge)
-     { BRepExtrema_UnCompatibleShape::Raise
-       ("BRepExtrema_DistShapeShape::ParOnEdgeS1:ParOnEdgeS1 is impossible without EDGE  ");
-     }  
-
-  (ListeDeSolutionShape1.Value(N)).EdgeParameter(t);
+  if (!myIsDone)
+    StdFail_NotDone::Raise("BRepExtrema_DistShapeShape::ParOnEdgeS1: There's no solution");
+
+  const BRepExtrema_SolutionElem &sol = mySolutionsShape1.Value(N);
+  if (sol.SupportKind() != BRepExtrema_IsOnEdge)
+    BRepExtrema_UnCompatibleShape::Raise
+      ("BRepExtrema_DistShapeShape::ParOnEdgeS1: ParOnEdgeS1 is impossible without EDGE");
+
+  sol.EdgeParameter(t);
 }
 
 //=======================================================================
@@ -507,24 +377,15 @@ void BRepExtrema_DistShapeShape::ParOnEdgeS1(const Standard_Integer N, Standard_
 
 void BRepExtrema_DistShapeShape::ParOnEdgeS2(const Standard_Integer N,  Standard_Real& t) const 
 { 
-  BRepExtrema_SupportType Type;
-
-  if (myIsDone == Standard_False)
-     { StdFail_NotDone::Raise
-       ("BRepExtrema_DistShapeShape::ParOnEdgeS2: There's no solution ");
-     } 
-  if ((N<1)||(N>myNbSolution))
-     { Standard_OutOfRange::Raise
-       ("BRepExtrema_DistShapeShape::ParOnEdgeS2:  Nth solution doesn't exist ");
-     } 
-
-  Type = ((ListeDeSolutionShape2.Value(N)).SupportKind());  
-  if (Type != BRepExtrema_IsOnEdge)
-     { BRepExtrema_UnCompatibleShape::Raise
-       ("BRepExtrema_DistShapeShape::ParOnEdgeS2:ParOnEdgeS2 is impossible without EDGE  ");
-     }  
+  if (!myIsDone)
+    StdFail_NotDone::Raise("BRepExtrema_DistShapeShape::ParOnEdgeS2: There's no solution");
+
+  const BRepExtrema_SolutionElem &sol = mySolutionsShape2.Value(N);
+  if (sol.SupportKind() != BRepExtrema_IsOnEdge)
+    BRepExtrema_UnCompatibleShape::Raise
+      ("BRepExtrema_DistShapeShape::ParOnEdgeS2: ParOnEdgeS2 is impossible without EDGE");
  
-  (ListeDeSolutionShape2.Value(N)).EdgeParameter(t);
+  sol.EdgeParameter(t);
 }
 
 //=======================================================================
@@ -534,46 +395,33 @@ void BRepExtrema_DistShapeShape::ParOnEdgeS2(const Standard_Integer N,  Standard
 
 void BRepExtrema_DistShapeShape::ParOnFaceS1(const Standard_Integer N,  Standard_Real& u,  Standard_Real& v) const 
 { 
-  BRepExtrema_SupportType Type;
-
-  if (myIsDone == Standard_False)
-     { StdFail_NotDone::Raise
-       ("BRepExtrema_DistShapeShape::ParOnFaceS1: There's no solution ");
-     } 
-  if ((N<1)||(N>myNbSolution))
-     { Standard_OutOfRange::Raise
-       ("BRepExtrema_DistShapeShape::ParOnFaceS1:  Nth solution doesn't exist ");
-     } 
-
-  Type = ((ListeDeSolutionShape1.Value(N)).SupportKind());  
-  if (Type != BRepExtrema_IsInFace)
-    { BRepExtrema_UnCompatibleShape::Raise
-        ("BRepExtrema_DistShapeShape::ParOnFaceS1:ParOnFaceS1 is impossible without FACE ");
-    }  
+  if (!myIsDone)
+    StdFail_NotDone::Raise("BRepExtrema_DistShapeShape::ParOnFaceS1: There's no solution");
+
+  const BRepExtrema_SolutionElem &sol = mySolutionsShape1.Value(N);
+  if (sol.SupportKind() != BRepExtrema_IsInFace)
+    BRepExtrema_UnCompatibleShape::Raise
+      ("BRepExtrema_DistShapeShape::ParOnFaceS1: ParOnFaceS1 is impossible without FACE");
   
-  (ListeDeSolutionShape1.Value(N)).FaceParameter(u, v); 
+  sol.FaceParameter(u, v);
 }
 
+//=======================================================================
+//function : ParOnFaceS2
+//purpose  : 
+//=======================================================================
+
 void BRepExtrema_DistShapeShape::ParOnFaceS2(const Standard_Integer N,  Standard_Real& u, Standard_Real& v) const 
 { 
-  BRepExtrema_SupportType  Type;     
-
-  if (myIsDone == Standard_False)
-     { StdFail_NotDone::Raise
-       ("BRepExtrema_DistShapeShape::ParOnFaceS2: There's no solution ");
-     } 
-  if ((N<1)||(N>myNbSolution))
-     { Standard_OutOfRange::Raise
-       ("BRepExtrema_DistShapeShape::ParOnFaceS2:  Nth solution doesn't exist ");
-     } 
-  Type = ((ListeDeSolutionShape2.Value(N)).SupportKind());  
-  if (Type != BRepExtrema_IsInFace)
-    { BRepExtrema_UnCompatibleShape::Raise
-        ("BRepExtrema_DistShapeShape::ParOnFaceS2:ParOnFaceS2 is impossible without FACE ");
-    }  
-  
-  (ListeDeSolutionShape2.Value(N)).FaceParameter(u, v); 
+  if (!myIsDone)
+    StdFail_NotDone::Raise("BRepExtrema_DistShapeShape::ParOnFaceS2: There's no solution");
 
+  const BRepExtrema_SolutionElem &sol = mySolutionsShape2.Value(N);
+  if (sol.SupportKind() != BRepExtrema_IsInFace)
+    BRepExtrema_UnCompatibleShape::Raise
+      ("BRepExtrema_DistShapeShape::ParOnFaceS2:ParOnFaceS2 is impossible without FACE ");
+  
+  sol.FaceParameter(u, v);
 }
 
 //=======================================================================
@@ -585,13 +433,13 @@ void BRepExtrema_DistShapeShape::Dump(Standard_OStream& o) const
 {
   Standard_Integer i;
   Standard_Real r1,r2;
-  BRepExtrema_SupportType       Type1, Type2;
   
   o<< "the distance  value is :  " << Value()<<endl;
   o<< "the number of solutions is :"<<NbSolution()<<endl;
   o<<endl;
-  for (i=1;i<=NbSolution();i++) { 
-    o<<"solution number "<<i<<": "<< endl; 
+  for (i=1;i<=NbSolution();i++)
+  {
+    o<<"solution number "<<i<<": "<< endl;
     o<<"the type of the solution on the first shape is " <<Standard_Integer( SupportTypeShape1(i)) <<endl; 
     o<<"the type of the solution on the second shape is "<<Standard_Integer( SupportTypeShape2(i))<< endl;
     o<< "the coordinates of  the point on the first shape are: "<<endl; 
@@ -599,29 +447,28 @@ void BRepExtrema_DistShapeShape::Dump(Standard_OStream& o) const
     o<< "the coordinates of  the point on the second shape are: "<<endl; 
     o<<"X="<< PointOnShape2(i).X()<< " Y="<<PointOnShape2(i).Y()<<" Z="<< PointOnShape2(i).Z()<<endl;
     
-     Type1=SupportTypeShape1(i);
-     Type2=SupportTypeShape2(i);
-     if (Type1 == BRepExtrema_IsOnEdge) 
-       { 
-        ParOnEdgeS1(i,r1);
-        o << "parameter on the first edge :  t= " << r1 << endl;
-       } 
-     if (Type1 == BRepExtrema_IsInFace) 
-       {
-        ParOnFaceS1(i,r1,r2);
-        o << "parameters on the first face :  u= " << r1 << " v=" <<  r2 << endl;
-       }
-      if (Type2 == BRepExtrema_IsOnEdge) 
-       {
-        ParOnEdgeS2(i,r1);
-        o << "parameter on the second edge : t=" << r1 << endl;
-       } 
-    if (Type2 == BRepExtrema_IsInFace) 
-       {
-        ParOnFaceS2(i,r1,r2);
-        o << "parameters on the second face : u= " << r1 << " v=" <<  r2 << endl;
-        }
-    
+    switch (SupportTypeShape1(i))
+    {
+      case BRepExtrema_IsOnEdge:
+        ParOnEdgeS1(i,r1);
+        o << "parameter on the first edge :  t= " << r1 << endl;
+        break;
+      case BRepExtrema_IsInFace:
+        ParOnFaceS1(i,r1,r2);
+        o << "parameters on the first face :  u= " << r1 << " v=" <<  r2 << endl;
+        break;
+    }
+    switch (SupportTypeShape2(i))
+    {
+      case BRepExtrema_IsOnEdge:
+        ParOnEdgeS2(i,r1);
+        o << "parameter on the second edge : t=" << r1 << endl;
+        break;
+      case BRepExtrema_IsInFace:
+        ParOnFaceS2(i,r1,r2);
+        o << "parameters on the second face : u= " << r1 << " v=" <<  r2 << endl;
+        break;
+    }
     o<<endl;
   } 
 }
diff --git a/src/BRepExtrema/BRepExtrema_DistShapeShape.hxx b/src/BRepExtrema/BRepExtrema_DistShapeShape.hxx
new file mode 100644 (file)
index 0000000..119f81a
--- /dev/null
@@ -0,0 +1,215 @@
+// File generated by CPPExt (Value)
+//
+//                     Copyright (C) 1991 - 2000 by  
+//                      Matra Datavision SA.  All rights reserved.
+//  
+//                     Copyright (C) 2001 - 2004 by
+//                     Open CASCADE SA.  All rights reserved.
+// 
+// This file is part of the Open CASCADE Technology software.
+//
+// This software may be distributed and/or modified under the terms and
+// conditions of the Open CASCADE Public License as defined by Open CASCADE SA
+// and appearing in the file LICENSE included in the packaging of this file.
+//  
+// This software is distributed on an "AS IS" basis, without warranty of any
+// kind, and Open CASCADE SA hereby disclaims all such warranties,
+// including without limitation, any warranties of merchantability, fitness
+// for a particular purpose or non-infringement. Please see the License for
+// the specific terms and conditions governing rights and limitations under the
+// License.
+
+#ifndef _BRepExtrema_DistShapeShape_HeaderFile
+#define _BRepExtrema_DistShapeShape_HeaderFile
+
+#ifndef _Standard_HeaderFile
+#include <Standard.hxx>
+#endif
+#ifndef _Standard_Macro_HeaderFile
+#include <Standard_Macro.hxx>
+#endif
+
+#ifndef _Standard_Integer_HeaderFile
+#include <Standard_Integer.hxx>
+#endif
+#ifndef _Standard_Real_HeaderFile
+#include <Standard_Real.hxx>
+#endif
+#ifndef _Standard_Boolean_HeaderFile
+#include <Standard_Boolean.hxx>
+#endif
+#ifndef _BRepExtrema_SeqOfSolution_HeaderFile
+#include <BRepExtrema_SeqOfSolution.hxx>
+#endif
+#ifndef _BRepExtrema_SolutionElem_HeaderFile
+#include <BRepExtrema_SolutionElem.hxx>
+#endif
+#ifndef _TopoDS_Shape_HeaderFile
+#include <TopoDS_Shape.hxx>
+#endif
+#ifndef _TopTools_IndexedMapOfShape_HeaderFile
+#include <TopTools_IndexedMapOfShape.hxx>
+#endif
+#ifndef _Extrema_ExtFlag_HeaderFile
+#include <Extrema_ExtFlag.hxx>
+#endif
+#ifndef _Extrema_ExtAlgo_HeaderFile
+#include <Extrema_ExtAlgo.hxx>
+#endif
+#ifndef _BRepExtrema_SupportType_HeaderFile
+#include <BRepExtrema_SupportType.hxx>
+#endif
+#ifndef _Standard_OStream_HeaderFile
+#include <Standard_OStream.hxx>
+#endif
+#ifndef _gp_Pnt_HeaderFile
+#include <gp_Pnt.hxx>
+#endif
+class TopoDS_Shape;
+class TopTools_IndexedMapOfShape;
+class Bnd_SeqOfBox;
+
+
+//! This class  provides tools to compute minimum distance <br>
+//! between two Shapes (Compound,CompSolid, Solid, Shell, Face, Wire, Edge, Vertex). <br>
+class BRepExtrema_DistShapeShape
+{
+ public:
+
+  void* operator new(size_t,void* anAddress) 
+  {
+    return anAddress;
+  }
+  void* operator new(size_t size) 
+  {
+    return Standard::Allocate(size); 
+  }
+  void  operator delete(void *anAddress) 
+  {
+    if (anAddress) Standard::Free((Standard_Address&)anAddress); 
+  }
+
+  //! create empty tool <br>
+  Standard_EXPORT BRepExtrema_DistShapeShape();
+  //! computation of the minimum distance (value and pair of points) using default deflection <br>
+  //! Default value is Precision::Confusion(). <br>
+  Standard_EXPORT BRepExtrema_DistShapeShape(const TopoDS_Shape& Shape1,const TopoDS_Shape& Shape2,const Extrema_ExtFlag F = Extrema_ExtFlag_MINMAX,const Extrema_ExtAlgo A = Extrema_ExtAlgo_Grad);
+  //! create tool and load both shapes into it <br>
+  Standard_EXPORT BRepExtrema_DistShapeShape(const TopoDS_Shape& Shape1,const TopoDS_Shape& Shape2,const Standard_Real theDeflection,const Extrema_ExtFlag F = Extrema_ExtFlag_MINMAX,const Extrema_ExtAlgo A = Extrema_ExtAlgo_Grad);
+  
+  Standard_EXPORT void SetDeflection(const Standard_Real theDeflection)
+  {
+    myEps = theDeflection;
+  }
+  //! load first shape into extrema <br>
+  Standard_EXPORT void LoadS1(const TopoDS_Shape& Shape1);
+  //! load second shape into extrema <br>
+  Standard_EXPORT void LoadS2(const TopoDS_Shape& Shape1);
+  //! computation of  the minimum  distance  (value  and <br>
+  //!          couple  of points). Parameter theDeflection is used <br>
+  //!          to specify a maximum deviation of extreme distances <br>
+  //!          from the minimum one. <br>
+  //!          Returns IsDone status. <br>
+  Standard_EXPORT Standard_Boolean Perform();
+  //! True if the minimum distance is found. <br>
+  Standard_EXPORT Standard_Boolean IsDone() const
+  { 
+    return myIsDone;
+  }
+  //! Returns the number of solutions satisfying the minimum distance. <br>
+  Standard_EXPORT Standard_Integer NbSolution() const
+  { 
+    return mySolutionsShape1.Length();
+  }
+  //! Returns the value of the minimum distance. <br>
+  Standard_EXPORT Standard_Real Value() const;
+  //! True if one of the shapes is a solid and the other shape <br>
+  //! is completely or partially inside the solid. <br>
+  Standard_EXPORT Standard_Boolean InnerSolution() const
+  { 
+    return myInnerSol;
+  }
+  //! Returns the Point corresponding to the <N>th solution on the first Shape <br>
+  Standard_EXPORT const gp_Pnt & PointOnShape1(const Standard_Integer N) const
+  { 
+    return mySolutionsShape1.Value(N).Point();
+  }
+  //! Returns the Point corresponding to the <N>th solution on the second Shape <br>
+  Standard_EXPORT const gp_Pnt & PointOnShape2(const Standard_Integer N) const
+  { 
+    return mySolutionsShape2.Value(N).Point();
+  }
+  //! gives the type of the support where the Nth solution on the first shape is situated: <br>
+  //!   IsVertex => the Nth solution on the first shape is a Vertex <br>
+  //!   IsOnEdge => the Nth soluion on the first shape is on a Edge <br>
+  //!   IsInFace => the Nth solution on the first shape is inside a face <br>
+  //! the corresponding support is obtained by the method SupportOnShape1 <br>
+  Standard_EXPORT BRepExtrema_SupportType SupportTypeShape1(const Standard_Integer N) const
+  { 
+    return mySolutionsShape1.Value(N).SupportKind();
+  }
+  //! gives the type of the support where the Nth solution on the second shape is situated: <br>
+  //!   IsVertex => the Nth solution on the second shape is a Vertex <br>
+  //!   IsOnEdge => the Nth soluion on the secondt shape is on a Edge <br>
+  //!   IsInFace => the Nth solution on the second shape is inside a face <br>
+  //! the corresponding support is obtained by the method SupportOnShape2 <br>
+  Standard_EXPORT BRepExtrema_SupportType SupportTypeShape2(const Standard_Integer N) const
+  { 
+    return mySolutionsShape2.Value(N).SupportKind();
+  }
+  //! gives the support where the Nth solution on the first shape is situated. <br>
+  //! This support can be a Vertex, an Edge or a Face. <br>
+  Standard_EXPORT TopoDS_Shape SupportOnShape1(const Standard_Integer N) const;
+  //! gives the support where the Nth solution on the second shape is situated. <br>
+  //! This support can be a Vertex, an Edge or a Face. <br>
+  Standard_EXPORT TopoDS_Shape SupportOnShape2(const Standard_Integer N) const;
+  //! gives the corresponding parameter t if the Nth solution <br>
+  //! is situated on an Egde of the first shape <br>
+  Standard_EXPORT void ParOnEdgeS1(const Standard_Integer N,Standard_Real& t) const;
+  //! gives the corresponding parameter t if the Nth solution <br>
+  //! is situated on an Egde of the first shape <br>
+  Standard_EXPORT void ParOnEdgeS2(const Standard_Integer N,Standard_Real& t) const;
+  //! gives the corresponding parameters (U,V) if the Nth solution <br>
+  //! is situated on an face of the first shape <br>
+  Standard_EXPORT void ParOnFaceS1(const Standard_Integer N,Standard_Real& u,Standard_Real& v) const;
+  //! gives the corresponding parameters (U,V) if the Nth solution <br>
+  //! is situated on an Face of the second shape <br>
+  Standard_EXPORT void ParOnFaceS2(const Standard_Integer N,Standard_Real& u,Standard_Real& v) const;
+  //! Prints on the stream o information on the current state of the object. <br>
+  Standard_EXPORT void Dump(Standard_OStream& o) const;
+
+  Standard_EXPORT void SetFlag(const Extrema_ExtFlag F)
+  {
+    myFlag = F;
+  }
+
+  Standard_EXPORT void SetAlgo(const Extrema_ExtAlgo A)
+  {
+    myAlgo = A;
+  }
+
+private:
+
+  //! computes the minimum distance between two maps of shapes (Face,Edge,Vertex) <br>
+  Standard_EXPORT void DistanceMapMap(const TopTools_IndexedMapOfShape& Map1,const TopTools_IndexedMapOfShape& Map2,const Bnd_SeqOfBox& LBox1,const Bnd_SeqOfBox& LBox2);
+
+  Standard_Real myDistRef;
+  Standard_Real myDistValue;
+  Standard_Boolean myIsDone;
+  BRepExtrema_SeqOfSolution mySolutionsShape1;
+  BRepExtrema_SeqOfSolution mySolutionsShape2;
+  Standard_Boolean myInnerSol;
+  Standard_Real myEps;
+  TopoDS_Shape myShape1;
+  TopoDS_Shape myShape2;
+  TopTools_IndexedMapOfShape myMapV1;
+  TopTools_IndexedMapOfShape myMapV2;
+  TopTools_IndexedMapOfShape myMapE1;
+  TopTools_IndexedMapOfShape myMapE2;
+  TopTools_IndexedMapOfShape myMapF1;
+  TopTools_IndexedMapOfShape myMapF2;
+  Extrema_ExtFlag myFlag;
+  Extrema_ExtAlgo myAlgo;
+};
+
+#endif
index 22e60db..828e4f1 100755 (executable)
@@ -1,18 +1,18 @@
-// File:       BRepExtrema_DistanceSS.cxx
-// Created:    Mon Apr 22 17:03:37 1996
+// File:    BRepExtrema_DistanceSS.cxx
+// Created: Mon Apr 22 17:03:37 1996
 // Author:     Maria PUMBORIOS
-// Author:      Herve LOUESSARD 
-//             <mps@sgi64>
+// Author:  Herve LOUESSARD 
 
+// Modified: Sergey ZERCHANINOV
+
+#include <BRepExtrema_DistanceSS.hxx>
 
-#include <BRepExtrema_DistanceSS.ixx>
 #include <TopTools_IndexedMapOfShape.hxx>
 #include <TopExp.hxx>
 #include <gp_Pnt.hxx>
 #include <gp_Pnt2d.hxx>
 #include <BRep_Tool.hxx>
 #include <BRepExtrema_SupportType.hxx>
-#include <Precision.hxx>
 #include <Standard_Real.hxx>
 #include <BRepExtrema_SolutionElem.hxx>
 #include <BRepExtrema_SeqOfSolution.hxx>
@@ -23,6 +23,7 @@
 #include <Bnd_Box.hxx>
 #include <BRepExtrema_ExtPC.hxx>
 #include <BRepExtrema_ExtPF.hxx>
+#include <Extrema_ExtFlag.hxx>
 #include <BRepExtrema_ExtCC.hxx>
 #include <BRepExtrema_ExtCF.hxx>
 #include <BRepExtrema_ExtFF.hxx>
 #include <TColgp_Array1OfPnt.hxx>
 
 
-
-/*********************************************************************************/
 /*********************************************************************************/
 
 //------------------------------------------------------------------------------
 // function: TRI_SOLUTION
 //------------------------------------------------------------------------------
-void TRI_SOLUTION (const BRepExtrema_SeqOfSolution& SeqSol,
-                  const gp_Pnt& Pt, Standard_Boolean& inserer )
+static Standard_Boolean TRI_SOLUTION (const BRepExtrema_SeqOfSolution& SeqSol, const gp_Pnt& Pt)
 {
- inserer = Standard_True;
- Standard_Integer Nbsol= SeqSol.Length();
- Standard_Integer i;
- Standard_Real dst;
- for (i=1;i<=Nbsol;i++)
-    {gp_Pnt P1=SeqSol.Value(i).Point();
-     dst=P1.Distance(Pt);
-     if (dst<=Precision::Confusion()) inserer=Standard_False;}  
+  const Standard_Integer Nbsol = SeqSol.Length();
+  for (Standard_Integer i = 1; i <= Nbsol; i++)
+  {
+    const Standard_Real dst = SeqSol.Value(i).Point().Distance(Pt);
+    if (dst <= Precision::Confusion()) return Standard_False;
+  }
+  return Standard_True;
 }  
 
 //------------------------------------------------------------------------------
 // function: MIN_SOLUTION
 //------------------------------------------------------------------------------
-void MIN_SOLUTION (const BRepExtrema_SeqOfSolution& SeqSol1,
-                  const BRepExtrema_SeqOfSolution& SeqSol2,
-                  const Standard_Real& DstRef,
-                  const Standard_Real& Eps,
-                  BRepExtrema_SeqOfSolution& seqSol1,
-                  BRepExtrema_SeqOfSolution& seqSol2)
+static void MIN_SOLUTION (const BRepExtrema_SeqOfSolution& SeqSol1,
+                          const BRepExtrema_SeqOfSolution& SeqSol2,
+                          const Standard_Real DstRef,
+                          const Standard_Real Eps,
+                          BRepExtrema_SeqOfSolution& seqSol1,
+                          BRepExtrema_SeqOfSolution& seqSol2)
 {
-  Standard_Real dst1;
-  Standard_Integer nbSol = SeqSol1.Length();
-  
-  for (Standard_Integer i = 1; i<=nbSol; i++)
-    {
-      dst1 = SeqSol1.Value(i).Dist();
-      
-      if (fabs(dst1 - DstRef) < Eps)
+  const Standard_Integer nbSol = SeqSol1.Length();
+  for (Standard_Integer i = 1; i <= nbSol; i++)
+  {
+    const Standard_Real dst1 = SeqSol1.Value(i).Dist();
+    if (fabs(dst1 - DstRef) < Eps)
        {         
-         seqSol1.Append(SeqSol1.Value(i));
-         seqSol2.Append(SeqSol2.Value(i));     
+      seqSol1.Append(SeqSol1.Value(i));
+      seqSol2.Append(SeqSol2.Value(i));
        }
-    }
+  }
 }
 
-
 //------------------------------------------------------------------------------
 // function: TRIM_INFINIT_EDGE
 //------------------------------------------------------------------------------
-void TRIM_INFINIT_EDGE(const TopoDS_Edge& S1, 
-                      const TopoDS_Edge& S2,                  
-                      TopoDS_Edge& aResEdge,
-                      Standard_Boolean& bIsTrim1,
-                      Standard_Boolean& bIsTrim2)
+static void TRIM_INFINIT_EDGE(const TopoDS_Edge& S1, const TopoDS_Edge& S2, TopoDS_Edge& aResEdge,
+                              Standard_Boolean& bIsTrim1, Standard_Boolean& bIsTrim2)
 {
-  if ( BRep_Tool::Degenerated(S1) ||
-       BRep_Tool::Degenerated(S2) )
+  if ( BRep_Tool::Degenerated(S1) || BRep_Tool::Degenerated(S2) )
     return;
 
   aResEdge = S2;
   Standard_Real aFirst1, aLast1, aFirst2, aLast2;
-  Handle(Geom_Curve) pCurv;
   Handle(Geom_Curve) pCurv1 = BRep_Tool::Curve(S1, aFirst1, aLast1);
   Handle(Geom_Curve) pCurv2 = BRep_Tool::Curve(S2, aFirst2, aLast2);
 
-  Standard_Real Umin, Umax;
-  Standard_Boolean bUmin, bUmax;
-  bUmin = bUmax = Standard_False;
-
   if (Precision::IsInfinite(aFirst1) &&
       Precision::IsInfinite(aLast1)  &&
       Precision::IsInfinite(aFirst2) &&
       Precision::IsInfinite(aLast2))
     return;
-
   
-  if ( !pCurv1.IsNull() && (Precision::IsInfinite(aFirst1) ||
-                           Precision::IsInfinite(aLast1)) )
+  Standard_Real Umin, Umax;
+  Standard_Boolean bUmin, bUmax;
+  bUmin = bUmax = Standard_False;
+
+  Handle(Geom_Curve) pCurv;
+  if ( !pCurv1.IsNull() && (Precision::IsInfinite(aFirst1) || Precision::IsInfinite(aLast1)) )
+  {
+    pCurv = pCurv1;
+    bIsTrim1 = Standard_True;
+    if (!Precision::IsInfinite(aFirst1))
     {
-      pCurv = pCurv1;
-      bIsTrim1 = Standard_True;
-      if (!Precision::IsInfinite(aFirst1))
-       {
-         bUmin = Standard_True;
-         Umin = aFirst1;
-       }
-      else if (!Precision::IsInfinite(aLast1))
-       {
-         bUmax = Standard_True;
-         Umax = aLast1;
-       }
+      bUmin = Standard_True;
+      Umin = aFirst1;
     }
-  else if ( !pCurv2.IsNull() && (Precision::IsInfinite(aFirst2) ||
-                                Precision::IsInfinite(aLast2)) )
+    else if (!Precision::IsInfinite(aLast1))
     {
-      pCurv = pCurv2;
-      bIsTrim2 = Standard_True;
-      if (!Precision::IsInfinite(aFirst2))
-       {
-         bUmin = Standard_True;
-         Umin = aFirst2;
-       }
-      else if (!Precision::IsInfinite(aLast2))
-       {
-         bUmax = Standard_True;
-         Umax = aLast2;
-       }
+      bUmax = Standard_True;
+      Umax = aLast1;
     }
-  if (bIsTrim1 || bIsTrim2)
+  }
+  else if ( !pCurv2.IsNull() && (Precision::IsInfinite(aFirst2) || Precision::IsInfinite(aLast2)) )
+  {
+    pCurv = pCurv2;
+    bIsTrim2 = Standard_True;
+    if (!Precision::IsInfinite(aFirst2))
     {
-      Bnd_Box aEdgeBox;
-      if (bIsTrim1)
-       BRepBndLib::Add(S2, aEdgeBox);
-      if (bIsTrim2)
-       BRepBndLib::Add(S1, aEdgeBox);
-      Standard_Real Xmin, Ymin, Zmin, Xmax, Ymax, Zmax;
-      aEdgeBox.Get(Xmin, Ymin, Zmin, Xmax, Ymax, Zmax);      
-
-
-      TColStd_Array1OfReal arrU(1, 8);
-      TColgp_Array1OfPnt arrPnt(1, 8);
-
-      gp_Pnt aPnt1(Xmin, Ymin, Zmin);
-      arrPnt.SetValue(1, aPnt1);
-      gp_Pnt aPnt2(Xmin, Ymax, Zmin);
-      arrPnt.SetValue(2, aPnt2);
-      gp_Pnt aPnt3(Xmin, Ymax, Zmax);
-      arrPnt.SetValue(3, aPnt3);
-      gp_Pnt aPnt4(Xmin, Ymin, Zmax);
-      arrPnt.SetValue(4, aPnt4);
-      gp_Pnt aPnt5(Xmax, Ymax, Zmin);
-      arrPnt.SetValue(5, aPnt5);
-      gp_Pnt aPnt6(Xmax, Ymax, Zmax);
-      arrPnt.SetValue(6, aPnt6);
-      gp_Pnt aPnt7(Xmax, Ymin, Zmax);
-      arrPnt.SetValue(7, aPnt7);
-      gp_Pnt aPnt8(Xmax, Ymin, Zmin);
-      arrPnt.SetValue(8, aPnt8);
-      
-      Standard_Real U;
-      Standard_Integer i = 1;
-
-      GeomAPI_ProjectPointOnCurve aProj(aPnt1, pCurv);
-
-      for (i = 1; i <= arrPnt.Length(); i++)
-       {
-         gp_Pnt aPnt = arrPnt.Value(i);
-         aProj.Perform(aPnt);
-         U = aProj.LowerDistanceParameter();
-         arrU.SetValue(i, U);
-       }
-
-      Standard_Real aU;
-
-      if (!bUmin)
-       Umin = arrU.Value(1);
+      bUmin = Standard_True;
+      Umin = aFirst2;
+    }
+    else if (!Precision::IsInfinite(aLast2))
+    {
+      bUmax = Standard_True;
+      Umax = aLast2;
+    }
+  }
+  if (bIsTrim1 || bIsTrim2)
+  {
+    Bnd_Box aEdgeBox;
+    if (bIsTrim1)
+      BRepBndLib::Add(S2, aEdgeBox);
+    if (bIsTrim2)
+      BRepBndLib::Add(S1, aEdgeBox);
+    Standard_Real Xmin, Ymin, Zmin, Xmax, Ymax, Zmax;
+    aEdgeBox.Get(Xmin, Ymin, Zmin, Xmax, Ymax, Zmax);
+
+    const gp_Pnt aPnt0(Xmin, Ymin, Zmin);
+    const gp_Pnt aPnt1(Xmin, Ymax, Zmin);
+    const gp_Pnt aPnt2(Xmin, Ymax, Zmax);
+    const gp_Pnt aPnt3(Xmin, Ymin, Zmax);
+    const gp_Pnt aPnt4(Xmax, Ymax, Zmin);
+    const gp_Pnt aPnt5(Xmax, Ymax, Zmax);
+    const gp_Pnt aPnt6(Xmax, Ymin, Zmax);
+    const gp_Pnt aPnt7(Xmax, Ymin, Zmin);
+
+       Standard_Real arrU[8];
+    GeomAPI_ProjectPointOnCurve aProj(aPnt0, pCurv);
+    /*szv:aProj.Perform(aPnt0);*/ arrU[0] = aProj.LowerDistanceParameter();
+    aProj.Perform(aPnt1); arrU[1] = aProj.LowerDistanceParameter();
+    aProj.Perform(aPnt2); arrU[2] = aProj.LowerDistanceParameter();
+    aProj.Perform(aPnt3); arrU[3] = aProj.LowerDistanceParameter();
+    aProj.Perform(aPnt4); arrU[4] = aProj.LowerDistanceParameter();
+    aProj.Perform(aPnt5); arrU[5] = aProj.LowerDistanceParameter();
+    aProj.Perform(aPnt6); arrU[6] = aProj.LowerDistanceParameter();
+    aProj.Perform(aPnt7); arrU[7] = aProj.LowerDistanceParameter();
+    
+    if (!bUmin)
+      Umin = arrU[0];
        
-      if (!bUmax)
-       Umax = arrU.Value(1);
+    if (!bUmax)
+      Umax = arrU[0];
 
-      for(i = 1; i <= arrU.Length(); i++)
+    Standard_Integer i = 0;
+    while (i < 8)
        {
-         aU = arrU.Value(i);
+      const Standard_Real aU = arrU[i++];
          if (aU < Umin)
            Umin = aU;
          else if (aU > Umax)
            Umax = aU;
-
-       }
-      GeomAdaptor_Curve aGAC(pCurv);
-      Standard_Real tol = Precision::Confusion();
-      if (bIsTrim1)
-       tol = BRep_Tool::Tolerance(S1);
-      else if (bIsTrim2)
-       tol = BRep_Tool::Tolerance(S2);
-      
-      Standard_Real EpsU = aGAC.Resolution(3*tol);
-      if (fabs(Umin - Umax) < EpsU)
-       {
-         Umin = Umin - EpsU;
-         Umax = Umax + EpsU;
        }
 
+    Standard_Real tol = Precision::Confusion();
+    if (bIsTrim1)
+      tol = BRep_Tool::Tolerance(S1);
+    else if (bIsTrim2)
+      tol = BRep_Tool::Tolerance(S2);
 
-      Handle(Geom_Curve) result = new Geom_TrimmedCurve(pCurv, Umin, Umax);
-      aResEdge = BRepBuilderAPI_MakeEdge(result);
+    const Standard_Real EpsU = GeomAdaptor_Curve(pCurv).Resolution(3.*tol);
+    if (fabs(Umin - Umax) < EpsU)
+    {
+      Umin -= EpsU;
+      Umax += EpsU;
     }
+
+    Handle(Geom_Curve) result = new Geom_TrimmedCurve(pCurv, Umin, Umax);
+    aResEdge = BRepBuilderAPI_MakeEdge(result);
+  }
 }
 
 //------------------------------------------------------------------------------
 // function: TRIM_INFINIT_FACE
 //------------------------------------------------------------------------------
-void TRIM_INFINIT_FACE(const TopoDS_Shape& S1,
-                      const TopoDS_Shape& S2,
-                      TopoDS_Face& aResFace,
-                      Standard_Boolean& bIsInfinit)
+static void TRIM_INFINIT_FACE(const TopoDS_Shape& S1, const TopoDS_Shape& S2,
+                              TopoDS_Face& aResFace, Standard_Boolean& bIsInfinit)
 {
   bIsInfinit = Standard_False;
 
-  TopAbs_ShapeEnum       Type1, Type2;
-  Type1 = S1.ShapeType();     
-  Type2 = S2.ShapeType();
+  TopAbs_ShapeEnum Type1 = S1.ShapeType();     
+  TopAbs_ShapeEnum Type2 = S2.ShapeType();
 
   TopoDS_Edge aE;
   TopoDS_Face aF;
   
   if (Type1 == TopAbs_EDGE && Type2 == TopAbs_FACE)
-    {
-      aE = TopoDS::Edge(S1);
-      if ( BRep_Tool::Degenerated(aE) )
-       return;
-      aF = TopoDS::Face(S2);
-    }
+  {
+    aE = TopoDS::Edge(S1);
+    if ( BRep_Tool::Degenerated(aE) )
+      return;
+    aF = TopoDS::Face(S2);
+  }
   else if (Type2 == TopAbs_EDGE && Type1 == TopAbs_FACE)
-    {
-      aE = TopoDS::Edge(S2);
-      if ( BRep_Tool::Degenerated(aE) )
-       return;
-      aF = TopoDS::Face(S1);
-    }
-  else
-    {
-      bIsInfinit = Standard_False;
+  {
+    aE = TopoDS::Edge(S2);
+    if ( BRep_Tool::Degenerated(aE) )
       return;
-    }  
-  Standard_Real Umin, Umax, Vmin, Vmax;
+    aF = TopoDS::Face(S1);
+  }
+  else
+  {
+    bIsInfinit = Standard_False;
+    return;
+  }
 
-  Standard_Boolean bIsTrim = Standard_False;
-  
-  
   aResFace = aF;
   Handle(Geom_Surface) pSurf = BRep_Tool::Surface(aF);
  
-  Standard_Real U1, V1, U2, V2;
-  
-  Standard_Boolean bRestrict = BRep_Tool::NaturalRestriction(aF);
+  const Standard_Boolean bRestrict = BRep_Tool::NaturalRestriction(aF);
 
+  Standard_Real U1, V1, U2, V2;
+  Standard_Real Umin, Umax, Vmin, Vmax;
   Standard_Boolean bUmin, bUmax, bVmin, bVmax;
   bUmin = bUmax = bVmin = bVmax = Standard_False;
+  Standard_Boolean bIsTrim = Standard_False;
 
   if (bRestrict)
+  {
+    pSurf->Bounds(U1, U2, V1, V2);
+    if (Precision::IsInfinite(U1))
+      bIsTrim = Standard_True;
+    else
     {
-      pSurf->Bounds(U1, U2, V1, V2);
-      if (Precision::IsInfinite(U1))
-       bIsTrim = Standard_True;
-      else
-       {
-         Umin = U1;
-         bUmin = Standard_True;
-       }
+      Umin = U1;
+      bUmin = Standard_True;
+    }
 
-      if (Precision::IsInfinite(U2))
-       bIsTrim = Standard_True;
-      else
-       {
-         Umax = U2;
-         bUmax = Standard_True;
-       }
+    if (Precision::IsInfinite(U2))
+      bIsTrim = Standard_True;
+    else
+    {
+      Umax = U2;
+      bUmax = Standard_True;
+    }
 
-      if (Precision::IsInfinite(V1))
-       bIsTrim = Standard_True;
-      else
+    if (Precision::IsInfinite(V1))
+      bIsTrim = Standard_True;
+    else
        {
-         Vmin = V1;
-         bVmin = Standard_True;
+      Vmin = V1;
+      bVmin = Standard_True;
        }
       
-      if (Precision::IsInfinite(V2))
-       bIsTrim = Standard_True;
-      else
+    if (Precision::IsInfinite(V2))
+      bIsTrim = Standard_True;
+    else
        {
-         Vmax = V2;
-         bVmax = Standard_True;
-       }
+      Vmax = V2;
+      bVmax = Standard_True;
     }
+  }
   else
-    {
-      BRepTools::UVBounds(aF, U1, U2, V1, V2);
-      if (Precision::IsInfinite(U1) &&
-         Precision::IsInfinite(U2) &&
-         Precision::IsInfinite(V1) &&
-         Precision::IsInfinite(V2))
-       bIsTrim = Standard_True;
-    }
+  {
+    BRepTools::UVBounds(aF, U1, U2, V1, V2);
+    if (Precision::IsInfinite(U1) &&
+        Precision::IsInfinite(U2) &&
+        Precision::IsInfinite(V1) &&
+        Precision::IsInfinite(V2))
+      bIsTrim = Standard_True;
+  }
 
   if (bIsTrim)
-    {      
-      Bnd_Box aEdgeBox;
-      BRepBndLib::Add(aE, aEdgeBox);
-
-      if(aEdgeBox.IsWhole())
-       return;
-
-      Standard_Real Xmin, Ymin, Zmin, Xmax, Ymax, Zmax;
-      aEdgeBox.Get(Xmin, Ymin, Zmin, Xmax, Ymax, Zmax);
-
-      TColStd_Array1OfReal arrU(1, 8);
-      TColStd_Array1OfReal arrV(1, 8);
-      TColgp_Array1OfPnt arrPnt(1, 8);
-
-      gp_Pnt aPnt1(Xmin, Ymin, Zmin);
-      arrPnt.SetValue(1, aPnt1);
-      gp_Pnt aPnt2(Xmin, Ymax, Zmin);
-      arrPnt.SetValue(2, aPnt2);
-      gp_Pnt aPnt3(Xmin, Ymax, Zmax);
-      arrPnt.SetValue(3, aPnt3);
-      gp_Pnt aPnt4(Xmin, Ymin, Zmax);
-      arrPnt.SetValue(4, aPnt4);
-      gp_Pnt aPnt5(Xmax, Ymax, Zmin);
-      arrPnt.SetValue(5, aPnt5);
-      gp_Pnt aPnt6(Xmax, Ymax, Zmax);
-      arrPnt.SetValue(6, aPnt6);
-      gp_Pnt aPnt7(Xmax, Ymin, Zmax);
-      arrPnt.SetValue(7, aPnt7);
-      gp_Pnt aPnt8(Xmax, Ymin, Zmin);
-      arrPnt.SetValue(8, aPnt8);
-      
-      Standard_Real U, V;
-      Standard_Integer i;
-      GeomAPI_ProjectPointOnSurf aProj(aPnt1, pSurf);
-      for (i = 1; i <= arrPnt.Length(); i++)
-       {
-         gp_Pnt aPnt = arrPnt.Value(i);
-         aProj.Perform(aPnt);
-         if (aProj.IsDone())
-           {
-             aProj.LowerDistanceParameters(U, V);
-             arrU.SetValue(i, U);
-             arrV.SetValue(i, V);            
-             
-           }
-       }
+  {      
+    Bnd_Box aEdgeBox;
+    BRepBndLib::Add(aE, aEdgeBox);
+
+    if(aEdgeBox.IsWhole())
+      return;
 
-      Standard_Real aU, aV;
-      if (!bUmin)
-       Umin = arrU.Value(1);
-      if (!bUmax)
-       Umax = arrU.Value(1);
-      if (!bVmin)
-       Vmin = arrV.Value(1);
-      if (!bVmax)
-       Vmax = arrV.Value(1);
-
-      for(i = 1; i <= arrU.Length(); i++)
+    Standard_Real Xmin, Ymin, Zmin, Xmax, Ymax, Zmax;
+    aEdgeBox.Get(Xmin, Ymin, Zmin, Xmax, Ymax, Zmax);
+
+    const gp_Pnt aPnt0(Xmin, Ymin, Zmin);
+    const gp_Pnt aPnt1(Xmin, Ymax, Zmin);
+    const gp_Pnt aPnt2(Xmin, Ymax, Zmax);
+    const gp_Pnt aPnt3(Xmin, Ymin, Zmax);
+    const gp_Pnt aPnt4(Xmax, Ymax, Zmin);
+    const gp_Pnt aPnt5(Xmax, Ymax, Zmax);
+    const gp_Pnt aPnt6(Xmax, Ymin, Zmax);
+    const gp_Pnt aPnt7(Xmax, Ymin, Zmin);
+
+    Standard_Real arrU[8], arrV[8];
+    GeomAPI_ProjectPointOnSurf aProj(aPnt0, pSurf);
+    /*szv:aProj.Perform(aPnt0);*/ if (aProj.IsDone()) aProj.LowerDistanceParameters(arrU[0],arrV[0]);
+    aProj.Perform(aPnt1); if (aProj.IsDone()) aProj.LowerDistanceParameters(arrU[1],arrV[1]);
+    aProj.Perform(aPnt2); if (aProj.IsDone()) aProj.LowerDistanceParameters(arrU[2],arrV[2]);
+    aProj.Perform(aPnt3); if (aProj.IsDone()) aProj.LowerDistanceParameters(arrU[3],arrV[3]);
+    aProj.Perform(aPnt4); if (aProj.IsDone()) aProj.LowerDistanceParameters(arrU[4],arrV[4]);
+    aProj.Perform(aPnt5); if (aProj.IsDone()) aProj.LowerDistanceParameters(arrU[5],arrV[5]);
+    aProj.Perform(aPnt6); if (aProj.IsDone()) aProj.LowerDistanceParameters(arrU[6],arrV[6]);
+    aProj.Perform(aPnt7); if (aProj.IsDone()) aProj.LowerDistanceParameters(arrU[7],arrV[7]);
+
+    if (!bUmin)
+      Umin = arrU[0];
+    if (!bUmax)
+      Umax = arrU[0];
+    if (!bVmin)
+      Vmin = arrV[0];
+    if (!bVmax)
+      Vmax = arrV[0];
+
+    Standard_Integer i = 0;
+    while (i < 8)
        {
-         aU = arrU.Value(i);
+      const Standard_Real aU = arrU[i];
          if (aU < Umin)
            Umin = aU;
          else if (aU > Umax)
            Umax = aU;
 
-         aV = arrV.Value(i);
+      const Standard_Real aV = arrV[i];
          if (aV < Vmin)
            Vmin = aV;
          else if (aV > Vmax)
            Vmax = aV;
        }
       
-      GeomAdaptor_Surface aGAS(pSurf);
-      Standard_Real tol = BRep_Tool::Tolerance(aF);
-      Standard_Real EpsU = aGAS.UResolution(3*tol);
-      Standard_Real EpsV = aGAS.VResolution(3*tol);
-      if (fabs(Umin - Umax) < EpsU)
-       {
-         Umin = Umin - EpsU;
-         Umax = Umax + EpsU;
-       }
+    GeomAdaptor_Surface aGAS(pSurf);
+    const Standard_Real tol = BRep_Tool::Tolerance(aF);
 
-      if (fabs(Vmin - Vmax) < EpsV)
-       {
-         Vmin = Vmin - EpsV;
-         Vmax = Vmax + EpsV;
-       }
+    const Standard_Real EpsU = aGAS.UResolution(3.*tol);
+    if (fabs(Umin - Umax) < EpsU)
+    {
+      Umin -= EpsU;
+      Umax += EpsU;
+    }
 
-      Handle(Geom_Surface) result = new Geom_RectangularTrimmedSurface(pSurf, Umin, Umax, Vmin, Vmax);
-      aResFace = BRepBuilderAPI_MakeFace(result);
-      
-      bIsInfinit = Standard_True;
+    const Standard_Real EpsV = aGAS.VResolution(3.*tol);
+    if (fabs(Vmin - Vmax) < EpsV)
+    {
+      Vmin -= EpsV;
+      Vmax += EpsV;
     }
+
+    Handle(Geom_Surface) result = new Geom_RectangularTrimmedSurface(pSurf, Umin, Umax, Vmin, Vmax);
+    aResFace = BRepBuilderAPI_MakeFace(result);
+
+    bIsInfinit = Standard_True;
+  }
   else
     bIsInfinit = Standard_False;
 }
@@ -431,1076 +378,670 @@ void TRIM_INFINIT_FACE(const TopoDS_Shape& S1,
 //------------------------------------------------------------------------------
 // static function: PERFORM_C0
 //------------------------------------------------------------------------------
-static void PERFORM_C0(TopoDS_Edge S1, 
-                      TopoDS_Edge S2, 
-                      BRepExtrema_SeqOfSolution& SeqSol1,
-                      BRepExtrema_SeqOfSolution& SeqSol2,
-                      Standard_Real DstRef,
-                      Standard_Real& mDstRef,
-                      const Standard_Real& Eps)
+static void PERFORM_C0(const TopoDS_Edge &S1, const TopoDS_Edge &S2,
+                       BRepExtrema_SeqOfSolution& SeqSol1,
+                       BRepExtrema_SeqOfSolution& SeqSol2,
+                       const Standard_Real DstRef,
+                       Standard_Real& mDstRef,
+                       const Standard_Real Eps)
 {
-
-  if ( BRep_Tool::Degenerated(S1) ||
-      BRep_Tool::Degenerated(S2) )
+  if ( BRep_Tool::Degenerated(S1) || BRep_Tool::Degenerated(S2) )
     return;
+
   Standard_Integer iE;
-//   TopoDS_Edge E, Eover;
   for (iE = 0; iE < 2; iE++)
-    {
-      TopoDS_Edge E, Eother;
-      if (iE == 0)
+  {
+    TopoDS_Edge E, Eother;
+    if (iE == 0)
        {
          E      = S1;
          Eother = S2;
        }
-      else
+    else
        {
          E      = S2;
          Eother = S1;
        }
-      Standard_Real aFirst, aLast, epsP = Precision::PConfusion(), Udeb, Ufin;
-      Handle(Geom_Curve) pCurv = BRep_Tool::Curve(E, aFirst, aLast);
-      
-      Standard_Real aFOther, aLOther;
-      Handle(Geom_Curve) pCurvOther = BRep_Tool::Curve(Eother, aFOther, aLOther);
-       
 
+    Standard_Real aFirst, aLast;
+    Handle(Geom_Curve) pCurv = BRep_Tool::Curve(E, aFirst, aLast);
 
-      GeomAbs_Shape s = pCurv->Continuity();
-      if (s == GeomAbs_C0)
+    Standard_Real aFOther, aLOther;
+    Handle(Geom_Curve) pCurvOther = BRep_Tool::Curve(Eother, aFOther, aLOther);
+
+    if (pCurv->Continuity() == GeomAbs_C0)
        {
-         GeomAdaptor_Curve aAdaptorCurve(pCurv, aFirst, aLast);
-         Standard_Integer nbIntervals = aAdaptorCurve.NbIntervals(GeomAbs_C1);
-         
-         TColStd_Array1OfReal arrInter(1,1+nbIntervals);
-         aAdaptorCurve.Intervals(arrInter, GeomAbs_C1);
-
-         GeomAdaptor_Curve aAdaptorCurveOther(pCurvOther, aFOther, aLOther);
-         Standard_Integer nbIntervalsOther = aAdaptorCurveOther.NbIntervals(GeomAbs_C1);
-         TColStd_Array1OfReal arrInterOther(1,1+nbIntervalsOther);
-         aAdaptorCurveOther.Intervals(arrInterOther, GeomAbs_C1);
-         
-         Standard_Real Dstmin, Dst;
-         gp_Pnt P1,Pt;
-         gp_Pnt2d PUV;
-         Standard_Boolean notavertex, inserer;
-         Standard_Integer i, ii;  
-         BRepClass_FaceClassifier classifier;
-         Standard_Real aParameter;
-         for (i=1; i<=arrInter.Length(); i++)
-           {   
-             gp_Pnt aPnt = aAdaptorCurve.Value(arrInter(i));
-             
-             TopoDS_Vertex V1 = BRepBuilderAPI_MakeVertex(aPnt);
-             
-             aParameter = arrInter(i);
-             BRepExtrema_ExtPC Ext(V1,Eother);
-             if ( (Ext.IsDone()) && (Ext.NbExt() > 0) )
-               { 
-                 Standard_Integer NbExtrema=Ext.NbExt();
-                 
-                 //       Recherche de la distance minimum dstmin
-                 Dstmin=sqrt (Ext.SquareDistance(1));
-                 for (ii=2;ii<=NbExtrema;ii++)
-                   {
-                     Dst=sqrt (Ext.SquareDistance(ii));
-                     if (Dst<Dstmin) 
-                       Dstmin=Dst;
-                   }
-
-                 if ((Dstmin < DstRef -Eps) || (fabs(Dstmin-DstRef)<Eps))
-                   for (ii=1;ii<=NbExtrema;ii++)
-                     { if (fabs(Dstmin-sqrt(Ext.SquareDistance(ii)))<Eps)
-                         {Pt=Ext.Point(ii);
-                          TRI_SOLUTION(SeqSol2,Pt,inserer);
-                          if (inserer) 
-                            {
-                              // on regarde si le parametre ne correspondont pas a un vertex
-                              Standard_Real t =Ext.Parameter(ii) ;
-                              notavertex=Standard_True;
-                              BRep_Tool::Range(Eother,Udeb,Ufin);
-                              if ((fabs(t-Udeb)<epsP)||(fabs(t-Ufin)<=epsP )) notavertex=Standard_False;
-                              if (notavertex)
-                                {
-                                  //  Modified by Sergey KHROMOV - Tue Mar  6 12:28:51 2001 Begin
-                                  if (mDstRef > Dstmin)
-                                    mDstRef=Dstmin;
-                                  //  Modified by Sergey KHROMOV - Tue Mar  6 12:28:54 2001 End
-                                  //myModif=Standard_True;
-                                  P1=BRep_Tool::Pnt(V1);
-                                  BRepExtrema_SolutionElem Sol1 (Dstmin,P1,BRepExtrema_IsOnEdge,E, aParameter);
-                                  BRepExtrema_SolutionElem Sol2 (Dstmin,Pt,BRepExtrema_IsOnEdge,Eother,t);
-                                   SeqSol1.Append(iE == 0 ? Sol1 : Sol2);
-                                   SeqSol2.Append(iE == 0 ? Sol2 : Sol1);
-                                }
-                            }
-                        }
-                     }
-                 
-                 
-               }
-             Standard_Real aParameterOther;
-             for (Standard_Integer i2 = 1; i2<=arrInterOther.Length(); i2++)
-               {
-                 gp_Pnt aPntOther = aAdaptorCurveOther.Value(arrInterOther(i2));
-                 Dst=aPnt.Distance(aPntOther);
-                 aParameterOther = arrInterOther(i2);
-                 if( (Dst< DstRef  - Eps ) || (fabs(Dst-DstRef)< Eps ))
-                   {           
-                     if (mDstRef > Dst)
-                       mDstRef=Dst;
-
-                     BRepExtrema_SolutionElem Sol1 (Dst,aPnt,BRepExtrema_IsOnEdge,E, aParameter);
-                     BRepExtrema_SolutionElem Sol2 (Dst,aPntOther, BRepExtrema_IsOnEdge,Eother, aParameterOther);
-                      SeqSol1.Append(iE == 0 ? Sol1 : Sol2);
-                     SeqSol2.Append(iE == 0 ? Sol2 : Sol1);
-                   }             
-
-               }
-           }
-         
-         
-       }
-    }
-}
+      const Standard_Real epsP = Precision::PConfusion();
 
-/*********************************************************************************/
+      GeomAdaptor_Curve aAdaptorCurve(pCurv, aFirst, aLast);
+      const Standard_Integer nbIntervals = aAdaptorCurve.NbIntervals(GeomAbs_C1);
 
-BRepExtrema_DistanceSS::BRepExtrema_DistanceSS(const TopoDS_Shape& S1, 
-                                              const TopoDS_Shape& S2, 
-                                              const Bnd_Box& B1, 
-                                              const Bnd_Box& B2, 
-                                              const Standard_Real DstRef)
+      TColStd_Array1OfReal arrInter(1,1+nbIntervals);
+      aAdaptorCurve.Intervals(arrInter, GeomAbs_C1);
 
-{
-  myEps = Precision::Confusion();
-  Perform(S1, S2, B1, B2, DstRef);
-}
+      GeomAdaptor_Curve aAdaptorCurveOther(pCurvOther, aFOther, aLOther);
+      const Standard_Integer nbIntervalsOther = aAdaptorCurveOther.NbIntervals(GeomAbs_C1);
+      TColStd_Array1OfReal arrInterOther(1,1+nbIntervalsOther);
+      aAdaptorCurveOther.Intervals(arrInterOther, GeomAbs_C1);
 
-/*********************************************************************************/
+      Standard_Real Udeb,Ufin;
+      BRep_Tool::Range(Eother,Udeb,Ufin);
 
-BRepExtrema_DistanceSS::BRepExtrema_DistanceSS(const TopoDS_Shape& S1, 
-                                              const TopoDS_Shape& S2, 
-                                              const Bnd_Box& B1, 
-                                              const Bnd_Box& B2, 
-                                              const Standard_Real DstRef,
-                                              const Standard_Real theDeflection)
+      gp_Pnt P1,Pt;
+      Standard_Integer i, ii;  
+      BRepClass_FaceClassifier classifier;
+      for (i = 1; i <= arrInter.Length(); i++)
+      {
+        const Standard_Real aParameter = arrInter(i);
+        const gp_Pnt aPnt = aAdaptorCurve.Value(aParameter);
+        const TopoDS_Vertex V1 = BRepBuilderAPI_MakeVertex(aPnt);
 
-{
-  myEps = theDeflection;
-  Perform(S1, S2, B1, B2, DstRef);
+        BRepExtrema_ExtPC Ext(V1,Eother);
+        const Standard_Integer NbExtrema = Ext.IsDone()? Ext.NbExt() : 0;
+        if ( NbExtrema > 0 )
+               { 
+          // Search minimum distance dstmin
+          Standard_Real Dstmin = Ext.SquareDistance(1);
+          for (ii = 2; ii <= NbExtrema; ii++)
+          {
+            const Standard_Real sDst = Ext.SquareDistance(ii);
+            if (sDst<Dstmin)
+              Dstmin=sDst;
+          }
+          Dstmin = sqrt(Dstmin);
+
+          if ((Dstmin < DstRef - Eps) || (fabs(Dstmin-DstRef) < Eps))
+            for (ii = 1; ii <= NbExtrema; ii++)
+            {
+              if (fabs(Dstmin-sqrt(Ext.SquareDistance(ii)))<Eps)
+              {
+                Pt=Ext.Point(ii);
+                if (TRI_SOLUTION(SeqSol2,Pt))
+                {
+                  // Check if the parameter does not correspond to a vertex
+                  const Standard_Real t = Ext.Parameter(ii);
+                  if ((fabs(t-Udeb)>=epsP)&&(fabs(t-Ufin)>epsP))
+                  {
+                    if (mDstRef > Dstmin)
+                      mDstRef=Dstmin;
+                    const BRepExtrema_SolutionElem Sol1(Dstmin,aPnt,BRepExtrema_IsOnEdge,E,aParameter);
+                    const BRepExtrema_SolutionElem Sol2(Dstmin,Pt,BRepExtrema_IsOnEdge,Eother,t);
+                    SeqSol1.Append(iE == 0 ? Sol1 : Sol2);
+                    SeqSol2.Append(iE == 0 ? Sol2 : Sol1);
+                  }
+                }
+              }
+            }
+        }
+        for (Standard_Integer i2 = 1; i2<=arrInterOther.Length(); i2++)
+        {
+          const Standard_Real aParameterOther = arrInterOther(i2);
+          const gp_Pnt aPntOther = aAdaptorCurveOther.Value(aParameterOther);
+          const Standard_Real Dst = aPnt.Distance(aPntOther);
+          if ((Dst < DstRef - Eps) || (fabs(Dst-DstRef) < Eps))
+          {            
+            if (mDstRef > Dst)
+              mDstRef=Dst;
+            const BRepExtrema_SolutionElem Sol1(Dst,aPnt,BRepExtrema_IsOnEdge,E,aParameter);
+            const BRepExtrema_SolutionElem Sol2(Dst,aPntOther,BRepExtrema_IsOnEdge,Eother,aParameterOther);
+            SeqSol1.Append(iE == 0 ? Sol1 : Sol2);
+            SeqSol2.Append(iE == 0 ? Sol2 : Sol1);
+          }              
+        }
+      }
+    }
+  }
 }
 
 /*********************************************************************************/
 
-void BRepExtrema_DistanceSS::Perform(const TopoDS_Shape& S1, 
-                                    const TopoDS_Shape& S2, 
-                                    const Bnd_Box& B1, 
-                                    const Bnd_Box& B2, 
-                                    const Standard_Real DstRef)
+void BRepExtrema_DistanceSS::Perform(const TopoDS_Shape& S1, const TopoDS_Shape& S2,
+                                     const Bnd_Box& B1, const Bnd_Box& B2)
 {
-TopAbs_ShapeEnum       Type1, Type2;
-  Type1 = S1.ShapeType();     
-  Type2 = S2.ShapeType();
-//  Modified by Sergey KHROMOV - Tue Mar  6 12:55:05 2001 Begin
-  myDstRef = DstRef;
-//  Modified by Sergey KHROMOV - Tue Mar  6 12:55:05 2001 End
-  TopoDS_Face aTrimFace;
-  TopoDS_Edge aTrimEdge;
-  Standard_Boolean bIsInfinit;
-  switch ( Type1)
-   { case TopAbs_VERTEX :
-                 switch (Type2)
-                  { case TopAbs_VERTEX : { TopoDS_Vertex V1 = TopoDS::Vertex(S1);
-                                           TopoDS_Vertex V2 = TopoDS::Vertex(S2);
-                                           Perform  ( V1 , V2, B1, B2,DstRef );}
-                                            break; 
-                    case TopAbs_EDGE   : { TopoDS_Vertex V1 = TopoDS::Vertex(S1);
-                                           TopoDS_Edge V2 = TopoDS::Edge(S2);
-                                            Perform  ( V1 , V2,  B1, B2,DstRef );}
-                                            break; 
-                    case TopAbs_FACE   : { TopoDS_Vertex V1 = TopoDS::Vertex(S1);
-                                           TopoDS_Face V2 = TopoDS::Face(S2);
-                                           Perform ( V1 , V2, B1, B2,DstRef );}
-                                            break; 
-                    default :{}           
-                    }break;
-
-      case TopAbs_EDGE :
-                  switch (Type2)
-                   { case TopAbs_VERTEX : { TopoDS_Edge V1 = TopoDS::Edge(S1);
-                                            TopoDS_Vertex V2 = TopoDS::Vertex(S2);
-                                            Perform ( V1 , V2, B1, B2,DstRef );} 
-                                             break;
-                     case TopAbs_EDGE   : { TopoDS_Edge V1 = TopoDS::Edge(S1);
-                                            TopoDS_Edge V2 = TopoDS::Edge(S2);
-                                            Standard_Boolean bIsTrim1 = Standard_False;
-                                            Standard_Boolean bIsTrim2 = Standard_False;
-                                            TRIM_INFINIT_EDGE(V1, V2, aTrimEdge, bIsTrim1, bIsTrim2);
-                                            if (bIsTrim1)
-                                              V1 = aTrimEdge;
-                                            if (bIsTrim2)
-                                              V2 = aTrimEdge;
-                                            Perform   ( V1 , V2,  B1, B2,DstRef );}
-                                             break;
-                     case TopAbs_FACE   : { TopoDS_Edge V1 = TopoDS::Edge(S1);
-                                            TopoDS_Face V2 = TopoDS::Face(S2);                                     
-                                            TRIM_INFINIT_FACE(V1, V2, aTrimFace, bIsInfinit);
-                                            if (bIsInfinit)
-                                              V2 = aTrimFace;
-                                             Perform ( V1 , V2, B1, B2,DstRef  );}
-                                              break;
-                     default :{}    }break;
-
-      case TopAbs_FACE :
-                   switch (Type2)
-                     { case TopAbs_VERTEX : { TopoDS_Face V1 = TopoDS::Face(S1);
-                                              TopoDS_Vertex V2 = TopoDS::Vertex(S2);
-                                              Perform ( V1 , V2,  B1, B2,DstRef);}
-                                               break;
-                       case TopAbs_EDGE   : { TopoDS_Face V1 = TopoDS::Face(S1);
-                                              TopoDS_Edge V2 = TopoDS::Edge(S2);
-                                              TRIM_INFINIT_FACE(V1, V2, aTrimFace, bIsInfinit);
-                                              if (bIsInfinit)
-                                                V1 = aTrimFace;
-                                              Perform ( V1 , V2,  B1, B2,DstRef );}
-                                                break;
-                       case TopAbs_FACE   : { TopoDS_Face V1 = TopoDS::Face(S1);
-                                              TopoDS_Face V2 = TopoDS::Face(S2);
-                                               Perform( V1 , V2,   B1, B2,DstRef);}
-                                               break;
-                       default :{}
-                       }break;
-     default :{}
- }
-}
-
-/*********************************************************************************/
+  SeqSolShape1.Clear();
+  SeqSolShape2.Clear();
+  myModif=Standard_False;
 
-void BRepExtrema_DistanceSS::Perform(const TopoDS_Vertex& S1, const TopoDS_Vertex& S2, 
-                                     const Bnd_Box& ,
-//                                      const Bnd_Box& B2, 
-                                      const Bnd_Box& , 
-                                     const Standard_Real DstRef)
-{     
-   gp_Pnt P1,P2;
-   Standard_Real Dst;
-   P1= BRep_Tool::Pnt(S1);
-   P2= BRep_Tool::Pnt(S2); 
-   Dst=P1.Distance(P2);  
-   SeqSolShape1.Clear();
-   SeqSolShape2.Clear();
-   myModif=Standard_False;
-   
-   if( (Dst< DstRef  -myEps ) || (fabs(Dst-DstRef)< myEps ))      
-   { 
-//  Modified by Sergey KHROMOV - Tue Mar  6 12:28:51 2001 Begin
-     if (myDstRef > Dst)
-       myDstRef=Dst;
-//  Modified by Sergey KHROMOV - Tue Mar  6 12:28:54 2001 End
-     myModif=Standard_True;
-     BRepExtrema_SolutionElem Sol1 (Dst,P1,BRepExtrema_IsVertex,S1);
-     BRepExtrema_SolutionElem Sol2 (Dst,P2, BRepExtrema_IsVertex,S2);
-     SeqSolShape1.Append(Sol1);
-     SeqSolShape2.Append(Sol2);
-   }
-}
+  switch (S1.ShapeType())
+  {
+    case TopAbs_VERTEX :
+    {
+      TopoDS_Vertex V1 = TopoDS::Vertex(S1);
+      switch (S2.ShapeType())
+      {
+        case TopAbs_VERTEX :
+        {
+          TopoDS_Vertex V2 = TopoDS::Vertex(S2);
+          Perform( V1, V2 );
+          break;
+        }
+        case TopAbs_EDGE :
+        {
+          TopoDS_Edge E2 = TopoDS::Edge(S2);
+          Perform( V1, E2, B1, B2 );
+          break;
+        }
+        case TopAbs_FACE :
+        {
+          TopoDS_Face F2 = TopoDS::Face(S2);
+          Perform( V1, F2, B1, B2 );
+          break;
+        }
+      }
+      break;
+    }
 
-/*********************************************************************************/
+    case TopAbs_EDGE :
+    {
+      TopoDS_Edge E1 = TopoDS::Edge(S1);
+      switch (S2.ShapeType())
+      {
+        case TopAbs_VERTEX :
+        {
+          TopoDS_Vertex V2 = TopoDS::Vertex(S2);
+          Perform( E1, V2, B1, B2 );
+          break;
+        }
+        case TopAbs_EDGE :
+        {
+          TopoDS_Edge E2 = TopoDS::Edge(S2);
+          TopoDS_Edge aTrimEdge;
+          Standard_Boolean bIsTrim1 = Standard_False;
+          Standard_Boolean bIsTrim2 = Standard_False;
+          TRIM_INFINIT_EDGE( E1, E2, aTrimEdge, bIsTrim1, bIsTrim2 );
+          if (bIsTrim1)
+            E1 = aTrimEdge;
+          if (bIsTrim2)
+            E2 = aTrimEdge;
+          Perform( E1, E2, B1, B2 );
+          break;
+        }
+        case TopAbs_FACE :
+        {
+          TopoDS_Face F2 = TopoDS::Face(S2);
+          TopoDS_Face aTrimFace;
+          Standard_Boolean bIsInfinit;
+          TRIM_INFINIT_FACE( E1, F2, aTrimFace, bIsInfinit );
+          if (bIsInfinit)
+            F2 = aTrimFace;
+          Perform( E1, F2, B1, B2 );
+          break;
+        }
+      }
+      break;
+    }
 
-void BRepExtrema_DistanceSS::Perform(const TopoDS_Vertex& S1, const TopoDS_Edge& S2, 
-                                     const Bnd_Box& B1, const Bnd_Box& B2, 
-                                     const Standard_Real DstRef)
-{ 
-   Standard_Real Dst,Dstmin,epsP,Udeb,Ufin ; 
-   gp_Pnt Pt,P1;
-   Standard_Boolean inserer,notavertex;
-   Standard_Integer i;  
-   
-   epsP=Precision::PConfusion();
-   SeqSolShape1.Clear();
-   SeqSolShape2.Clear();
-   myModif=Standard_False;
-  
-   if (!BRep_Tool::Degenerated (S2)) {
-   Dst=B1.Distance(B2);
-   if ( (Dst< DstRef  -myEps ) || (fabs(Dst-DstRef)< myEps ))     
-   { 
-     BRepExtrema_ExtPC Ext(S1,S2); 
-     if ( (Ext.IsDone()) && (Ext.NbExt() > 0) )
-       { Standard_Integer NbExtrema=Ext.NbExt();
-//       Recherche de la distance minimum dstmin
-         Dstmin=sqrt(Ext.SquareDistance(1));
-         for (i=2;i<=NbExtrema;i++)
-          {Dst=sqrt(Ext.SquareDistance(i));
-            if (Dst<Dstmin) 
-               Dstmin=Dst;
-           }
-         if ((Dstmin < DstRef -myEps) || (fabs(Dstmin-DstRef)<myEps))
-         for (i=1;i<=NbExtrema;i++)
-          { if (fabs(Dstmin-sqrt(Ext.SquareDistance(i)))<myEps)
-                    {Pt=Ext.Point(i);
-                      TRI_SOLUTION(SeqSolShape2,Pt,inserer);
-                      if (inserer) 
-                        {
-                          // on regarde si le parametre ne correspondont pas a un vertex
-                          Standard_Real t =Ext.Parameter(i) ;
-                          notavertex=Standard_True;
-                          BRep_Tool::Range(S2,Udeb,Ufin);
-                          if ((fabs(t-Udeb)<epsP)||(fabs(t-Ufin)<=epsP )) notavertex=Standard_False;
-                          if (notavertex)
-                          {
-//  Modified by Sergey KHROMOV - Tue Mar  6 12:28:51 2001 Begin
-                          if (myDstRef > Dstmin)
-                            myDstRef=Dstmin;
-//  Modified by Sergey KHROMOV - Tue Mar  6 12:28:54 2001 End
-                           myModif=Standard_True;
-                           P1=BRep_Tool::Pnt(S1);
-                           BRepExtrema_SolutionElem Sol1 (Dstmin,P1,BRepExtrema_IsVertex,S1);
-                           BRepExtrema_SolutionElem Sol2 (Dstmin,Pt,BRepExtrema_IsOnEdge,S2,t);
-                           SeqSolShape1.Append(Sol1);
-                           SeqSolShape2.Append(Sol2);            
-                          }
-                        }
-                    }
-          }
-   }
-   }
-}
+    case TopAbs_FACE :
+    {
+      TopoDS_Face F1 = TopoDS::Face(S1);
+      switch (S2.ShapeType())
+      {
+        case TopAbs_VERTEX :
+        {
+          TopoDS_Vertex V2 = TopoDS::Vertex(S2);
+          Perform( F1, V2, B1, B2 );
+          break;
+        }
+        case TopAbs_EDGE :
+        {
+          TopoDS_Edge E2 = TopoDS::Edge(S2);
+          TopoDS_Face aTrimFace;
+          Standard_Boolean bIsInfinit;
+          TRIM_INFINIT_FACE( F1, E2, aTrimFace, bIsInfinit );
+          if (bIsInfinit)
+            F1 = aTrimFace;
+          Perform( F1, E2, B1, B2 );
+          break;
+        }
+        case TopAbs_FACE :
+        {
+          TopoDS_Face F2 = TopoDS::Face(S2);
+          Perform( F1, F2, B1, B2 );
+          break;
+        }
+      }
+      break;
+    }
+  }
 }
 
 /*********************************************************************************/
 
-void BRepExtrema_DistanceSS::Perform(const TopoDS_Vertex& S1, const TopoDS_Face& S2, 
-                                     const Bnd_Box& B1, const Bnd_Box& B2,
-                                     const Standard_Real DstRef)
-{
-   Standard_Real Dst,Dstmin,epsP,U,V ; 
-   gp_Pnt P1,Pt;
-   gp_Pnt2d PUV;
-   Standard_Boolean inserer,notavertex;
-   Standard_Integer i;  
-   BRepClass_FaceClassifier classifier; 
-   
-   epsP=Precision::PConfusion();
-   SeqSolShape1.Clear();
-   SeqSolShape2.Clear();
-   myModif=Standard_False;
-
-   Dst=B1.Distance(B2);
-   if ( (Dst< DstRef  -myEps ) || (fabs(Dst-DstRef)< myEps ))     
-   { 
-     BRepExtrema_ExtPF Ext(S1,S2);
-     if ( (Ext.IsDone()) && (Ext.NbExt() > 0) )
-       { Standard_Integer NbExtrema=Ext.NbExt();
-//       Recherche de la distance minimum dstmin
-         Dstmin=sqrt(Ext.SquareDistance(1));
-         for (i=2;i<=NbExtrema;i++)
-          {Dst=sqrt (Ext.SquareDistance(i));
-            if (Dst<Dstmin) 
-               Dstmin=Dst;
-           }
-         if ((Dstmin < DstRef -myEps) || (fabs(Dstmin-DstRef)<myEps))
-         for (i=1;i<=NbExtrema;i++)
-          { if (fabs(Dstmin-sqrt(Ext.SquareDistance(i)))<myEps)
-                    { Pt=Ext.Point(i);
-                      TRI_SOLUTION(SeqSolShape2,Pt,inserer);
-                      if (inserer) 
-                        {
-                          // on regarde si le parametre ne correspondont pas a un vertex
-                          Ext.Parameter(i,U,V);
-  
-                          PUV.SetCoord(U,V);
-                         Standard_Real tol=BRep_Tool::Tolerance(S2);
-                          classifier.Perform(S2,PUV,tol);
-                          notavertex=(classifier.State()==TopAbs_IN); 
-                          if (notavertex)
-                          {
-//  Modified by Sergey KHROMOV - Tue Mar  6 12:28:51 2001 Begin
-                          if (myDstRef > Dstmin)
-                            myDstRef=Dstmin;
-//  Modified by Sergey KHROMOV - Tue Mar  6 12:28:54 2001 End
-                           myModif=Standard_True;
-                           P1=BRep_Tool::Pnt(S1);
-                           BRepExtrema_SolutionElem Sol1 (Dstmin,P1,BRepExtrema_IsVertex,S1);
-                           BRepExtrema_SolutionElem Sol2 (Dstmin,Pt,BRepExtrema_IsInFace,S2,U,V);
-                           SeqSolShape1.Append(Sol1);
-                           SeqSolShape2.Append(Sol2);            
-                          }
-                        }
-                    }
-          }
-   }
-   }
-}
-
-/*********************************************************************************/
+void BRepExtrema_DistanceSS::Perform(const TopoDS_Vertex& S1, const TopoDS_Vertex& S2)
+{     
+  const gp_Pnt P1 = BRep_Tool::Pnt(S1);
+  const gp_Pnt P2 = BRep_Tool::Pnt(S2);
 
-void BRepExtrema_DistanceSS::Perform(const TopoDS_Edge& S1, const TopoDS_Vertex& S2, 
-                                     const Bnd_Box& B1, const Bnd_Box& B2, 
-                                     const Standard_Real DstRef)
-
-{Standard_Real Dst,Dstmin,epsP,Udeb,Ufin ; 
-   gp_Pnt Pt,P1;
-   Standard_Boolean inserer,notavertex;
-   Standard_Integer i;  
-   
-   epsP=Precision::PConfusion();
-   SeqSolShape1.Clear();
-   SeqSolShape2.Clear();
-   myModif=Standard_False;
-   
-   if (!BRep_Tool::Degenerated(S1))  {
-   Dst=B1.Distance(B2);
-   if ( (Dst< DstRef  -myEps ) || (fabs(Dst-DstRef)< myEps ))     
-   { 
-     BRepExtrema_ExtPC Ext(S2,S1);
-     if ( (Ext.IsDone()) && (Ext.NbExt() > 0) )
-       { Standard_Integer NbExtrema=Ext.NbExt();
-//       Recherche de la distance minimum dstmin
-         Dstmin=sqrt(Ext.SquareDistance(1));
-         for (i=2;i<=NbExtrema;i++)
-
-          {Dst=sqrt(Ext.SquareDistance(i));
-            if (Dst<Dstmin) 
-               Dstmin=Dst;
-           }
-         if ((Dstmin < DstRef -myEps) || (fabs(Dstmin-DstRef)<myEps))
-         for (i=1;i<=NbExtrema;i++)
-          { if (fabs(Dstmin-sqrt (Ext.SquareDistance(i)))<myEps)
-                    {Pt=Ext.Point(i);
-                      TRI_SOLUTION(SeqSolShape1,Pt,inserer); 
-                      if (inserer) 
-                        {
-                          // on regarde si le parametre ne correspondont pas a un vertex
-                          Standard_Real t =Ext.Parameter(i) ;
-                          notavertex=Standard_True;
-                          BRep_Tool::Range(S1,Udeb,Ufin);
-                          if ((fabs(t-Udeb)<epsP)||(fabs(t-Ufin)<=epsP )) notavertex=Standard_False;
-                          if (notavertex)
-                          {
-//  Modified by Sergey KHROMOV - Tue Mar  6 12:28:51 2001 Begin
-                          if (myDstRef > Dstmin)
-                            myDstRef=Dstmin;
-//  Modified by Sergey KHROMOV - Tue Mar  6 12:28:54 2001 End
-                           myModif=Standard_True;
-                           P1=BRep_Tool::Pnt(S2);
-                           BRepExtrema_SolutionElem Sol1 (Dstmin,Pt,BRepExtrema_IsOnEdge,S1,t);
-                           BRepExtrema_SolutionElem Sol2 (Dstmin,P1,BRepExtrema_IsVertex,S2);
-                           SeqSolShape1.Append(Sol1);
-                           SeqSolShape2.Append(Sol2);
-                          }
-                        }
-                    }
-          }
-   }
-   }
-}
+  const Standard_Real Dst = P1.Distance(P2);
+  if ((Dst < myDstRef - myEps) || (fabs(Dst-myDstRef) < myEps))
+  { 
+    if (myDstRef > Dst)
+      myDstRef=Dst;
+    myModif=Standard_True;
+    const BRepExtrema_SolutionElem Sol1(Dst,P1,BRepExtrema_IsVertex,S1);
+    const BRepExtrema_SolutionElem Sol2(Dst,P2,BRepExtrema_IsVertex,S2);
+    SeqSolShape1.Append(Sol1);
+    SeqSolShape2.Append(Sol2);
+  }
 }
 
 /*********************************************************************************/
 
-void BRepExtrema_DistanceSS::Perform(const TopoDS_Edge& S1, const TopoDS_Edge& S2, 
-                                     const Bnd_Box& B1, const Bnd_Box& B2, 
-                                     const Standard_Real DstRef)
-
-{
-   Standard_Real Dst,Dstmin,epsP,Udeb,Ufin; 
-   gp_Pnt Pt1,Pt2;
-   Standard_Boolean insere1, insere2, notavertex;
-   Standard_Integer i;   
-   
-   epsP=Precision::PConfusion();
-   SeqSolShape1.Clear();
-   SeqSolShape2.Clear();
-   myModif=Standard_False;
-   
-   if (!BRep_Tool::Degenerated(S1)&& !BRep_Tool::Degenerated(S2))
-
- {
-
-   Dst=B1.Distance(B2);
-   if ( (Dst< DstRef  -myEps ) || (fabs(Dst-DstRef)< myEps ))     
-   { 
-     BRepExtrema_ExtCC Ext(S1,S2);
-     if ( (Ext.IsDone()) && (Ext.NbExt() > 0) && (!Ext.IsParallel())) 
-       { Standard_Integer NbExtrema=Ext.NbExt();
-//       Recherche de la distance minimum dstmin
-         Dstmin=sqrt (Ext.SquareDistance(1));
-         for (i=2;i<=NbExtrema;i++)
-          {Dst=sqrt (Ext.SquareDistance(i));
-            if (Dst<Dstmin) 
-               Dstmin=Dst;
-         }
-        if ((Dstmin < DstRef -myEps) || (fabs(Dstmin-DstRef)<myEps))   
-         for (i=1;i<=NbExtrema;i++)
-          { if (fabs(Dstmin-sqrt (Ext.SquareDistance(i)))<myEps )
-                    {Pt1=Ext.PointOnE1(i);
-                      Pt2=Ext.PointOnE2(i);
-                      TRI_SOLUTION(SeqSolShape1,Pt1,insere1);
-                      TRI_SOLUTION(SeqSolShape2,Pt2,insere2);
-                      if (insere1 ||insere2 ) 
-                        {
-                          // on regarde si le parametre ne correspondont pas a un vertex
-                          Standard_Real t1 =Ext.ParameterOnE1(i) ;
-                          Standard_Real t2 =Ext.ParameterOnE2(i) ;
-                          
-                          notavertex=Standard_True;
-                          BRep_Tool::Range(S1,Udeb,Ufin);
-                          if ((fabs(t1-Udeb)<epsP)||(fabs(t1-Ufin)<=epsP )) notavertex=Standard_False;
-                           
-                          BRep_Tool::Range(S2,Udeb,Ufin);
-                          if ((fabs(t2-Udeb)<epsP)||(fabs(t2-Ufin)<=epsP )) notavertex=Standard_False;
-  
-                          if (notavertex)
-                          {
-//  Modified by Sergey KHROMOV - Tue Mar  6 12:28:51 2001 Begin
-                          if (myDstRef > Dstmin)
-                            myDstRef=Dstmin;
-//  Modified by Sergey KHROMOV - Tue Mar  6 12:28:54 2001 End
-                           myModif=Standard_True;
-                           BRepExtrema_SolutionElem Sol1 (Dstmin,Pt1,BRepExtrema_IsOnEdge,S1,t1);
-                           BRepExtrema_SolutionElem Sol2 (Dstmin,Pt2,BRepExtrema_IsOnEdge,S2,t2);
-                           SeqSolShape1.Append(Sol1);
-                           SeqSolShape2.Append(Sol2);
-                          }
-                        }
-                
-    }
-          }
-   }
-
-     BRepExtrema_SeqOfSolution SeqSolution1;
-     BRepExtrema_SeqOfSolution SeqSolution2;
-//      Standard_Integer i;
-
-     PERFORM_C0(S1, S2, SeqSolution1, SeqSolution2, DstRef, myDstRef, myEps);
-     
-     BRepExtrema_SeqOfSolution seqSol1;
-     BRepExtrema_SeqOfSolution seqSol2;
-       
-     if (SeqSolution1.Length() > 0 && SeqSolution2.Length() > 0) {
-       MIN_SOLUTION(SeqSolution1, SeqSolution2, myDstRef, myEps, seqSol1, seqSol2);
-     }
-     
-     if (!seqSol1.IsEmpty() && !seqSol2.IsEmpty())
-       {
-        SeqSolShape1.Append(seqSol1);
-        SeqSolShape2.Append(seqSol2);  
-        myModif = Standard_True;
-       }
-     
-   }
- }
- }
-
-/*********************************************************************************/
+void BRepExtrema_DistanceSS::Perform(const TopoDS_Vertex& S1, const TopoDS_Edge& S2,
+                                     const Bnd_Box& B1, const Bnd_Box& B2)
+{ 
+  if (BRep_Tool::Degenerated(S2))
+    return;
 
-void BRepExtrema_DistanceSS::Perform(const TopoDS_Edge& S1, const TopoDS_Face& S2, 
-                                     const Bnd_Box& B1, const Bnd_Box& B2, 
-                                     const Standard_Real DstRef)
-{
-  Standard_Real Dst,Dstmin,epsP,Udeb,Ufin,U,V ; 
-  gp_Pnt Pt1,Pt2;
-  gp_Pnt2d PUV;
-  Standard_Boolean insere1 ,insere2, notavertex;
-  BRepClass_FaceClassifier classifier;
-  Standard_Integer i;  
-  
-  epsP=Precision::PConfusion();
-  SeqSolShape1.Clear();
-  SeqSolShape2.Clear();
-  myModif=Standard_False;
-  
-  if (!BRep_Tool::Degenerated(S1)) {
-    
-    Dst=B1.Distance(B2);
-    if ( (Dst< DstRef  -myEps ) || (fabs(Dst-DstRef)< myEps ))     
+  const Standard_Real Dst=B1.Distance(B2);
+  if ((Dst < myDstRef - myEps) || (fabs(Dst-myDstRef) < myEps))
+  {
+    BRepExtrema_ExtPC Ext(S1,S2);
+    const Standard_Integer NbExtrema = Ext.IsDone()? Ext.NbExt() : 0;
+    if ( NbExtrema > 0 )
+    {
+      // Search minimum distance Dstmin
+      Standard_Integer i;
+      Standard_Real Dstmin = Ext.SquareDistance(1);
+      for (i = 2; i <= NbExtrema; i++)
       {
-       BRepExtrema_ExtCF Ext(S1,S2);
-       if ( (Ext.IsDone()) && ((Ext.NbExt() > 0) && (!Ext.IsParallel()) ))
-         { Standard_Integer NbExtrema=Ext.NbExt();
-           //       Recherche de la distance minimum dstmin
-           Dstmin=sqrt (Ext.SquareDistance(1));
-           for (i=2;i<=NbExtrema;i++)
-             {Dst=sqrt (Ext.SquareDistance(i));
-              if (Dst<Dstmin) 
-                Dstmin=Dst;
-            }
-           if ((Dstmin < DstRef -myEps) || (fabs(Dstmin-DstRef)<myEps))
-             for (i=1;i<=NbExtrema;i++)
-               { if (fabs(Dstmin-sqrt (Ext.SquareDistance(i)))<myEps)
-                   {Pt1=Ext.PointOnEdge(i);
-                    Pt2=Ext.PointOnFace(i);
-                    TRI_SOLUTION (SeqSolShape1,Pt1,insere1);
-                    TRI_SOLUTION (SeqSolShape2,Pt2,insere2); 
-                    if (insere1||insere2)
-                      {
-                        // on regarde si le parametre ne correspondont pas a un vertex
-                        Standard_Real t1 =Ext.ParameterOnEdge(i) ;
-                        
-                        notavertex=Standard_True;
-                        BRep_Tool::Range(S1,Udeb,Ufin);
-                        if ((fabs(t1-Udeb)<epsP)||(fabs(t1-Ufin)<=epsP )) notavertex=Standard_False;
-                        
-                        Ext.ParameterOnFace(i,U,V);
-                        PUV.SetCoord(U,V);
-                        Standard_Real tol=BRep_Tool::Tolerance(S2);
-                        classifier.Perform(S2,PUV,tol);
-                        if ( classifier.State()!=TopAbs_IN)  notavertex=Standard_False;
-                        
-                        if (notavertex)
-                          {
-//  Modified by Sergey KHROMOV - Tue Mar  6 12:28:51 2001 Begin
-                            if (myDstRef > Dstmin)
-                              myDstRef=Dstmin;
-//  Modified by Sergey KHROMOV - Tue Mar  6 12:28:54 2001 End
-                            myModif=Standard_True;
-                            BRepExtrema_SolutionElem Sol1 (Dstmin,Pt1,BRepExtrema_IsOnEdge,S1,t1);
-                            BRepExtrema_SolutionElem Sol2 (Dstmin,Pt2,BRepExtrema_IsInFace,S2,U,V);
-                            SeqSolShape1.Append(Sol1);
-                            SeqSolShape2.Append(Sol2);           
-                          }
-                      }
-                  }
-               }
+        const Standard_Real sDst = Ext.SquareDistance(i);
+        if (sDst<Dstmin)
+          Dstmin=sDst;
          }
-       Standard_Real aFirst, aLast;
-       Handle(Geom_Curve) pCurv = BRep_Tool::Curve(S1, aFirst, aLast);
-       GeomAbs_Shape s = pCurv->Continuity();
-       if (s == GeomAbs_C0)
-         {
-           BRepExtrema_SeqOfSolution SeqSolution1;
-           BRepExtrema_SeqOfSolution SeqSolution2;
+      Dstmin = sqrt(Dstmin);
+      if ((Dstmin < myDstRef - myEps) || (fabs(Dstmin-myDstRef) < myEps))
+      {
+        Standard_Real Udeb,Ufin;
+        BRep_Tool::Range(S2,Udeb,Ufin);
 
-           
-           GeomAdaptor_Curve aAdaptorCurve(pCurv, aFirst, aLast);
-           Standard_Integer nbIntervals = aAdaptorCurve.NbIntervals(GeomAbs_C1);
-           
-           TColStd_Array1OfReal arrInter(1,1+nbIntervals);
-           aAdaptorCurve.Intervals(arrInter, GeomAbs_C1);
-           
-//         Standard_Real U,V;
-           gp_Pnt P1,Pt;
-//         gp_Pnt2d PUV;
-//         Standard_Boolean notavertex;
-//         Standard_Integer i, ii;  
-           Standard_Integer ii;  
-//         BRepClass_FaceClassifier classifier;
-           Standard_Real aParameter;
-           for (i=1; i<=arrInter.Length(); i++)
-             { 
-               gp_Pnt aPnt = aAdaptorCurve.Value(arrInter(i));
-               
-               TopoDS_Vertex V1 = BRepBuilderAPI_MakeVertex(aPnt);
-
-               aParameter = arrInter(i);
-               
-               BRepExtrema_ExtPF ExtPF(V1,S2);
-               if ( (ExtPF.IsDone()) && (ExtPF.NbExt() > 0) )
-                 { 
-                   Standard_Integer NbExtrema=ExtPF.NbExt();
-                   //       Recherche de la distance minimum dstmin
-                   Dstmin=sqrt (ExtPF.SquareDistance(1));
-                   for (ii=2;ii<=NbExtrema;ii++)
-                     {Dst=sqrt(ExtPF.SquareDistance(ii));
-                      if (Dst<Dstmin) 
-                        Dstmin=Dst;
-                    }
-                   if ((Dstmin < DstRef -myEps) || (fabs(Dstmin-DstRef)<myEps))
-                     {
-                       
-                       for (ii=1;ii<=NbExtrema;ii++)
-                         { 
-                           if (fabs(Dstmin-sqrt (ExtPF.SquareDistance(ii)))<myEps)
-                             { 
-                               Pt=ExtPF.Point(ii);
-                               // on regarde si le parametre ne correspondont pas a un vertex
-                               ExtPF.Parameter(ii,U,V);
-                               // Standard_Real t1 =Ext.ParameterOnEdge(ii) ;
-                                                               
-                               PUV.SetCoord(U,V);
-                               Standard_Real tol=BRep_Tool::Tolerance(S2);
-                               classifier.Perform(S2,PUV,tol);
-                               notavertex=(classifier.State()==TopAbs_IN); 
-                               if (notavertex)
-                                 {
-                                   //  Modified by Sergey KHROMOV - Tue Mar  6 12:28:51 2001 Begin
-                                   if (myDstRef > Dstmin)
-                                     myDstRef=Dstmin;
-                                   //  Modified by Sergey KHROMOV - Tue Mar  6 12:28:54 2001 End
-                                   myModif=Standard_True;
-                                   P1=BRep_Tool::Pnt(V1);
-                                   BRepExtrema_SolutionElem Sol1 (Dstmin,P1,BRepExtrema_IsOnEdge,S1,aParameter);
-                                   BRepExtrema_SolutionElem Sol2 (Dstmin,Pt,BRepExtrema_IsInFace,S2,U,V);
-                                   SeqSolution1.Append(Sol1);
-                                   SeqSolution2.Append(Sol2);
-                                 }
-                             }
-                         }
-                     }
-                 }
-             }
-           BRepExtrema_SeqOfSolution seqSol1;
-           BRepExtrema_SeqOfSolution seqSol2;
-           Standard_Boolean bIsMini = Standard_False;
-           if (SeqSolution1.Length() > 0 && SeqSolution2.Length() > 0)
-             MIN_SOLUTION(SeqSolution1, SeqSolution2, myDstRef, myEps, seqSol1, seqSol2);
-           
-           if (!seqSol1.IsEmpty() && !seqSol2.IsEmpty())
-             {
-               SeqSolShape1.Append(seqSol1);
-               SeqSolShape2.Append(seqSol2);
-             }
-         }
+        gp_Pnt Pt,P1=BRep_Tool::Pnt(S1);
+        const Standard_Real epsP=Precision::PConfusion();
+
+        for (i = 1; i <= NbExtrema; i++)
+        {
+          if (fabs(Dstmin-sqrt(Ext.SquareDistance(i)))<myEps)
+          {
+            Pt=Ext.Point(i);
+            if (TRI_SOLUTION(SeqSolShape2,Pt))
+            {
+              // Check if the parameter does not correspond to a vertex
+              const Standard_Real t = Ext.Parameter(i);
+              if ( (fabs(t-Udeb)>=epsP) && (fabs(t-Ufin)>epsP) )
+              {
+                if (myDstRef > Dstmin)
+                  myDstRef=Dstmin;
+                myModif=Standard_True;
+                const BRepExtrema_SolutionElem Sol1(Dstmin,P1,BRepExtrema_IsVertex,S1);
+                const BRepExtrema_SolutionElem Sol2(Dstmin,Pt,BRepExtrema_IsOnEdge,S2,t);
+                SeqSolShape1.Append(Sol1);
+                SeqSolShape2.Append(Sol2);
+              }
+            }
+          }
+        }
       }
+    }
   }
 }
 
 /*********************************************************************************/
 
-void BRepExtrema_DistanceSS::Perform(const TopoDS_Face& S1, const TopoDS_Vertex& S2, 
-                                     const Bnd_Box& B1, const Bnd_Box& B2, 
-                                     const Standard_Real DstRef)
-
+void BRepExtrema_DistanceSS::Perform(const TopoDS_Vertex& S1, const TopoDS_Face& S2, 
+                                     const Bnd_Box& B1, const Bnd_Box& B2)
 {
-  const Standard_Real epsP=Precision::PConfusion();
-  SeqSolShape1.Clear();
-  SeqSolShape2.Clear();
-  myModif=Standard_False;
-
-  Standard_Real Dst=B1.Distance(B2);
-  if ((Dst < DstRef -myEps) || (fabs(Dst-DstRef)< myEps))
+  const Standard_Real Dst=B1.Distance(B2);
+  if ((Dst < myDstRef - myEps) || (fabs(Dst-myDstRef) < myEps))
   { 
-    BRepExtrema_ExtPF Ext(S2,S1);
-    if ( Ext.IsDone() && (Ext.NbExt() > 0) )
+    BRepExtrema_ExtPF Ext(S1,S2,myFlag,myAlgo);
+    const Standard_Integer NbExtrema = Ext.IsDone()? Ext.NbExt() : 0;
+    if ( NbExtrema > 0 )
     {
-      const Standard_Integer NbExtrema=Ext.NbExt();
-      // Search the minimal distance Dstmin
+      // Search minimum distance Dstmin
       Standard_Integer i;
       Standard_Real Dstmin = Ext.SquareDistance(1);
-      for (i=2;i<=NbExtrema;i++)
-         {
-        Dst = Ext.SquareDistance(i);
-        if (Dst<Dstmin)
-          Dstmin=Dst;
+      for (i = 2; i <= NbExtrema; i++)
+      {
+        const Standard_Real sDst = Ext.SquareDistance(i);
+        if (sDst<Dstmin) 
+          Dstmin=sDst;
       }
       Dstmin = sqrt(Dstmin);
-
-      if ((Dstmin < DstRef -myEps) || (fabs(Dstmin-DstRef)<myEps))
+      if ((Dstmin < myDstRef - myEps) || (fabs(Dstmin-myDstRef) < myEps))
       {
         Standard_Real U,V;
-        gp_Pnt P1,Pt;
-        gp_Pnt2d PUV;
-        Standard_Boolean inserer;
+        gp_Pnt Pt,P1=BRep_Tool::Pnt(S1);
         BRepClass_FaceClassifier classifier;
-
-        for (i=1;i<=NbExtrema;i++)
+        const Standard_Real tol = BRep_Tool::Tolerance(S2);
+        const Standard_Real epsP = Precision::PConfusion();
+        for (i = 1; i <= NbExtrema; i++)
         {
-          if (fabs(Dstmin-sqrt (Ext.SquareDistance(i)))<myEps)
-                 {
+          if (fabs(Dstmin-sqrt(Ext.SquareDistance(i)))<myEps)
+          {
             Pt=Ext.Point(i);
-            TRI_SOLUTION (SeqSolShape1,Pt,inserer);
-            if (inserer)
-                       {
-              // on regarde si le parametre ne correspondont pas a un vertex
+            if (TRI_SOLUTION(SeqSolShape2,Pt))
+            {
+              // Check if the parameter does not correspond to a vertex
               Ext.Parameter(i,U,V);
-
-              PUV.SetCoord(U,V);
-                     const Standard_Real tol=BRep_Tool::Tolerance(S1);
-              classifier.Perform(S1,PUV,tol);
+              const gp_Pnt2d PUV(U,V);
+              classifier.Perform(S2,PUV,tol);
               if (classifier.State()==TopAbs_IN)
               {
-//  Modified by Sergey KHROMOV - Tue Mar  6 12:28:51 2001 Begin
-                           if (myDstRef > Dstmin)
-                             myDstRef=Dstmin;
-//  Modified by Sergey KHROMOV - Tue Mar  6 12:28:54 2001 End
+                if (myDstRef > Dstmin)
+                  myDstRef=Dstmin;
                 myModif=Standard_True;
-                P1=BRep_Tool::Pnt(S2);
-                BRepExtrema_SolutionElem Sol1 (Dstmin,Pt,BRepExtrema_IsInFace,S1,U,V);
-                BRepExtrema_SolutionElem Sol2 (Dstmin,P1,BRepExtrema_IsVertex,S2);
+                const BRepExtrema_SolutionElem Sol1(Dstmin,P1,BRepExtrema_IsVertex,S1);
+                const BRepExtrema_SolutionElem Sol2(Dstmin,Pt,BRepExtrema_IsInFace,S2,U,V);
                 SeqSolShape1.Append(Sol1);
-                SeqSolShape2.Append(Sol2);
+                SeqSolShape2.Append(Sol2);               
               }
             }
           }
         }
-         }
+      }
     }
   }
 }
 
 /*********************************************************************************/
 
-void BRepExtrema_DistanceSS::Perform(const TopoDS_Face& S1, const TopoDS_Edge& S2, 
-                                     const Bnd_Box& B1, const Bnd_Box& B2, 
-                                     const Standard_Real DstRef)
-
+void BRepExtrema_DistanceSS::Perform(const TopoDS_Edge& S1, const TopoDS_Edge& S2,
+                                     const Bnd_Box& B1, const Bnd_Box& B2)
 {
-   Standard_Real Dst,Dstmin,epsP,Udeb,Ufin,U,V ; 
-   gp_Pnt Pt1,Pt2;
-   gp_Pnt2d PUV;
-   Standard_Boolean insere1,insere2,notavertex;
-   BRepClass_FaceClassifier classifier;
-   Standard_Integer i;  
-   
-   epsP=Precision::PConfusion();
-   SeqSolShape1.Clear();
-   SeqSolShape2.Clear();
-   myModif=Standard_False;
-   
-   if (!BRep_Tool::Degenerated(S2)) 
+  if (BRep_Tool::Degenerated(S1) || BRep_Tool::Degenerated(S2))
+    return;
+
+  const Standard_Real Dst=B1.Distance(B2);
+  if ((Dst < myDstRef - myEps) || (fabs(Dst-myDstRef) < myEps))
   {
-   Dst=B1.Distance(B2);
-   if ( (Dst< DstRef  -myEps ) || (fabs(Dst-DstRef)< myEps ))     
-   { 
-     BRepExtrema_ExtCF Ext(S2,S1);
-     if ( (Ext.IsDone()) && ((Ext.NbExt() > 0) && (!Ext.IsParallel())) )
-         { Standard_Integer NbExtrema=Ext.NbExt();
-//       Recherche de la distance minimum dstmin
-         Dstmin=sqrt (Ext.SquareDistance(1));
-         for (i=2;i<=NbExtrema;i++)
-          {Dst=sqrt (Ext.SquareDistance(i));
-            if (Dst<Dstmin) 
-               Dstmin=Dst;}
-         if ((Dstmin < DstRef -myEps) || (fabs(Dstmin-DstRef)<myEps))   
-         for (i=1;i<=NbExtrema;i++)
-          { if (fabs(Dstmin-sqrt (Ext.SquareDistance(i)))<myEps)
-                    {Pt1=Ext.PointOnFace(i);
-                      Pt2=Ext.PointOnEdge(i);
-                      TRI_SOLUTION (SeqSolShape1,Pt1,insere1);
-                      TRI_SOLUTION (SeqSolShape2,Pt2,insere2); 
-                      if (insere1||insere2)
-          
-                        {
-                          // on regarde si le parametre ne correspondont pas a un vertex
-                          Standard_Real t1 =Ext.ParameterOnEdge(i) ;
-                          
-                          notavertex=Standard_True;
-                          BRep_Tool::Range(S2,Udeb,Ufin);
-                          if ((fabs(t1-Udeb)<epsP)||(fabs(t1-Ufin)<=epsP )) notavertex=Standard_False;
-                    
-                          Ext.ParameterOnFace(i,U,V);
-                          PUV.SetCoord(U,V);
-                         Standard_Real tol=BRep_Tool::Tolerance(S1);
-                          classifier.Perform(S1,PUV,tol);
-                          if (classifier.State()!=TopAbs_IN) notavertex=Standard_False; 
-                
-                          if (notavertex)
-                          {
-//  Modified by Sergey KHROMOV - Tue Mar  6 12:28:51 2001 Begin
-                          if (myDstRef > Dstmin)
-                            myDstRef=Dstmin;
-//  Modified by Sergey KHROMOV - Tue Mar  6 12:28:54 2001 End
-                           myModif=Standard_True;
-                           BRepExtrema_SolutionElem Sol1 (Dstmin,Pt1,BRepExtrema_IsInFace,S1,U,V);
-                           BRepExtrema_SolutionElem Sol2 (Dstmin,Pt2,BRepExtrema_IsOnEdge,S2,t1);
-                           SeqSolShape1.Append(Sol1);
-                           SeqSolShape2.Append(Sol2);            
-                          }
-                        }
-                    }
-          }
-        }
-
-     Standard_Real aFirst, aLast;
-     Handle(Geom_Curve) pCurv = BRep_Tool::Curve(S2, aFirst, aLast);
-     GeomAbs_Shape s = pCurv->Continuity();
-     if (s == GeomAbs_C0)
-       {
-        BRepExtrema_SeqOfSolution SeqSolution1;
-        BRepExtrema_SeqOfSolution SeqSolution2;
-
-
-        GeomAdaptor_Curve aAdaptorCurve(pCurv, aFirst, aLast);
-        Standard_Integer nbIntervals = aAdaptorCurve.NbIntervals(GeomAbs_C1);
-        
-        TColStd_Array1OfReal arrInter(1,1+nbIntervals);
-        aAdaptorCurve.Intervals(arrInter, GeomAbs_C1);
-        
-//      Standard_Real U,V;
-        gp_Pnt P1,Pt;
-//      gp_Pnt2d PUV;
-//      Standard_Boolean notavertex;
-        Standard_Integer ii;  
-//      BRepClass_FaceClassifier classifier;
-        Standard_Real aParameter;
-        for (i=1; i<=arrInter.Length(); i++)
-          {    
-            gp_Pnt aPnt = aAdaptorCurve.Value(arrInter(i));
-            
-            TopoDS_Vertex V1 = BRepBuilderAPI_MakeVertex(aPnt);
-            
-            aParameter = arrInter(i);
-            
-            BRepExtrema_ExtPF ExtPF(V1,S1);
-            if ( (ExtPF.IsDone()) && (ExtPF.NbExt() > 0) )
-              { 
-                Standard_Integer NbExtrema=ExtPF.NbExt();
-                //       Recherche de la distance minimum dstmin
-                Dstmin=sqrt(ExtPF.SquareDistance(1));
-                for (ii=2;ii<=NbExtrema;ii++)
-                  {Dst=sqrt(ExtPF.SquareDistance(ii));
-                   if (Dst<Dstmin) 
-                     Dstmin=Dst;
-                 }
-                if ((Dstmin < DstRef -myEps) || (fabs(Dstmin-DstRef)<myEps))
-                  {
-                    
-                    for (ii=1;ii<=NbExtrema;ii++)
-                      { 
-                        if (fabs(Dstmin-sqrt(ExtPF.SquareDistance(ii)))<myEps)
-                          { 
-                            Pt=ExtPF.Point(ii);
-                            // on regarde si le parametre ne correspondont pas a un vertex
-                            ExtPF.Parameter(ii,U,V);
-                            // Standard_Real t1 =Ext.ParameterOnEdge(ii) ;
-                            
-                            PUV.SetCoord(U,V);
-                            Standard_Real tol=BRep_Tool::Tolerance(S1);
-                            classifier.Perform(S1,PUV,tol);
-                            notavertex=(classifier.State()==TopAbs_IN); 
-                            if (notavertex)
-                              {
-                                //  Modified by Sergey KHROMOV - Tue Mar  6 12:28:51 2001 Begin
-                                if (myDstRef > Dstmin)
-                                  myDstRef=Dstmin;
-                                //  Modified by Sergey KHROMOV - Tue Mar  6 12:28:54 2001 End
-                                myModif=Standard_True;
-                                P1=BRep_Tool::Pnt(V1);                          
-                                BRepExtrema_SolutionElem Sol1 (Dstmin,Pt,BRepExtrema_IsInFace,S1,U,V);
-                                BRepExtrema_SolutionElem Sol2 (Dstmin,P1,BRepExtrema_IsOnEdge,S2,aParameter);
-                                SeqSolution1.Append(Sol1);
-                                SeqSolution2.Append(Sol2);                              
-                              }
-                          }
-                      }
-                  }
-              }
-          }
-        BRepExtrema_SeqOfSolution seqSol1;
-        BRepExtrema_SeqOfSolution seqSol2;
-        Standard_Boolean bIsMini = Standard_False;
-        if (SeqSolution1.Length() > 0 && SeqSolution2.Length() > 0)
-          MIN_SOLUTION(SeqSolution1, SeqSolution2, myDstRef, myEps, seqSol1, seqSol2);
-        
-        if (!seqSol1.IsEmpty() && !seqSol2.IsEmpty())
-          {
-            SeqSolShape1.Append(seqSol1);
-            SeqSolShape2.Append(seqSol2);
-          }
-       }
-     
-   }
- }
- }
+    const Standard_Real DstRef = myDstRef;
 
-/*********************************************************************************/
+    BRepExtrema_ExtCC Ext(S1,S2);
+       const Standard_Integer NbExtrema = Ext.IsDone()? (Ext.IsParallel()? 0 : Ext.NbExt()) : 0;
+    if ( NbExtrema > 0 )
+    {
+      // Search minimum distance Dstmin
+      Standard_Integer i;
+      Standard_Real Dstmin = Ext.SquareDistance(1);
+      for (i = 2; i <= NbExtrema; i++)
+      {
+        const Standard_Real sDst = Ext.SquareDistance(i);
+        if (sDst<Dstmin) 
+          Dstmin=sDst;
+         }
+      Dstmin = sqrt(Dstmin);
+      if ((Dstmin < myDstRef - myEps) || (fabs(Dstmin-myDstRef) < myEps))
+      {
+        Standard_Real Udeb1,Ufin1,Udeb2,Ufin2;
+        BRep_Tool::Range(S1,Udeb1,Ufin1);
+        BRep_Tool::Range(S2,Udeb2,Ufin2);
 
-void BRepExtrema_DistanceSS::Perform(const TopoDS_Face& S1, const TopoDS_Face& S2, 
-                                     const Bnd_Box& B1, const Bnd_Box& B2, 
-                                     const Standard_Real DstRef)
+        gp_Pnt Pt1,Pt2;
+        const Standard_Real epsP=Precision::PConfusion();
 
-{
-   Standard_Real Dst,Dstmin,epsP,U1,V1,U2,V2,tol ; 
-   gp_Pnt Pt1,Pt2;
-   gp_Pnt2d PUV;
-   Standard_Boolean insere1,insere2,notavertex;
-   BRepClass_FaceClassifier classifier;
-   Standard_Integer i;  
-   
-   epsP=Precision::PConfusion();
-   SeqSolShape1.Clear();
-   SeqSolShape2.Clear();
-   myModif=Standard_False;
-   Dst=B1.Distance(B2);
-   if ( (Dst< DstRef  -myEps ) || (fabs(Dst-DstRef)< myEps ))     
-   { 
-     BRepExtrema_ExtFF Ext(S1,S2);
-     if ( (Ext.IsDone()) && ((Ext.NbExt() > 0) && (!Ext.IsParallel()) ))
-       { Standard_Integer NbExtrema=Ext.NbExt();
-//       Recherche de la distance minimum dstmin
-         Dstmin=sqrt (Ext.SquareDistance(1));
-         for (i=2;i<=NbExtrema;i++)
-          {Dst=sqrt(Ext.SquareDistance(i));
-            if (Dst<Dstmin) 
-               Dstmin=Dst;
-           }
-         if ((Dstmin < DstRef -myEps) || (fabs(Dstmin-DstRef)<myEps))
-         for (i=1;i<=NbExtrema;i++)
-          { if (fabs(Dstmin-sqrt (Ext.SquareDistance(i)))<myEps)
-                    {Pt1=Ext.PointOnFace1(i);
-                      Pt2=Ext.PointOnFace2(i); 
-                      TRI_SOLUTION (SeqSolShape1,Pt1,insere1);
-                      TRI_SOLUTION (SeqSolShape2,Pt2,insere2) ;                             
-                         if (insere1||insere2)
-                        {
-                          // on regarde si le parametre ne correspondont pas a un vertex
-              
-
-                    
-                          Ext.ParameterOnFace1(i,U1,V1);
-                          PUV.SetCoord(U1,V1);
-                         tol=BRep_Tool::Tolerance(S1);
-                          classifier.Perform(S1,PUV,tol);
-                          notavertex=(classifier.State()==TopAbs_IN);
-  
-                          Ext.ParameterOnFace2(i,U2,V2);
-                          PUV.SetCoord(U2,V2);
-                         tol=BRep_Tool::Tolerance(S2);
-                          classifier.Perform(S2,PUV,tol);
-                          if (classifier.State()!=TopAbs_IN) notavertex= Standard_False;
-                          
-                          if (notavertex)
-                          {
-//  Modified by Sergey KHROMOV - Tue Mar  6 12:28:51 2001 Begin
-                          if (myDstRef > Dstmin)
-                            myDstRef=Dstmin;
-//  Modified by Sergey KHROMOV - Tue Mar  6 12:28:54 2001 End
-                           myModif=Standard_True;
-                           BRepExtrema_SolutionElem Sol1 (Dstmin,Pt1,BRepExtrema_IsInFace,S1,U1,V1);
-                           BRepExtrema_SolutionElem Sol2 (Dstmin,Pt2,BRepExtrema_IsInFace,S2,U2,V2);
-                           SeqSolShape1.Append(Sol1);
-                           SeqSolShape2.Append(Sol2);            
-                          }
-                        }
-                    }
-          }
-   }
-   }
-}
+        for (i=1;i<=NbExtrema;i++)
+        {
+          if (fabs(Dstmin-sqrt(Ext.SquareDistance(i)))<myEps)
+          {
+            Pt1=Ext.PointOnE1(i);
+            Pt2=Ext.PointOnE2(i);
+            if (TRI_SOLUTION(SeqSolShape1,Pt1) || TRI_SOLUTION(SeqSolShape2,Pt2))
+            {
+              // Check if the parameters do not correspond to a vertex
+              const Standard_Real t1 = Ext.ParameterOnE1(i);
+              const Standard_Real t2 = Ext.ParameterOnE2(i);
+              if ((fabs(t1-Udeb1)>=epsP)&&(fabs(t1-Ufin1)>epsP)&&(fabs(t2-Udeb2)>=epsP)&&(fabs(t2-Ufin2)>epsP))
+              {
+                if (myDstRef > Dstmin)
+                  myDstRef=Dstmin;
+                myModif=Standard_True;
+                const BRepExtrema_SolutionElem Sol1(Dstmin,Pt1,BRepExtrema_IsOnEdge,S1,t1);
+                const BRepExtrema_SolutionElem Sol2(Dstmin,Pt2,BRepExtrema_IsOnEdge,S2,t2);
+                SeqSolShape1.Append(Sol1);
+                SeqSolShape2.Append(Sol2);
+              }
+            }
+          }
+        }
+      }
+    }
 
-/*********************************************************************************/
+    BRepExtrema_SeqOfSolution SeqSolution1;
+    BRepExtrema_SeqOfSolution SeqSolution2;
 
-Standard_Boolean BRepExtrema_DistanceSS::IsDone() const 
-{
-  return myModif;
+    PERFORM_C0(S1, S2, SeqSolution1, SeqSolution2, DstRef, myDstRef, myEps);
+     
+    BRepExtrema_SeqOfSolution seqSol1;
+    BRepExtrema_SeqOfSolution seqSol2;
+       
+    if (SeqSolution1.Length() > 0 && SeqSolution2.Length() > 0)
+      MIN_SOLUTION(SeqSolution1, SeqSolution2, myDstRef, myEps, seqSol1, seqSol2);
+     
+    if (!seqSol1.IsEmpty() && !seqSol2.IsEmpty())
+    {
+      SeqSolShape1.Append(seqSol1);
+      SeqSolShape2.Append(seqSol2);    
+      myModif = Standard_True;
+    }
+  }
 }
 
 /*********************************************************************************/
 
-Standard_Real BRepExtrema_DistanceSS::DistValue() const 
+void BRepExtrema_DistanceSS::Perform(const TopoDS_Edge& S1, const TopoDS_Face& S2,
+                                     const Bnd_Box& B1, const Bnd_Box& B2)
 {
- return myDstRef;
-}
+  if (BRep_Tool::Degenerated(S1))
+    return;
+    
+  const Standard_Real Dst=B1.Distance(B2);
+  if ((Dst < myDstRef - myEps) || (fabs(Dst-myDstRef) < myEps))
+  {
+    BRepClass_FaceClassifier classifier;
 
-/*********************************************************************************/
+    BRepExtrema_ExtCF Ext(S1,S2);
+       const Standard_Integer NbExtrema = Ext.IsDone()? (Ext.IsParallel()? 0 : Ext.NbExt()) : 0;
+    if ( NbExtrema > 0 )
+    {
+      // Search minimum distance Dstmin
+      Standard_Integer i;
+      Standard_Real Dstmin = Ext.SquareDistance(1);
+      for (i = 2; i <= NbExtrema; i++)
+      {
+        const Standard_Real sDst = Ext.SquareDistance(i);
+        if (sDst<Dstmin) 
+          Dstmin=sDst;
+      }
+      Dstmin = sqrt(Dstmin);
+      if ((Dstmin < myDstRef - myEps) || (fabs(Dstmin-myDstRef) < myEps))
+      {
+        Standard_Real Udeb,Ufin,U,V;
+        BRep_Tool::Range(S1,Udeb,Ufin);
+        const Standard_Real tol=BRep_Tool::Tolerance(S2);
 
-const BRepExtrema_SeqOfSolution& BRepExtrema_DistanceSS::Seq1Value() const 
-{
- return  SeqSolShape1;
+        gp_Pnt Pt1,Pt2;
+        const Standard_Real epsP=Precision::PConfusion();
+
+        for (i = 1; i <= NbExtrema; i++)
+        {
+          if (fabs(Dstmin-sqrt(Ext.SquareDistance(i)))<myEps)
+          {
+            Pt1=Ext.PointOnEdge(i);
+            Pt2=Ext.PointOnFace(i);
+            if (TRI_SOLUTION(SeqSolShape1,Pt1) || TRI_SOLUTION(SeqSolShape2,Pt2))
+            {
+              // Check if the parameter does not correspond to a vertex
+              const Standard_Real t1 = Ext.ParameterOnEdge(i);
+              if ((fabs(t1-Udeb)>=epsP)&&(fabs(t1-Ufin)>epsP))
+              {
+                Ext.ParameterOnFace(i,U,V);
+                const gp_Pnt2d PUV(U,V);
+                classifier.Perform(S2,PUV,tol);
+                if (classifier.State()==TopAbs_IN)
+                {
+                  if (myDstRef > Dstmin)
+                    myDstRef=Dstmin;
+                  myModif=Standard_True;
+                  const BRepExtrema_SolutionElem Sol1(Dstmin,Pt1,BRepExtrema_IsOnEdge,S1,t1);
+                  const BRepExtrema_SolutionElem Sol2(Dstmin,Pt2,BRepExtrema_IsInFace,S2,U,V);
+                  SeqSolShape1.Append(Sol1);
+                  SeqSolShape2.Append(Sol2);             
+                }
+              }
+            }
+          }
+        }
+      }
+    }
+
+    Standard_Real aFirst, aLast;
+    Handle(Geom_Curve) pCurv = BRep_Tool::Curve(S1, aFirst, aLast);
+    if (pCurv->Continuity() == GeomAbs_C0)
+    {
+      BRepExtrema_SeqOfSolution SeqSolution1;
+      BRepExtrema_SeqOfSolution SeqSolution2;
+
+      GeomAdaptor_Curve aAdaptorCurve(pCurv, aFirst, aLast);
+      const Standard_Integer nbIntervals = aAdaptorCurve.NbIntervals(GeomAbs_C1);
+
+      TColStd_Array1OfReal arrInter(1,1+nbIntervals);
+      aAdaptorCurve.Intervals(arrInter, GeomAbs_C1);
+
+      gp_Pnt Pt;
+      Standard_Real U,V;
+      const Standard_Real tol = BRep_Tool::Tolerance(S2);
+
+      Standard_Integer i;
+      for (i = 1; i <= arrInter.Length(); i++)
+      {
+        const Standard_Real aParameter = arrInter(i);
+        gp_Pnt aPnt = aAdaptorCurve.Value(aParameter);
+        TopoDS_Vertex V1 = BRepBuilderAPI_MakeVertex(aPnt);
+
+        BRepExtrema_ExtPF ExtPF(V1,S2);
+        const Standard_Integer NbExtrema = ExtPF.IsDone()? ExtPF.NbExt() : 0;
+        if ( NbExtrema > 0 )
+        {
+          // Search minimum distance Dstmin
+          Standard_Integer ii;
+          Standard_Real Dstmin = ExtPF.SquareDistance(1);
+          for (ii = 2; ii <= NbExtrema; ii++)
+          {
+            const Standard_Real sDst = ExtPF.SquareDistance(ii);
+            if (sDst<Dstmin)
+              Dstmin=sDst;
+          }
+          Dstmin = sqrt(Dstmin);
+
+          if ((Dstmin < myDstRef - myEps) || (fabs(Dstmin-myDstRef) < myEps))
+          {
+            for (ii = 1; ii <= NbExtrema; ii++)
+            { 
+              if (fabs(Dstmin-sqrt(ExtPF.SquareDistance(ii)))<myEps)
+              { 
+                // Check if the parameter does not correspond to a vertex
+                ExtPF.Parameter(ii,U,V);
+                const gp_Pnt2d PUV(U,V);
+                               classifier.Perform(S2,PUV,tol);
+                if (classifier.State()==TopAbs_IN)
+                {
+                  if (myDstRef > Dstmin)
+                    myDstRef=Dstmin;
+                  myModif=Standard_True;
+                  const BRepExtrema_SolutionElem Sol1(Dstmin,aPnt,BRepExtrema_IsOnEdge,S1,aParameter);
+                  const BRepExtrema_SolutionElem Sol2(Dstmin,ExtPF.Point(ii),BRepExtrema_IsInFace,S2,U,V);
+                  SeqSolution1.Append(Sol1);
+                  SeqSolution2.Append(Sol2);
+                }
+              }
+            }
+          }
+        }
+      }
+
+      BRepExtrema_SeqOfSolution seqSol1;
+      BRepExtrema_SeqOfSolution seqSol2;
+      Standard_Boolean bIsMini = Standard_False;
+      if (SeqSolution1.Length() > 0 && SeqSolution2.Length() > 0)
+        MIN_SOLUTION(SeqSolution1, SeqSolution2, myDstRef, myEps, seqSol1, seqSol2);
+           
+      if (!seqSol1.IsEmpty() && !seqSol2.IsEmpty())
+      {
+        SeqSolShape1.Append(seqSol1);
+        SeqSolShape2.Append(seqSol2);
+      }
+    }
+  }
 }
 
 /*********************************************************************************/
 
-const BRepExtrema_SeqOfSolution& BRepExtrema_DistanceSS::Seq2Value() const 
-{ 
-return  SeqSolShape2; 
+void BRepExtrema_DistanceSS::Perform(const TopoDS_Face& S1, const TopoDS_Face& S2,
+                                     const Bnd_Box& B1, const Bnd_Box& B2)
+{
+  const Standard_Real Dst=B1.Distance(B2);
+  if ((Dst < myDstRef - myEps) || (fabs(Dst-myDstRef) < myEps))
+  { 
+    BRepExtrema_ExtFF Ext(S1,S2);
+       const Standard_Integer NbExtrema = Ext.IsDone()? (Ext.IsParallel()? 0 : Ext.NbExt()) : 0;
+    if ( NbExtrema > 0 )
+    {
+      // Search minimum distance Dstmin
+      Standard_Integer i;
+      Standard_Real Dstmin = Ext.SquareDistance(1);
+      for (i = 2; i <= NbExtrema; i++)
+      {
+        const Standard_Real sDst = Ext.SquareDistance(i);
+        if (sDst<Dstmin)
+          Dstmin=sDst;
+      }
+      Dstmin = sqrt(Dstmin);
+      if ((Dstmin < myDstRef - myEps) || (fabs(Dstmin-myDstRef) < myEps))
+      {
+        const Standard_Real tol1=BRep_Tool::Tolerance(S1);
+        const Standard_Real tol2=BRep_Tool::Tolerance(S2);
+
+        gp_Pnt Pt1,Pt2;
+        gp_Pnt2d PUV;
+        Standard_Real U1,V1,U2,V2;
+        BRepClass_FaceClassifier classifier;
+        const Standard_Real epsP=Precision::PConfusion();
+        for (i = 1; i <= NbExtrema; i++)
+        {
+          if (fabs(Dstmin-sqrt(Ext.SquareDistance(i)))<myEps)
+          {
+            Pt1=Ext.PointOnFace1(i);
+            Pt2=Ext.PointOnFace2(i); 
+            if (TRI_SOLUTION(SeqSolShape1,Pt1) || TRI_SOLUTION(SeqSolShape2,Pt2))
+            {
+              // Check if the parameter does not correspond to a vertex
+              Ext.ParameterOnFace1(i,U1,V1);
+              PUV.SetCoord(U1,V1);
+              classifier.Perform(S1,PUV,tol1);
+              if (classifier.State()==TopAbs_IN)
+              {
+                Ext.ParameterOnFace2(i,U2,V2);
+                PUV.SetCoord(U2,V2);
+                classifier.Perform(S2,PUV,tol2);
+                if (classifier.State()==TopAbs_IN)
+                {
+                  if (myDstRef > Dstmin)
+                    myDstRef=Dstmin;
+                  myModif=Standard_True;
+                  const BRepExtrema_SolutionElem Sol1(Dstmin,Pt1,BRepExtrema_IsInFace,S1,U1,V1);
+                  const BRepExtrema_SolutionElem Sol2(Dstmin,Pt2,BRepExtrema_IsInFace,S2,U2,V2);
+                  SeqSolShape1.Append(Sol1);
+                  SeqSolShape2.Append(Sol2);
+                }
+              }
+            }
+          }
+        }
+      }
+    }
+  }
 }
 
 /*********************************************************************************/
-/*********************************************************************************/
diff --git a/src/BRepExtrema/BRepExtrema_DistanceSS.hxx b/src/BRepExtrema/BRepExtrema_DistanceSS.hxx
new file mode 100644 (file)
index 0000000..4464411
--- /dev/null
@@ -0,0 +1,174 @@
+// File generated by CPPExt (Value)
+//
+//                     Copyright (C) 1991 - 2000 by  
+//                      Matra Datavision SA.  All rights reserved.
+//  
+//                     Copyright (C) 2001 - 2004 by
+//                     Open CASCADE SA.  All rights reserved.
+// 
+// This file is part of the Open CASCADE Technology software.
+//
+// This software may be distributed and/or modified under the terms and
+// conditions of the Open CASCADE Public License as defined by Open CASCADE SA
+// and appearing in the file LICENSE included in the packaging of this file.
+//  
+// This software is distributed on an "AS IS" basis, without warranty of any
+// kind, and Open CASCADE SA hereby disclaims all such warranties,
+// including without limitation, any warranties of merchantability, fitness
+// for a particular purpose or non-infringement. Please see the License for
+// the specific terms and conditions governing rights and limitations under the
+// License.
+
+#ifndef _BRepExtrema_DistanceSS_HeaderFile
+#define _BRepExtrema_DistanceSS_HeaderFile
+
+#ifndef _Standard_HeaderFile
+#include <Standard.hxx>
+#endif
+#ifndef _Standard_Macro_HeaderFile
+#include <Standard_Macro.hxx>
+#endif
+
+#ifndef _BRepExtrema_SeqOfSolution_HeaderFile
+#include <BRepExtrema_SeqOfSolution.hxx>
+#endif
+#ifndef _Standard_Real_HeaderFile
+#include <Standard_Real.hxx>
+#endif
+#ifndef _Standard_Boolean_HeaderFile
+#include <Standard_Boolean.hxx>
+#endif
+#ifndef _Extrema_ExtFlag_HeaderFile
+#include <Extrema_ExtFlag.hxx>
+#endif
+#ifndef _Extrema_ExtAlgo_HeaderFile
+#include <Extrema_ExtAlgo.hxx>
+#endif
+#ifndef _Precision_HeaderFile
+#include <Precision.hxx>
+#endif
+class TopoDS_Shape;
+class Bnd_Box;
+class TopoDS_Vertex;
+class TopoDS_Edge;
+class TopoDS_Face;
+
+
+//!  This class allows to compute minimum distance between two shapes <br>
+//! (face edge vertex) and is used in DistShapeShape class. <br>
+class BRepExtrema_DistanceSS
+{
+ public:
+
+  void* operator new(size_t,void* anAddress) 
+  {
+    return anAddress;
+  }
+  void* operator new(size_t size) 
+  {
+    return Standard::Allocate(size); 
+  }
+  void  operator delete(void *anAddress) 
+  {
+    if (anAddress) Standard::Free((Standard_Address&)anAddress); 
+  }
+
+  //! computes the distance between two Shapes ( face edge vertex). <br>
+  Standard_EXPORT BRepExtrema_DistanceSS(const TopoDS_Shape& S1, const TopoDS_Shape& S2,
+                                         const Bnd_Box& B1, const Bnd_Box& B2,
+                                         const Standard_Real DstRef,
+                                         const Extrema_ExtFlag F = Extrema_ExtFlag_MINMAX,
+                                         const Extrema_ExtAlgo A = Extrema_ExtAlgo_Grad)
+  : myDstRef(DstRef), myModif(Standard_False), myEps(Precision::Confusion()), myFlag(F), myAlgo(A)
+  {
+    Perform(S1, S2, B1, B2);
+  }
+  //! computes the distance between two Shapes ( face edge vertex). <br>
+  //! Parameter theDeflection is used to specify a maximum deviation <br>
+  //! of extreme distances from the minimum one. <br>
+  //! Default value is Precision::Confusion(). <br>
+  Standard_EXPORT BRepExtrema_DistanceSS(const TopoDS_Shape& S1, const TopoDS_Shape& S2,
+                                         const Bnd_Box& B1, const Bnd_Box& B2,
+                                         const Standard_Real DstRef, const Standard_Real aDeflection,
+                                         const Extrema_ExtFlag F = Extrema_ExtFlag_MINMAX,
+                                         const Extrema_ExtAlgo A = Extrema_ExtAlgo_Grad)
+  : myDstRef(DstRef), myModif(Standard_False), myEps(aDeflection), myFlag(F), myAlgo(A)
+  {
+    Perform(S1, S2, B1, B2);
+  }
+  //! True if the distance has been computed <br>
+  Standard_EXPORT Standard_Boolean IsDone() const
+  {
+    return myModif;
+  }
+  //! returns the distance value <br>
+  Standard_EXPORT Standard_Real DistValue() const
+  {
+    return myDstRef;
+  }
+  //! returns the list of solutions on the first shape <br>
+  Standard_EXPORT const BRepExtrema_SeqOfSolution& Seq1Value() const
+  {
+    return SeqSolShape1;
+  }
+  //! returns the list of solutions on the second shape <br>
+  Standard_EXPORT const BRepExtrema_SeqOfSolution& Seq2Value() const
+  {
+    return SeqSolShape2;
+  }
+  //! sets the flag controlling minimum and maximum search
+  Standard_EXPORT void SetFlag(const Extrema_ExtFlag F)
+  {
+    myFlag = F;
+  }
+  //! sets the flag controlling ...
+  Standard_EXPORT void SetAlgo(const Extrema_ExtAlgo A)
+  {
+    myAlgo = A;
+  }
+
+ private:
+
+  //! computes the distance between two Shapes ( face edge vertex) <br>
+  void Perform(const TopoDS_Shape& S1,const TopoDS_Shape& S2,const Bnd_Box& B1,const Bnd_Box& B2);
+
+  //! computes the distance between two vertices <br>
+  void Perform(const TopoDS_Vertex& S1,const TopoDS_Vertex& S2);
+  //! computes the minimum distance between a vertex and an edge <br>
+  void Perform(const TopoDS_Vertex& S1,const TopoDS_Edge& S2,const Bnd_Box& B1,const Bnd_Box& B2);
+  //! computes the minimum distance between a vertex and a face <br>
+  void Perform(const TopoDS_Vertex& S1,const TopoDS_Face& S2,const Bnd_Box& B1,const Bnd_Box& B2);
+
+  //! computes the minimum distance between an edge and a vertex <br>
+  void Perform(const TopoDS_Edge& S1,const TopoDS_Vertex& S2,const Bnd_Box& B1,const Bnd_Box& B2)
+  {
+    Perform(S2, S1, B2, B1);
+  }
+  //! computes the minimum distance between two edges <br>
+  void Perform(const TopoDS_Edge& S1,const TopoDS_Edge& S2,const Bnd_Box& B1,const Bnd_Box& B2);
+  //! computes the minimum distance an edge and a face <br>
+  void Perform(const TopoDS_Edge& S1,const TopoDS_Face& S2,const Bnd_Box& B1,const Bnd_Box& B2);
+
+  //! computes the minimum distance betwwen a face and a vertex <br>
+  void Perform(const TopoDS_Face& S1,const TopoDS_Vertex& S2,const Bnd_Box& B1,const Bnd_Box& B2)
+  {
+    Perform(S2, S1, B2, B1);
+  }
+  //! computes the minimum distance between a face and an edge <br>
+  void Perform(const TopoDS_Face& S1,const TopoDS_Edge& S2,const Bnd_Box& B1,const Bnd_Box& B2)
+  {
+    Perform(S2, S1, B2, B1);
+  }
+  //! computes the minimum distance between two faces <br>
+  void Perform(const TopoDS_Face& S1,const TopoDS_Face& S2,const Bnd_Box& B1,const Bnd_Box& B2);
+
+  BRepExtrema_SeqOfSolution SeqSolShape1;
+  BRepExtrema_SeqOfSolution SeqSolShape2;
+  Standard_Real myDstRef;
+  Standard_Boolean myModif;
+  Standard_Real myEps;
+  Extrema_ExtFlag myFlag;
+  Extrema_ExtAlgo myAlgo;
+};
+
+#endif
index 7b247d4..3909c63 100755 (executable)
@@ -1,12 +1,10 @@
 // File:       BRepExtrema_ExtCC.cxx
 // Created:    Wed Dec 15 16:48:53 1993
 // Author:     Christophe MARION
-//             <cma@sdsun1>
 
-#include <BRepExtrema_ExtCC.ixx>
+#include <BRepExtrema_ExtCC.hxx>
+
 #include <BRep_Tool.hxx>
-#include <StdFail_NotDone.hxx>
-#include <Standard_Failure.hxx>
 #include <Extrema_POnCurv.hxx>
 #include <BRepAdaptor_Curve.hxx>
 #include <BRepAdaptor_HCurve.hxx>
 //purpose  : 
 //=======================================================================
 
-BRepExtrema_ExtCC::BRepExtrema_ExtCC()
-{
-}
-
-//=======================================================================
-//function : BRepExtrema_ExtCC
-//purpose  : 
-//=======================================================================
-
-BRepExtrema_ExtCC::BRepExtrema_ExtCC
-  (const TopoDS_Edge& E1,
-   const TopoDS_Edge& E2)
+BRepExtrema_ExtCC::BRepExtrema_ExtCC(const TopoDS_Edge& E1, const TopoDS_Edge& E2)
 {
   Initialize(E2);
   Perform(E1);
@@ -45,7 +32,7 @@ void BRepExtrema_ExtCC::Initialize(const TopoDS_Edge& E2)
   BRepAdaptor_Curve Curv(E2);
   myHC = new BRepAdaptor_HCurve(Curv);
   BRep_Tool::Range(E2,V1,V2);
-  myExtrem.SetCurve (2, myHC->Curve(),V1,V2);
+  myExtCC.SetCurve(2,myHC->Curve(),V1,V2);
 }
 
 //=======================================================================
@@ -59,49 +46,8 @@ void BRepExtrema_ExtCC::Perform(const TopoDS_Edge& E1)
   BRepAdaptor_Curve Curv(E1);
   Handle(BRepAdaptor_HCurve) HC = new BRepAdaptor_HCurve(Curv);
   BRep_Tool::Range(E1,U1,U2);
-  myExtrem.SetCurve (1, HC->Curve(), U1, U2);
-  myExtrem.Perform();
-}
-
-//=======================================================================
-//function : IsDone
-//purpose  : 
-//=======================================================================
-
-Standard_Boolean BRepExtrema_ExtCC::IsDone()const
-{
-  return myExtrem.IsDone();
-}
-
-//=======================================================================
-//function : NbExt
-//purpose  : 
-//=======================================================================
-
-Standard_Integer BRepExtrema_ExtCC::NbExt() const
-{
-  return myExtrem.NbExt();
-}
-
-//=======================================================================
-//function : IsMin
-//purpose  : 
-//=======================================================================
-
-Standard_Boolean BRepExtrema_ExtCC::IsParallel() const
-{
-  return myExtrem.IsParallel();
-}
-
-//=======================================================================
-//function : SquareDistance
-//purpose  : 
-//=======================================================================
-
-Standard_Real BRepExtrema_ExtCC::SquareDistance
-  (const Standard_Integer N) const
-{
-  return myExtrem.SquareDistance(N);
+  myExtCC.SetCurve (1, HC->Curve(), U1, U2);
+  myExtCC.Perform();
 }
 
 //=======================================================================
@@ -109,11 +55,10 @@ Standard_Real BRepExtrema_ExtCC::SquareDistance
 //purpose  : 
 //=======================================================================
 
-Standard_Real BRepExtrema_ExtCC::ParameterOnE1
-  (const Standard_Integer N) const
+Standard_Real BRepExtrema_ExtCC::ParameterOnE1(const Standard_Integer N) const
 {
   Extrema_POnCurv POnE1, POnE2;
-  myExtrem.Points(N, POnE1, POnE2);
+  myExtCC.Points(N, POnE1, POnE2);
   return POnE1.Parameter();
 }
 
@@ -122,13 +67,11 @@ Standard_Real BRepExtrema_ExtCC::ParameterOnE1
 //purpose  : 
 //=======================================================================
 
-gp_Pnt BRepExtrema_ExtCC::PointOnE1
-  (const Standard_Integer N) const
+gp_Pnt BRepExtrema_ExtCC::PointOnE1(const Standard_Integer N) const
 {
   Extrema_POnCurv POnE1, POnE2;
-  myExtrem.Points(N, POnE1, POnE2);
-  gp_Pnt P = POnE1.Value();
-  return P; 
+  myExtCC.Points(N, POnE1, POnE2);
+  return POnE1.Value();
 }
 
 //=======================================================================
@@ -136,11 +79,10 @@ gp_Pnt BRepExtrema_ExtCC::PointOnE1
 //purpose  : 
 //=======================================================================
 
-Standard_Real BRepExtrema_ExtCC::ParameterOnE2
-  (const Standard_Integer N) const
+Standard_Real BRepExtrema_ExtCC::ParameterOnE2(const Standard_Integer N) const
 {
   Extrema_POnCurv POnE1, POnE2;
-  myExtrem.Points(N, POnE1, POnE2);
+  myExtCC.Points(N, POnE1, POnE2);
   return POnE2.Parameter();
 }
 
@@ -149,13 +91,11 @@ Standard_Real BRepExtrema_ExtCC::ParameterOnE2
 //purpose  : 
 //=======================================================================
 
-gp_Pnt BRepExtrema_ExtCC::PointOnE2
-  (const Standard_Integer N) const
+gp_Pnt BRepExtrema_ExtCC::PointOnE2(const Standard_Integer N) const
 {
   Extrema_POnCurv POnE1, POnE2;
-  myExtrem.Points(N, POnE1, POnE2);
-  gp_Pnt P = POnE2.Value();
-  return P; 
+  myExtCC.Points(N, POnE1, POnE2);
+  return POnE2.Value();
 }
 
 
@@ -174,7 +114,6 @@ void BRepExtrema_ExtCC::TrimmedSquareDistances
    gp_Pnt& pnt21,
    gp_Pnt& pnt22) const
 {
-  myExtrem.TrimmedSquareDistances(dist11,dist12,dist21, dist22,
-                           pnt11,pnt12, pnt21, pnt22);
+  myExtCC.TrimmedSquareDistances(dist11,dist12,dist21,dist22,
+                                 pnt11,pnt12,pnt21,pnt22);
 }
-
diff --git a/src/BRepExtrema/BRepExtrema_ExtCC.hxx b/src/BRepExtrema/BRepExtrema_ExtCC.hxx
new file mode 100644 (file)
index 0000000..a6e2fcd
--- /dev/null
@@ -0,0 +1,102 @@
+// This file is generated by WOK (CPPExt).
+// Please do not edit this file; modify original file instead.
+// The copyright and license terms as defined for the original file apply to 
+// this header file considered to be the "object code" form of the original source.
+
+#ifndef _BRepExtrema_ExtCC_HeaderFile
+#define _BRepExtrema_ExtCC_HeaderFile
+
+#ifndef _Standard_HeaderFile
+#include <Standard.hxx>
+#endif
+#ifndef _Standard_Macro_HeaderFile
+#include <Standard_Macro.hxx>
+#endif
+
+#ifndef _Extrema_ExtCC_HeaderFile
+#include <Extrema_ExtCC.hxx>
+#endif
+#ifndef _Handle_BRepAdaptor_HCurve_HeaderFile
+#include <Handle_BRepAdaptor_HCurve.hxx>
+#endif
+#ifndef _Standard_Boolean_HeaderFile
+#include <Standard_Boolean.hxx>
+#endif
+#ifndef _Standard_Integer_HeaderFile
+#include <Standard_Integer.hxx>
+#endif
+#ifndef _Standard_Real_HeaderFile
+#include <Standard_Real.hxx>
+#endif
+class BRepAdaptor_HCurve;
+class TopoDS_Edge;
+class gp_Pnt;
+
+
+class BRepExtrema_ExtCC
+{
+ public:
+
+  void* operator new(size_t,void* anAddress) 
+  {
+    return anAddress;
+  }
+  void* operator new(size_t size) 
+  {
+    return Standard::Allocate(size); 
+  }
+  void  operator delete(void *anAddress) 
+  {
+    if (anAddress) Standard::Free((Standard_Address&)anAddress); 
+  }
+  
+  Standard_EXPORT BRepExtrema_ExtCC()
+  {
+  }
+  //! It calculates all the distances. <br>
+  Standard_EXPORT BRepExtrema_ExtCC(const TopoDS_Edge& E1,const TopoDS_Edge& E2);
+
+  Standard_EXPORT void Initialize(const TopoDS_Edge& E2);
+  //! An exception is raised if the fields have not been initialized. <br>
+  Standard_EXPORT void Perform(const TopoDS_Edge& E1);
+  //! True if the distances are found. <br>
+  Standard_EXPORT Standard_Boolean IsDone() const
+  {
+    return myExtCC.IsDone();
+  }
+  //! Returns the number of extremum distances. <br>
+  Standard_EXPORT Standard_Integer NbExt() const
+  {
+    return myExtCC.NbExt();
+  }
+  //! Returns True if E1 and E2 are parallel. <br>
+  Standard_EXPORT Standard_Boolean IsParallel() const
+  {
+    return myExtCC.IsParallel();
+  }
+  //! Returns the value of the <N>th extremum square distance. <br>
+  Standard_EXPORT Standard_Real SquareDistance(const Standard_Integer N) const
+  {
+    return myExtCC.SquareDistance(N);
+  }
+  //! Returns the parameter on the first edge of the <N>th extremum distance. <br>
+  Standard_EXPORT Standard_Real ParameterOnE1(const Standard_Integer N) const;
+  //! Returns the Point of the <N>th extremum distance on the edge E1. <br>
+  Standard_EXPORT gp_Pnt PointOnE1(const Standard_Integer N) const;
+  //! Returns the parameter on the second edge of the <N>th extremum distance. <br>
+  Standard_EXPORT Standard_Real ParameterOnE2(const Standard_Integer N) const;
+  //! Returns the Point of the <N>th extremum distance on the edge E2. <br>
+  Standard_EXPORT gp_Pnt PointOnE2(const Standard_Integer N) const;
+  //! if the edges is a trimmed curve, <br>
+  //! dist11 is a square distance between the point on E1 <br>
+  //! of parameter FirstParameter and the point of <br>
+  //! parameter FirstParameter on E2. <br>
+  Standard_EXPORT void TrimmedSquareDistances(Standard_Real& dist11,Standard_Real& distP12,Standard_Real& distP21,Standard_Real& distP22,gp_Pnt& P11,gp_Pnt& P12,gp_Pnt& P21,gp_Pnt& P22) const;
+
+ private:
+
+  Extrema_ExtCC myExtCC;
+  Handle_BRepAdaptor_HCurve myHC;
+};
+
+#endif
index 1ea003b..0bd97b0 100755 (executable)
@@ -1,18 +1,13 @@
 // File:       BRepExtrema_ExtCF.cxx
 // Created:    Wed Dec 15 16:48:53 1993
 // Author:     Christophe MARION
-//             <cma@sdsun1>
 
-#include <BRepExtrema_ExtCF.ixx>
+#include <BRepExtrema_ExtCF.hxx>
+
 #include <BRep_Tool.hxx>
 #include <BRepTools.hxx>
 #include <Geom_Curve.hxx>
-#include <StdFail_NotDone.hxx>
-#include <Standard_Failure.hxx>
 #include <BRepClass_FaceClassifier.hxx>
-#include <GeomAdaptor_Surface.hxx>
-#include <Extrema_POnCurv.hxx>
-#include <Extrema_POnSurf.hxx>
 #include <gp_Pnt2d.hxx>
 #include <BRepAdaptor_Surface.hxx>
 #include <BRepAdaptor_HSurface.hxx>
 //purpose  : 
 //=======================================================================
 
-BRepExtrema_ExtCF::BRepExtrema_ExtCF()
-{
-}
-
-//=======================================================================
-//function : BRepExtrema_ExtCF
-//purpose  : 
-//=======================================================================
-
-BRepExtrema_ExtCF::BRepExtrema_ExtCF
-  (const TopoDS_Edge& E,
-   const TopoDS_Face& F)
+BRepExtrema_ExtCF::BRepExtrema_ExtCF(const TopoDS_Edge& E, const TopoDS_Face& F)
 {
   Initialize(F);
   Perform(E, F);
@@ -50,10 +34,10 @@ void BRepExtrema_ExtCF::Initialize(const TopoDS_Face& F2)
 {
   BRepAdaptor_Surface Surf(F2);
   myHS = new BRepAdaptor_HSurface(Surf);
-  Standard_Real Tol = BRep_Tool::Tolerance(F2);
+  const Standard_Real Tol = BRep_Tool::Tolerance(F2);
   Standard_Real U1, U2, V1, V2;
   BRepTools::UVBounds(F2, U1, U2, V1, V2);
-  myExtrem.Initialize(myHS->Surface(), U1, U2, V1, V2, Tol, Tol);
+  myExtCS.Initialize(myHS->Surface(), U1, U2, V1, V2, Tol, Tol);
 }
 
 //=======================================================================
@@ -61,149 +45,45 @@ void BRepExtrema_ExtCF::Initialize(const TopoDS_Face& F2)
 //purpose  : 
 //=======================================================================
 
-void BRepExtrema_ExtCF::Perform(const TopoDS_Edge& E,
-                               const TopoDS_Face& F2)
+void BRepExtrema_ExtCF::Perform(const TopoDS_Edge& E, const TopoDS_Face& F2)
 {
   mySqDist.Clear();
   myPointsOnS.Clear();
   myPointsOnC.Clear();
+
   Standard_Real U1, U2;
   BRep_Tool::Range(E, U1, U2);
 
   BRepAdaptor_Curve Curv(E);
   Handle(BRepAdaptor_HCurve) HC = new BRepAdaptor_HCurve(Curv);
-  myExtrem.Perform(HC->Curve(), U1, U2);
-
-  // exploration des points et classification:
-  BRepClass_FaceClassifier classifier;
-  gp_Pnt2d Puv;
-  TopAbs_State state;
-  Standard_Real Tol = BRep_Tool::Tolerance(F2);
-  Extrema_POnCurv P1;
-  Extrema_POnSurf P2;
-  mynbext = 0;
+  myExtCS.Perform(HC->Curve(), U1, U2);
 
-  if(!myExtrem.IsDone())
+  if(!myExtCS.IsDone())
     return;
 
-  if (myExtrem.IsParallel()) {
-    mySqDist.Append(myExtrem.SquareDistance(1));
-    mynbext = 1;
-  }
-  else {
-    for (Standard_Integer i = 1; i <= myExtrem.NbExt(); i++) {
-      myExtrem.Points(i, P1, P2);
+  if (myExtCS.IsParallel())
+    mySqDist.Append(myExtCS.SquareDistance(1));
+  else
+  {
+    // Exploration of points and classification
+    BRepClass_FaceClassifier classifier;
+    const Standard_Real Tol = BRep_Tool::Tolerance(F2);
+    Extrema_POnCurv P1;
+    Extrema_POnSurf P2;
+
+    for (Standard_Integer i = 1; i <= myExtCS.NbExt(); i++)
+    {
+      myExtCS.Points(i, P1, P2);
       P2.Parameter(U1, U2);
-      Puv.SetCoord(U1, U2);
+      const gp_Pnt2d Puv(U1, U2);
       classifier.Perform(F2, Puv, Tol);
-      state = classifier.State();
-      if(state == TopAbs_ON || state == TopAbs_IN) {
-       mynbext++;
-       mySqDist.Append(myExtrem.SquareDistance(i));
-       myPointsOnC.Append(P1);
-       myPointsOnS.Append(P2);
+      const TopAbs_State state = classifier.State();
+      if (state == TopAbs_ON || state == TopAbs_IN)
+      {
+        mySqDist.Append(myExtCS.SquareDistance(i));
+        myPointsOnC.Append(P1);
+        myPointsOnS.Append(P2);
       }
     }
   }
 }
-//=======================================================================
-//function : IsDone
-//purpose  : 
-//=======================================================================
-
-Standard_Boolean BRepExtrema_ExtCF::IsDone()const
-{
-  return myExtrem.IsDone();
-}
-
-
-//=======================================================================
-//function : IsParallel
-//purpose  : 
-//=======================================================================
-
-Standard_Boolean BRepExtrema_ExtCF::IsParallel()const
-{
-  return myExtrem.IsParallel();
-}
-
-//=======================================================================
-//function : NbExt
-//purpose  : 
-//=======================================================================
-
-Standard_Integer BRepExtrema_ExtCF::NbExt() const
-{
-  if(!myExtrem.IsDone()) StdFail_NotDone::Raise();
-  return mynbext;
-}
-
-
-//=======================================================================
-//function : SquareDistance
-//purpose  : 
-//=======================================================================
-
-Standard_Real BRepExtrema_ExtCF::SquareDistance
-  (const Standard_Integer N) const
-{
-  if(!myExtrem.IsDone()) StdFail_NotDone::Raise();
-  if ((N < 1) || (N > mynbext)) Standard_OutOfRange::Raise();
-  return mySqDist.Value(N);
-}
-
-//=======================================================================
-//function : ParameterOnFace
-//purpose  : 
-//=======================================================================
-
-void BRepExtrema_ExtCF::ParameterOnFace(const Standard_Integer N,
-                                        Standard_Real& U,
-                                        Standard_Real& V) const
-{
-  if(!myExtrem.IsDone()) StdFail_NotDone::Raise();
-  if ((N < 1) || (N > mynbext)) Standard_OutOfRange::Raise();
-  myPointsOnS.Value(N).Parameter(U, V);
-}
-
-//=======================================================================
-//function : ParameterOnEdge
-//purpose  : 
-//=======================================================================
-
-Standard_Real BRepExtrema_ExtCF::ParameterOnEdge
-  (const Standard_Integer N) const
-{
-  if(!myExtrem.IsDone()) StdFail_NotDone::Raise();
-  if ((N < 1) || (N > mynbext)) Standard_OutOfRange::Raise();
-  return myPointsOnC.Value(N).Parameter();
-}
-
-//=======================================================================
-//function : PointOnEdge
-//purpose  : 
-//=======================================================================
-
-gp_Pnt BRepExtrema_ExtCF::PointOnEdge
-  (const Standard_Integer N) const
-{
-  if(!myExtrem.IsDone()) StdFail_NotDone::Raise();
-  if ((N < 1) || (N > mynbext)) Standard_OutOfRange::Raise();
-  gp_Pnt P = myPointsOnC.Value(N).Value();
-  return P; 
-}
-
-//=======================================================================
-//function : PointOnFace
-//purpose  : 
-//=======================================================================
-
-gp_Pnt BRepExtrema_ExtCF::PointOnFace
-  (const Standard_Integer N) const
-{
-  if(!myExtrem.IsDone()) StdFail_NotDone::Raise();
-  if ((N < 1) || (N > mynbext)) Standard_OutOfRange::Raise();
-  gp_Pnt P = myPointsOnS.Value(N).Value();
-  return P; 
-}
-
diff --git a/src/BRepExtrema/BRepExtrema_ExtCF.hxx b/src/BRepExtrema/BRepExtrema_ExtCF.hxx
new file mode 100644 (file)
index 0000000..1fb6d62
--- /dev/null
@@ -0,0 +1,129 @@
+// This file is generated by WOK (CPPExt).
+// Please do not edit this file; modify original file instead.
+// The copyright and license terms as defined for the original file apply to 
+// this header file considered to be the "object code" form of the original source.
+
+#ifndef _BRepExtrema_ExtCF_HeaderFile
+#define _BRepExtrema_ExtCF_HeaderFile
+
+#ifndef _Standard_HeaderFile
+#include <Standard.hxx>
+#endif
+#ifndef _Standard_Macro_HeaderFile
+#include <Standard_Macro.hxx>
+#endif
+
+#ifndef _Extrema_ExtCS_HeaderFile
+#include <Extrema_ExtCS.hxx>
+#endif
+#ifndef _Standard_Integer_HeaderFile
+#include <Standard_Integer.hxx>
+#endif
+#ifndef _TColStd_SequenceOfReal_HeaderFile
+#include <TColStd_SequenceOfReal.hxx>
+#endif
+#ifndef _Extrema_SequenceOfPOnSurf_HeaderFile
+#include <Extrema_SequenceOfPOnSurf.hxx>
+#endif
+#ifndef _Extrema_SequenceOfPOnCurv_HeaderFile
+#include <Extrema_SequenceOfPOnCurv.hxx>
+#endif
+#ifndef _Handle_BRepAdaptor_HSurface_HeaderFile
+#include <Handle_BRepAdaptor_HSurface.hxx>
+#endif
+#ifndef _Standard_Boolean_HeaderFile
+#include <Standard_Boolean.hxx>
+#endif
+#ifndef _Standard_Real_HeaderFile
+#include <Standard_Real.hxx>
+#endif
+#ifndef _Extrema_POnCurv_HeaderFile
+#include <Extrema_POnCurv.hxx>
+#endif
+#ifndef _Extrema_POnSurf_HeaderFile
+#include <Extrema_POnSurf.hxx>
+#endif
+class BRepAdaptor_HSurface;
+class TopoDS_Edge;
+class TopoDS_Face;
+class gp_Pnt;
+
+
+class BRepExtrema_ExtCF
+{
+ public:
+
+  void* operator new(size_t,void* anAddress) 
+  {
+    return anAddress;
+  }
+  void* operator new(size_t size) 
+  {
+    return Standard::Allocate(size); 
+  }
+  void  operator delete(void *anAddress) 
+  {
+    if (anAddress) Standard::Free((Standard_Address&)anAddress); 
+  }
+
+  Standard_EXPORT BRepExtrema_ExtCF()
+  {
+  }
+  //! It calculates all the distances. <br>
+  Standard_EXPORT BRepExtrema_ExtCF(const TopoDS_Edge& V,const TopoDS_Face& E);
+
+  Standard_EXPORT void Initialize(const TopoDS_Face& E);
+  //! An exception is raised if the fields have not been initialized. <br>
+  //! Be careful: this method uses the Face only for classify not for the fields. <br>
+  Standard_EXPORT void Perform(const TopoDS_Edge& V,const TopoDS_Face& F);
+  //! True if the distances are found. <br>
+  Standard_EXPORT Standard_Boolean IsDone() const
+  {
+    return myExtCS.IsDone();
+  }
+  //! Returns the number of extremum distances. <br>
+  Standard_EXPORT Standard_Integer NbExt() const
+  {
+    return mySqDist.Length();
+  }
+  //! Returns the value of the <N>th extremum square distance. <br>
+  Standard_EXPORT Standard_Real SquareDistance(const Standard_Integer N) const
+  {
+    return mySqDist.Value(N);
+  }
+  //! Returns True if the curve is on a parallel surface. <br>
+  Standard_EXPORT Standard_Boolean IsParallel() const
+  {
+    return myExtCS.IsParallel();
+  }
+  //! Returns the parameters on the Edge of the <N>th extremum distance. <br>
+  Standard_EXPORT Standard_Real ParameterOnEdge(const Standard_Integer N) const
+  {
+    return myPointsOnC.Value(N).Parameter();
+  }
+  //! Returns the parameters on the Face of the <N>th extremum distance. <br>
+  Standard_EXPORT void ParameterOnFace(const Standard_Integer N,Standard_Real& U,Standard_Real& V) const
+  {
+    myPointsOnS.Value(N).Parameter(U, V);
+  }
+  //! Returns the Point of the <N>th extremum distance. <br>
+  Standard_EXPORT gp_Pnt PointOnEdge(const Standard_Integer N) const
+  {
+    return myPointsOnC.Value(N).Value();
+  }
+  //! Returns the Point of the <N>th extremum distance. <br>
+  Standard_EXPORT gp_Pnt PointOnFace(const Standard_Integer N) const
+  {
+    return myPointsOnS.Value(N).Value();
+  }
+
+ private:
+
+  Extrema_ExtCS myExtCS;
+  TColStd_SequenceOfReal mySqDist;
+  Extrema_SequenceOfPOnSurf myPointsOnS;
+  Extrema_SequenceOfPOnCurv myPointsOnC;
+  Handle_BRepAdaptor_HSurface myHS;
+};
+
+#endif
index 466bb12..515a8e2 100755 (executable)
@@ -1,22 +1,15 @@
 // File:       BRepExtrema_ExtFF.cxx
 // Created:    Wed Dec 15 16:48:53 1993
 // Author:     Christophe MARION
-//             <cma@sdsun1>
 // modified by mps (juillet 96 ): on utilise BRepAdaptor a la place de 
 // GeomAdaptor dans Initialize et Perform.
-#include <BRepExtrema_ExtFF.ixx>
+
+#include <BRepExtrema_ExtFF.hxx>
+
 #include <BRepExtrema_ExtCF.hxx>
 #include <BRep_Tool.hxx>
 #include <BRepTools.hxx>
-#include <Geom_Curve.hxx>
-#include <StdFail_NotDone.hxx>
-#include <Standard_Failure.hxx>
 #include <BRepClass_FaceClassifier.hxx>
-#include <TopoDS.hxx>
-#include <TopAbs_ShapeEnum.hxx>
-#include <TopExp_Explorer.hxx>
-#include <Geom_Surface.hxx>
-#include <Extrema_POnSurf.hxx>
 #include <gp_Pnt2d.hxx>
 #include <Precision.hxx>
 #include <BRepAdaptor_HSurface.hxx>
 //purpose  : 
 //=======================================================================
 
-BRepExtrema_ExtFF::BRepExtrema_ExtFF()
-{
-}
-
-//=======================================================================
-//function : BRepExtrema_ExtFF
-//purpose  : 
-//=======================================================================
-
-BRepExtrema_ExtFF::BRepExtrema_ExtFF
-  (const TopoDS_Face& F1,
-   const TopoDS_Face& F2)
+BRepExtrema_ExtFF::BRepExtrema_ExtFF(const TopoDS_Face& F1, const TopoDS_Face& F2)
 {
  Initialize(F2);
  Perform(F1,F2);
 }
+
 //=======================================================================
 //function : Initialize
 //purpose  : 
@@ -51,11 +34,10 @@ void BRepExtrema_ExtFF::Initialize(const TopoDS_Face& F2)
 {
   BRepAdaptor_Surface Surf(F2);
   myHS = new BRepAdaptor_HSurface(Surf);
-  Standard_Real Tol = BRep_Tool::Tolerance(F2);
+  const Standard_Real Tol = BRep_Tool::Tolerance(F2);
   Standard_Real U1, U2, V1, V2;
   BRepTools::UVBounds(F2, U1, U2, V1, V2);
-  myExtrem.Initialize(myHS->Surface(), U1, U2, V1, V2, Tol);
+  myExtSS.Initialize(myHS->Surface(), U1, U2, V1, V2, Tol);
 }
 
 //=======================================================================
@@ -63,156 +45,52 @@ void BRepExtrema_ExtFF::Initialize(const TopoDS_Face& F2)
 //purpose  : 
 //=======================================================================
 
-void BRepExtrema_ExtFF::Perform(const TopoDS_Face& F1,
-                               const TopoDS_Face& F2)
+void BRepExtrema_ExtFF::Perform(const TopoDS_Face& F1, const TopoDS_Face& F2)
 { 
-  Standard_Real U1, U2, V1, V2;
-  Standard_Integer i;   
   mySqDist.Clear();
   myPointsOnS1.Clear();
   myPointsOnS2.Clear();
+
   BRepAdaptor_Surface Surf1(F1);
   Handle(BRepAdaptor_HSurface) HS1 = new BRepAdaptor_HSurface(Surf1);
-  Standard_Real Tol1 = BRep_Tool::Tolerance(F1);
+  const Standard_Real Tol1 = BRep_Tool::Tolerance(F1);
+  Standard_Real U1, U2, V1, V2;
   BRepTools::UVBounds(F1, U1, U2, V1, V2);
-  myExtrem.Perform(HS1->Surface(), U1, U2, V1, V2, Tol1);
-
-  // exploration des points et classification:
-  BRepClass_FaceClassifier classifier;
-  gp_Pnt2d Puv;
-  TopAbs_State state1, state2;
-  Standard_Real Tol2 = BRep_Tool::Tolerance(F2);
-  Extrema_POnSurf P1, P2;
-  mynbext = 0;
-
-  if (myExtrem.IsParallel()) {
-    mySqDist.Append(myExtrem.SquareDistance(1));
-    mynbext = 1;
-  }
-  else {
-    for (i = 1; i <= myExtrem.NbExt(); i++) {
-      myExtrem.Points(i, P1, P2);
+  myExtSS.Perform(HS1->Surface(), U1, U2, V1, V2, Tol1);
+
+  if (!myExtSS.IsDone())
+    return;
+
+  if (myExtSS.IsParallel())
+    mySqDist.Append(myExtSS.SquareDistance(1));
+  else
+  {
+    // Exploration of points and classification
+    BRepClass_FaceClassifier classifier;
+    const Standard_Real Tol2 = BRep_Tool::Tolerance(F2);
+    Extrema_POnSurf P1, P2;
+
+    Standard_Integer i;
+    for (i = 1; i <= myExtSS.NbExt(); i++)
+    {
+      myExtSS.Points(i, P1, P2);
       P1.Parameter(U1, U2);
-      Puv.SetCoord(U1, U2);
-      classifier.Perform(F1, Puv, Tol1);
-      state1 = classifier.State();
-      P2.Parameter(U1, U2);
-      Puv.SetCoord(U1, U2);
-      classifier.Perform(F2, Puv, Tol2);
-      state2 = classifier.State();
-      if((state1 == TopAbs_ON || state1 == TopAbs_IN) &&
-        (state2 == TopAbs_ON || state2 == TopAbs_IN)) {
-       mynbext++;
-       mySqDist.Append(myExtrem.SquareDistance(i));
-       myPointsOnS1.Append(P1);
-       myPointsOnS2.Append(P2);
+      const gp_Pnt2d Puv1(U1, U2);
+      classifier.Perform(F1, Puv1, Tol1);
+      const TopAbs_State state1 = classifier.State();
+      if (state1 == TopAbs_ON || state1 == TopAbs_IN)
+      {
+        P2.Parameter(U1, U2);
+        const gp_Pnt2d Puv2(U1, U2);
+        classifier.Perform(F2, Puv2, Tol2);
+        const TopAbs_State state2 = classifier.State();
+        if (state2 == TopAbs_ON || state2 == TopAbs_IN)
+        {
+          mySqDist.Append(myExtSS.SquareDistance(i));
+          myPointsOnS1.Append(P1);
+          myPointsOnS2.Append(P2);
+        }
       }
     }
   }
 }
-  
-//=======================================================================
-//function : IsDone
-//purpose  : 
-//=======================================================================
-
-Standard_Boolean BRepExtrema_ExtFF::IsDone()const
-{
-  return myExtrem.IsDone();
-}
-
-//=======================================================================
-//function : IsParallel
-//purpose  : 
-//=======================================================================
-
-Standard_Boolean BRepExtrema_ExtFF::IsParallel()const
-{
-  return myExtrem.IsParallel();
-}
-
-
-//=======================================================================
-//function : NbExt
-//purpose  : 
-//=======================================================================
-
-Standard_Integer BRepExtrema_ExtFF::NbExt() const
-{
-  if(!myExtrem.IsDone()) StdFail_NotDone::Raise();
-  return mynbext;
-}
-
-
-//=======================================================================
-//function : SquareDistance
-//purpose  : 
-//=======================================================================
-
-Standard_Real BRepExtrema_ExtFF::SquareDistance
-  (const Standard_Integer N) const
-{
-  if(!myExtrem.IsDone()) StdFail_NotDone::Raise();
-  if ((N < 1) || (N > mynbext)) Standard_OutOfRange::Raise();
-  return mySqDist.Value(N);
-}
-
-//=======================================================================
-//function : ParameterOnFace1
-//purpose  : 
-//=======================================================================
-
-void BRepExtrema_ExtFF::ParameterOnFace1(const Standard_Integer N,
-                                         Standard_Real& U,
-                                         Standard_Real& V) const
-{
-  if(!myExtrem.IsDone()) StdFail_NotDone::Raise();
-  if ((N < 1) || (N > mynbext)) Standard_OutOfRange::Raise();
-  myPointsOnS1.Value(N).Parameter(U, V);
-}
-
-//=======================================================================
-//function : PointOnFace1
-//purpose  : 
-//=======================================================================
-
-gp_Pnt BRepExtrema_ExtFF::PointOnFace1
-  (const Standard_Integer N) const
-{
-  if(!myExtrem.IsDone()) StdFail_NotDone::Raise();
-  if ((N < 1) || (N > mynbext)) Standard_OutOfRange::Raise();
-  gp_Pnt P = myPointsOnS1.Value(N).Value();
-  return P; 
-}
-
-
-//=======================================================================
-//function : ParameterOnFace2
-//purpose  : 
-//=======================================================================
-
-void BRepExtrema_ExtFF::ParameterOnFace2(const Standard_Integer N,
-                                         Standard_Real& U,
-                                         Standard_Real& V) const
-{
-  if(!myExtrem.IsDone()) StdFail_NotDone::Raise();
-  if ((N < 1) || (N > mynbext)) Standard_OutOfRange::Raise();
-  myPointsOnS2.Value(N).Parameter(U, V);
-}
-
-//=======================================================================
-//function : PointOnFace1
-//purpose  : 
-//=======================================================================
-
-gp_Pnt BRepExtrema_ExtFF::PointOnFace2
-  (const Standard_Integer N) const
-{
-  if(!myExtrem.IsDone()) StdFail_NotDone::Raise();
-  if ((N < 1) || (N > mynbext)) Standard_OutOfRange::Raise();
-  gp_Pnt P = myPointsOnS2.Value(N).Value();
-  return P; 
-}
-
-
diff --git a/src/BRepExtrema/BRepExtrema_ExtFF.hxx b/src/BRepExtrema/BRepExtrema_ExtFF.hxx
new file mode 100644 (file)
index 0000000..9e2035e
--- /dev/null
@@ -0,0 +1,124 @@
+// This file is generated by WOK (CPPExt).
+// Please do not edit this file; modify original file instead.
+// The copyright and license terms as defined for the original file apply to 
+// this header file considered to be the "object code" form of the original source.
+
+#ifndef _BRepExtrema_ExtFF_HeaderFile
+#define _BRepExtrema_ExtFF_HeaderFile
+
+#ifndef _Standard_HeaderFile
+#include <Standard.hxx>
+#endif
+#ifndef _Standard_Macro_HeaderFile
+#include <Standard_Macro.hxx>
+#endif
+
+#ifndef _Extrema_ExtSS_HeaderFile
+#include <Extrema_ExtSS.hxx>
+#endif
+#ifndef _Standard_Integer_HeaderFile
+#include <Standard_Integer.hxx>
+#endif
+#ifndef _TColStd_SequenceOfReal_HeaderFile
+#include <TColStd_SequenceOfReal.hxx>
+#endif
+#ifndef _Extrema_SequenceOfPOnSurf_HeaderFile
+#include <Extrema_SequenceOfPOnSurf.hxx>
+#endif
+#ifndef _Handle_BRepAdaptor_HSurface_HeaderFile
+#include <Handle_BRepAdaptor_HSurface.hxx>
+#endif
+#ifndef _Standard_Boolean_HeaderFile
+#include <Standard_Boolean.hxx>
+#endif
+#ifndef _Standard_Real_HeaderFile
+#include <Standard_Real.hxx>
+#endif
+#ifndef _Extrema_POnSurf_HeaderFile
+#include <Extrema_POnSurf.hxx>
+#endif
+class BRepAdaptor_HSurface;
+class TopoDS_Face;
+class gp_Pnt;
+
+
+
+class BRepExtrema_ExtFF
+{
+ public:
+
+  void* operator new(size_t,void* anAddress) 
+  {
+    return anAddress;
+  }
+  void* operator new(size_t size) 
+  {
+    return Standard::Allocate(size); 
+  }
+  void  operator delete(void *anAddress) 
+  {
+    if (anAddress) Standard::Free((Standard_Address&)anAddress); 
+  }
+
+  
+  Standard_EXPORT BRepExtrema_ExtFF()
+  {
+  }
+  //! It calculates all the distances. <br>
+  Standard_EXPORT BRepExtrema_ExtFF(const TopoDS_Face& F1,const TopoDS_Face& F2);
+  
+  Standard_EXPORT void Initialize(const TopoDS_Face& F2) ;
+  //! An exception is raised if the fields have not been initialized. <br>
+  //! Be careful: this method uses the Face F2 only for classify, not for the fields. <br>
+  Standard_EXPORT void Perform(const TopoDS_Face& F1,const TopoDS_Face& F2);
+  //! True if the distances are found. <br>
+  Standard_EXPORT Standard_Boolean IsDone() const
+  {
+    return myExtSS.IsDone();
+  }
+  //! Returns True if the surfaces are parallel. <br>
+  Standard_EXPORT Standard_Boolean IsParallel() const
+  {
+    return myExtSS.IsParallel();
+  }
+  //! Returns the number of extremum distances. <br>
+  Standard_EXPORT Standard_Integer NbExt() const
+  {
+    return mySqDist.Length();
+  }
+  //! Returns the value of the <N>th extremum square distance. <br>
+  Standard_EXPORT Standard_Real SquareDistance(const Standard_Integer N) const
+  {
+    return mySqDist.Value(N);
+  }
+  //! Returns the parameters on the Face F1 of the <N>th extremum distance. <br>
+  Standard_EXPORT void ParameterOnFace1(const Standard_Integer N,Standard_Real& U,Standard_Real& V) const
+  {
+    myPointsOnS1.Value(N).Parameter(U, V);
+  }
+  //! Returns the parameters on the Face F2 of the <N>th extremum distance. <br>
+  Standard_EXPORT void ParameterOnFace2(const Standard_Integer N,Standard_Real& U,Standard_Real& V) const
+  {
+    myPointsOnS2.Value(N).Parameter(U, V);
+  }
+  //! Returns the Point of the <N>th extremum distance. <br>
+  Standard_EXPORT gp_Pnt PointOnFace1(const Standard_Integer N) const
+  {
+    return myPointsOnS1.Value(N).Value(); 
+  }
+  //! Returns the Point of the <N>th extremum distance. <br>
+  Standard_EXPORT gp_Pnt PointOnFace2(const Standard_Integer N) const
+  {
+    return myPointsOnS2.Value(N).Value();
+  }
+
+ private:
+
+  Extrema_ExtSS myExtSS;
+  TColStd_SequenceOfReal mySqDist;
+  Extrema_SequenceOfPOnSurf myPointsOnS1;
+  Extrema_SequenceOfPOnSurf myPointsOnS2;
+  Handle_BRepAdaptor_HSurface myHS;
+};
+
+#endif
index 2f4250f..6dbb59d 100755 (executable)
@@ -1,12 +1,12 @@
 // File:       BRepExtrema_ExtPC.cxx
 // Created:    Wed Dec 15 16:48:53 1993
 // Author:     Christophe MARION
-//             <cma@sdsun1>
 
-#include <BRepExtrema_ExtPC.ixx>
+#include <BRepExtrema_ExtPC.hxx>
+
 #include <BRep_Tool.hxx>
-#include <StdFail_NotDone.hxx>
-#include <Standard_Failure.hxx>
+//#include <StdFail_NotDone.hxx>
+//#include <Standard_Failure.hxx>
 #include <BRepAdaptor_Curve.hxx>
 #include <BRepAdaptor_HCurve.hxx>
 
 //purpose  : 
 //=======================================================================
 
-BRepExtrema_ExtPC::BRepExtrema_ExtPC()
-{
-}
-
-//=======================================================================
-//function : BRepExtrema_ExtPC
-//purpose  : 
-//=======================================================================
-
-BRepExtrema_ExtPC::BRepExtrema_ExtPC
-  (const TopoDS_Vertex& V,
-   const TopoDS_Edge& E)
+BRepExtrema_ExtPC::BRepExtrema_ExtPC(const TopoDS_Vertex& V, const TopoDS_Edge& E)
 {
   Initialize(E);
   Perform(V);
@@ -44,7 +33,7 @@ void BRepExtrema_ExtPC::Initialize(const TopoDS_Edge& E)
   BRepAdaptor_Curve Curv(E);
   myHC = new BRepAdaptor_HCurve(Curv);
   BRep_Tool::Range(E,U1,U2);
-  myExtrem.Initialize(myHC->Curve(),U1,U2);
+  myExtPC.Initialize(myHC->Curve(),U1,U2);
 }
 
 //=======================================================================
@@ -55,93 +44,5 @@ void BRepExtrema_ExtPC::Initialize(const TopoDS_Edge& E)
 void BRepExtrema_ExtPC::Perform(const TopoDS_Vertex& V)
 {
   gp_Pnt P = BRep_Tool::Pnt(V);
-  myExtrem.Perform(P);
-}
-
-//=======================================================================
-//function : IsDone
-//purpose  : 
-//=======================================================================
-
-Standard_Boolean BRepExtrema_ExtPC::IsDone()const
-{
-  return myExtrem.IsDone();
-}
-
-//=======================================================================
-//function : NbExt
-//purpose  : 
-//=======================================================================
-
-Standard_Integer BRepExtrema_ExtPC::NbExt() const
-{
-  if(!myExtrem.IsDone()) StdFail_NotDone::Raise();
-  return myExtrem.NbExt();
-}
-
-//=======================================================================
-//function : IsMin
-//purpose  : 
-//=======================================================================
-
-Standard_Boolean BRepExtrema_ExtPC::IsMin
-  (const Standard_Integer N) const
-{
-  if(!myExtrem.IsDone()) StdFail_NotDone::Raise();
-  if ((N < 1) || (N > myExtrem.NbExt())) Standard_OutOfRange::Raise();
-  return myExtrem.IsMin(N);
+  myExtPC.Perform(P);
 }
-
-//=======================================================================
-//function : Value
-//purpose  : 
-//=======================================================================
-
-Standard_Real BRepExtrema_ExtPC::SquareDistance
-  (const Standard_Integer N) const
-{
-  if(!myExtrem.IsDone()) StdFail_NotDone::Raise();
-  if ((N < 1) || (N > myExtrem.NbExt())) Standard_OutOfRange::Raise();
-  return myExtrem.SquareDistance(N);
-}
-
-//=======================================================================
-//function : Parameter
-//purpose  : 
-//=======================================================================
-
-Standard_Real BRepExtrema_ExtPC::Parameter
-  (const Standard_Integer N) const
-{
-  if(!myExtrem.IsDone()) StdFail_NotDone::Raise();
-  if ((N < 1) || (N > myExtrem.NbExt())) Standard_OutOfRange::Raise();
-  return myExtrem.Point(N).Parameter();
-}
-
-//=======================================================================
-//function : Point
-//purpose  : 
-//=======================================================================
-
-gp_Pnt BRepExtrema_ExtPC::Point
-  (const Standard_Integer N) const
-{
-  if(!myExtrem.IsDone()) StdFail_NotDone::Raise();
-  if ((N < 1) || (N > myExtrem.NbExt())) Standard_OutOfRange::Raise();
-  return (myExtrem.Point(N).Value()); 
-}
-
-//=======================================================================
-//function : TrimmedDistances
-//purpose  : 
-//=======================================================================
-
-void BRepExtrema_ExtPC::TrimmedSquareDistances
-  (Standard_Real& dist1,
-   Standard_Real& dist2,
-   gp_Pnt& pnt1,
-   gp_Pnt& pnt2) const
-{
-  myExtrem.TrimmedSquareDistances(dist1,dist2,pnt1,pnt2);
-}
-
diff --git a/src/BRepExtrema/BRepExtrema_ExtPC.hxx b/src/BRepExtrema/BRepExtrema_ExtPC.hxx
new file mode 100644 (file)
index 0000000..631d1ac
--- /dev/null
@@ -0,0 +1,110 @@
+// This file is generated by WOK (CPPExt).
+// Please do not edit this file; modify original file instead.
+// The copyright and license terms as defined for the original file apply to 
+// this header file considered to be the "object code" form of the original source.
+
+#ifndef _BRepExtrema_ExtPC_HeaderFile
+#define _BRepExtrema_ExtPC_HeaderFile
+
+#ifndef _Standard_HeaderFile
+#include <Standard.hxx>
+#endif
+#ifndef _Standard_Macro_HeaderFile
+#include <Standard_Macro.hxx>
+#endif
+
+#ifndef _Extrema_ExtPC_HeaderFile
+#include <Extrema_ExtPC.hxx>
+#endif
+#ifndef _Handle_BRepAdaptor_HCurve_HeaderFile
+#include <Handle_BRepAdaptor_HCurve.hxx>
+#endif
+#ifndef _Standard_Boolean_HeaderFile
+#include <Standard_Boolean.hxx>
+#endif
+#ifndef _Standard_Integer_HeaderFile
+#include <Standard_Integer.hxx>
+#endif
+#ifndef _Standard_Real_HeaderFile
+#include <Standard_Real.hxx>
+#endif
+class BRepAdaptor_HCurve;
+class TopoDS_Vertex;
+class TopoDS_Edge;
+class gp_Pnt;
+
+
+class BRepExtrema_ExtPC
+{
+ public:
+
+  void* operator new(size_t,void* anAddress) 
+  {
+    return anAddress;
+  }
+  void* operator new(size_t size) 
+  {
+    return Standard::Allocate(size); 
+  }
+  void  operator delete(void *anAddress) 
+  {
+    if (anAddress) Standard::Free((Standard_Address&)anAddress); 
+  }
+
+  
+  Standard_EXPORT BRepExtrema_ExtPC()
+  {
+  }
+  //! It calculates all the distances. <br>
+  Standard_EXPORT BRepExtrema_ExtPC(const TopoDS_Vertex& V,const TopoDS_Edge& E);
+  
+  Standard_EXPORT void Initialize(const TopoDS_Edge& E);
+  //! An exception is raised if the fields have not been initialized. <br>
+  Standard_EXPORT void Perform(const TopoDS_Vertex& V);
+  //! True if the distances are found. <br>
+  Standard_EXPORT Standard_Boolean IsDone() const
+  {
+    return myExtPC.IsDone();
+  }
+  //! Returns the number of extremum distances. <br>
+  Standard_EXPORT Standard_Integer NbExt() const
+  {
+    return myExtPC.NbExt();
+  }
+  //! Returns True if the <N>th extremum distance is a minimum. <br>
+  Standard_EXPORT Standard_Boolean IsMin(const Standard_Integer N) const
+  {
+    return myExtPC.IsMin(N);
+  }
+  //! Returns the value of the <N>th extremum square distance. <br>
+  Standard_EXPORT Standard_Real SquareDistance(const Standard_Integer N) const
+  {
+    return myExtPC.SquareDistance(N);
+  }
+  //! Returns the parameter on the edge of the <N>th extremum distance. <br>
+  Standard_EXPORT Standard_Real Parameter(const Standard_Integer N) const
+  {
+    return myExtPC.Point(N).Parameter();
+  }
+  //! Returns the Point of the <N>th extremum distance. <br>
+  Standard_EXPORT gp_Pnt Point(const Standard_Integer N) const
+  {
+    return myExtPC.Point(N).Value();
+  }
+  //! if the curve is a trimmed curve, <br>
+  //! dist1 is a square distance between <P> and the point <br>
+  //! of parameter FirstParameter <pnt1> and <br>
+  //! dist2 is a square distance between <P> and the point <br>
+  //! of parameter LastParameter <pnt2>. <br>
+  Standard_EXPORT void TrimmedSquareDistances(Standard_Real& dist1,Standard_Real& dist2,gp_Pnt& pnt1,gp_Pnt& pnt2) const
+  {
+    myExtPC.TrimmedSquareDistances(dist1,dist2,pnt1,pnt2);
+  }
+
+ private:
+
+  Extrema_ExtPC myExtPC;
+  Handle_BRepAdaptor_HCurve myHC;
+};
+
+#endif
index a30002c..ca3037c 100755 (executable)
@@ -1,41 +1,27 @@
 // File:       BRepExtrema_ExtPF.cxx
 // Created:    Wed Dec 15 16:48:53 1993
 // Author:     Christophe MARION
-//             <cma@sdsun1>
 // modified by MPS (june 96) : on utilise BRepClass_FaceClassifier seulement 
 //  si IsDone de Extrema est vrai  
-#include <BRepExtrema_ExtPF.ixx>
+
+#include <BRepExtrema_ExtPF.hxx>
+
 #include <BRep_Tool.hxx>
 #include <BRepTools.hxx>
-#include <StdFail_NotDone.hxx>
-#include <Standard_Failure.hxx>
 #include <BRepClass_FaceClassifier.hxx>
 #include <gp_Pnt2d.hxx>
-#include <BRepAdaptor_Curve.hxx>
-#include <BRepAdaptor_HCurve.hxx>
 #include <BRepAdaptor_Surface.hxx>
-#include <BRepAdaptor_HSurface.hxx>
-
-//=======================================================================
-//function : BRepExtrema_ExtPF
-//purpose  : 
-//=======================================================================
-
-BRepExtrema_ExtPF::BRepExtrema_ExtPF()
-{
-}
 
 //=======================================================================
 //function : BRepExtrema_ExtPF
 //purpose  : 
 //=======================================================================
 
-BRepExtrema_ExtPF::BRepExtrema_ExtPF
-  (const TopoDS_Vertex& V,
-   const TopoDS_Face&   E)
+BRepExtrema_ExtPF::BRepExtrema_ExtPF(const TopoDS_Vertex& TheVertex, const TopoDS_Face& TheFace,
+                                     const Extrema_ExtFlag TheFlag, const Extrema_ExtAlgo TheAlgo)
 {
-  Initialize(E);
-  Perform(V, E);
+  Initialize(TheFace,TheFlag,TheAlgo);
+  Perform(TheVertex,TheFace);
 }
 
 //=======================================================================
@@ -43,15 +29,18 @@ BRepExtrema_ExtPF::BRepExtrema_ExtPF
 //purpose  : 
 //=======================================================================
 
-void BRepExtrema_ExtPF::Initialize(const TopoDS_Face& F)
+void BRepExtrema_ExtPF::Initialize(const TopoDS_Face& TheFace,
+                                   const Extrema_ExtFlag TheFlag, const Extrema_ExtAlgo TheAlgo)
 {
   // cette surface doit etre en champ. Extrema ne fait
   // pas de copie et prend seulement un pointeur dessus.
-  mySurf.Initialize(F, Standard_False); 
-  Standard_Real Tol = BRep_Tool::Tolerance(F);
+  mySurf.Initialize(TheFace, Standard_False); 
+  const Standard_Real Tol = BRep_Tool::Tolerance(TheFace);
   Standard_Real U1, U2, V1, V2;
-  BRepTools::UVBounds(F, U1, U2, V1, V2);
-  myExtrem.Initialize(mySurf, U1, U2, V1, V2, Tol, Tol);
+  BRepTools::UVBounds(TheFace, U1, U2, V1, V2);
+  myExtPS.SetFlag(TheFlag);
+  myExtPS.SetAlgo(TheAlgo);
+  myExtPS.Initialize(mySurf, U1, U2, V1, V2, Tol, Tol);
 }
 
 //=======================================================================
@@ -59,95 +48,31 @@ void BRepExtrema_ExtPF::Initialize(const TopoDS_Face& F)
 //purpose  : 
 //=======================================================================
 
-void BRepExtrema_ExtPF::Perform(const TopoDS_Vertex& V,
-                               const TopoDS_Face&   E)
+void BRepExtrema_ExtPF::Perform(const TopoDS_Vertex& TheVertex, const TopoDS_Face& TheFace)
 {
   mySqDist.Clear();
   myPoints.Clear();
-  gp_Pnt P = BRep_Tool::Pnt(V);
-  myExtrem.Perform(P);
 
-  // exploration des points et classification:
-  if (myExtrem.IsDone()) {
-  BRepClass_FaceClassifier classifier;
-  gp_Pnt2d Puv;
-  Standard_Real U1, U2;
-  TopAbs_State state;
-  Standard_Real Tol = BRep_Tool::Tolerance(E);
-  mynbext = 0;
-  for (Standard_Integer i = 1; i <= myExtrem.NbExt(); i++) {
-    myExtrem.Point(i).Parameter(U1, U2);
-    Puv.SetCoord(U1, U2);
-    classifier.Perform(E, Puv, Tol);
-    state = classifier.State();
-    if(state == TopAbs_ON || state == TopAbs_IN) {
-      mynbext++;
-      mySqDist.Append(myExtrem.SquareDistance(i));
-      myPoints.Append(myExtrem.Point(i));
+  const gp_Pnt P = BRep_Tool::Pnt(TheVertex);
+  myExtPS.Perform(P);
+
+  // Exploration of points and classification
+  if (myExtPS.IsDone())
+  {
+    BRepClass_FaceClassifier classifier;
+    Standard_Real U1, U2;
+    const Standard_Real Tol = BRep_Tool::Tolerance(TheFace);
+    for (Standard_Integer i = 1; i <= myExtPS.NbExt(); i++)
+    {
+      myExtPS.Point(i).Parameter(U1, U2);
+      const gp_Pnt2d Puv(U1, U2);
+      classifier.Perform(TheFace, Puv, Tol);
+      const TopAbs_State state = classifier.State();
+      if(state == TopAbs_ON || state == TopAbs_IN)
+      {
+        mySqDist.Append(myExtPS.SquareDistance(i));
+        myPoints.Append(myExtPS.Point(i));
+      }
     }
   }
- }
-}
-//=======================================================================
-//function : IsDone
-//purpose  : 
-//=======================================================================
-
-Standard_Boolean BRepExtrema_ExtPF::IsDone()const
-{
-  return myExtrem.IsDone();
-}
-
-//=======================================================================
-//function : NbExt
-//purpose  : 
-//=======================================================================
-
-Standard_Integer BRepExtrema_ExtPF::NbExt() const
-{
-  if(!myExtrem.IsDone()) StdFail_NotDone::Raise();
-  return mynbext;
-}
-
-
-//=======================================================================
-//function : Value
-//purpose  : 
-//=======================================================================
-
-Standard_Real BRepExtrema_ExtPF::SquareDistance
-  (const Standard_Integer N) const
-{
-  if(!myExtrem.IsDone()) StdFail_NotDone::Raise();
-  if ((N < 1) || (N > mynbext)) Standard_OutOfRange::Raise();
-  return mySqDist.Value(N);
-}
-
-//=======================================================================
-//function : Parameters
-//purpose  : 
-//=======================================================================
-
-
-void BRepExtrema_ExtPF::Parameter(const Standard_Integer N,
-                                 Standard_Real& U,
-                                 Standard_Real& V) const
-{
-  if(!myExtrem.IsDone()) StdFail_NotDone::Raise();
-  if ((N < 1) || (N > mynbext)) Standard_OutOfRange::Raise();
-  myPoints.Value(N).Parameter(U, V);
-}
-
-//=======================================================================
-//function : Point
-//purpose  : 
-//=======================================================================
-
-gp_Pnt BRepExtrema_ExtPF::Point
-  (const Standard_Integer N) const
-{
-  if(!myExtrem.IsDone()) StdFail_NotDone::Raise();
-  if ((N < 1) || (N > mynbext)) Standard_OutOfRange::Raise();
-  gp_Pnt P = myPoints.Value(N).Value();
-  return P; 
 }
diff --git a/src/BRepExtrema/BRepExtrema_ExtPF.hxx b/src/BRepExtrema/BRepExtrema_ExtPF.hxx
new file mode 100644 (file)
index 0000000..6e8ac30
--- /dev/null
@@ -0,0 +1,139 @@
+// File generated by CPPExt (Value)
+//
+//                     Copyright (C) 1991 - 2000 by  
+//                      Matra Datavision SA.  All rights reserved.
+//  
+//                     Copyright (C) 2001 - 2004 by
+//                     Open CASCADE SA.  All rights reserved.
+// 
+// This file is part of the Open CASCADE Technology software.
+//
+// This software may be distributed and/or modified under the terms and
+// conditions of the Open CASCADE Public License as defined by Open CASCADE SA
+// and appearing in the file LICENSE included in the packaging of this file.
+//  
+// This software is distributed on an "AS IS" basis, without warranty of any
+// kind, and Open CASCADE SA hereby disclaims all such warranties,
+// including without limitation, any warranties of merchantability, fitness
+// for a particular purpose or non-infringement. Please see the License for
+// the specific terms and conditions governing rights and limitations under the
+// License.
+
+#ifndef _BRepExtrema_ExtPF_HeaderFile
+#define _BRepExtrema_ExtPF_HeaderFile
+
+#ifndef _Standard_HeaderFile
+#include <Standard.hxx>
+#endif
+#ifndef _Standard_Macro_HeaderFile
+#include <Standard_Macro.hxx>
+#endif
+
+#ifndef _Extrema_ExtPS_HeaderFile
+#include <Extrema_ExtPS.hxx>
+#endif
+#ifndef _Standard_Integer_HeaderFile
+#include <Standard_Integer.hxx>
+#endif
+#ifndef _TColStd_SequenceOfReal_HeaderFile
+#include <TColStd_SequenceOfReal.hxx>
+#endif
+#ifndef _Extrema_SequenceOfPOnSurf_HeaderFile
+#include <Extrema_SequenceOfPOnSurf.hxx>
+#endif
+#ifndef _BRepAdaptor_Surface_HeaderFile
+#include <BRepAdaptor_Surface.hxx>
+#endif
+#ifndef _Extrema_ExtFlag_HeaderFile
+#include <Extrema_ExtFlag.hxx>
+#endif
+#ifndef _Extrema_ExtAlgo_HeaderFile
+#include <Extrema_ExtAlgo.hxx>
+#endif
+#ifndef _Standard_Boolean_HeaderFile
+#include <Standard_Boolean.hxx>
+#endif
+#ifndef _Standard_Real_HeaderFile
+#include <Standard_Real.hxx>
+#endif
+class TopoDS_Vertex;
+class TopoDS_Face;
+class gp_Pnt;
+
+
+class BRepExtrema_ExtPF
+{
+ public:
+
+  void* operator new(size_t,void* anAddress) 
+  {
+    return anAddress;
+  }
+  void* operator new(size_t size) 
+  {
+    return Standard::Allocate(size); 
+  }
+  void  operator delete(void *anAddress) 
+  {
+    if (anAddress) Standard::Free((Standard_Address&)anAddress); 
+  }
+
+  Standard_EXPORT BRepExtrema_ExtPF()
+  {}
+  //! It calculates all the distances. <br>
+  Standard_EXPORT BRepExtrema_ExtPF(const TopoDS_Vertex& TheVertex,const TopoDS_Face& TheFace,
+                                    const Extrema_ExtFlag TheFlag = Extrema_ExtFlag_MINMAX,
+                                    const Extrema_ExtAlgo TheAlgo = Extrema_ExtAlgo_Grad);
+  
+  Standard_EXPORT void Initialize(const TopoDS_Face& TheFace,
+                                  const Extrema_ExtFlag TheFlag = Extrema_ExtFlag_MINMAX,
+                                  const Extrema_ExtAlgo TheAlgo = Extrema_ExtAlgo_Grad);
+
+  //! An exception is raised if the fields have not been initialized. <br>
+  //! Be careful: this method uses the Face only for classify not for the fields. <br>
+  Standard_EXPORT void Perform(const TopoDS_Vertex& TheVertex,const TopoDS_Face& TheFace);
+  //! True if the distances are found. <br>
+  Standard_EXPORT Standard_Boolean IsDone() const
+  {
+    return myExtPS.IsDone();
+  }
+  //! Returns the number of extremum distances. <br>
+  Standard_EXPORT Standard_Integer NbExt() const
+  {
+    return myPoints.Length();
+  }
+  //! Returns the value of the <N>th extremum square distance. <br>
+  Standard_EXPORT Standard_Real SquareDistance(const Standard_Integer N) const
+  {
+    return mySqDist.Value(N);
+  }
+  //! Returns the parameters on the Face of the <N>th extremum distance. <br>
+  Standard_EXPORT void Parameter(const Standard_Integer N,Standard_Real& U,Standard_Real& V) const
+  {
+    myPoints.Value(N).Parameter(U, V);
+  }
+  //! Returns the Point of the <N>th extremum distance. <br>
+  Standard_EXPORT gp_Pnt Point(const Standard_Integer N) const
+  {
+    return myPoints.Value(N).Value();
+  }
+
+  Standard_EXPORT void SetFlag(const Extrema_ExtFlag F)
+  {
+    myExtPS.SetFlag(F);
+  }
+
+  Standard_EXPORT void SetAlgo(const Extrema_ExtAlgo A)
+  {
+    myExtPS.SetAlgo(A);
+  }
+
+ private:
+
+  Extrema_ExtPS myExtPS;
+  TColStd_SequenceOfReal mySqDist;
+  Extrema_SequenceOfPOnSurf myPoints;
+  BRepAdaptor_Surface mySurf;
+};
+
+#endif
index bcaa14f..00d423c 100755 (executable)
@@ -1,9 +1,9 @@
 // File:       BRepExtrema_Poly.cxx
 // Created:    Fri Sep  8 11:03:14 1995
 // Author:     Christophe MARION
-//             <cma@ecolox>
 
-#include <BRepExtrema_Poly.ixx>
+#include <BRepExtrema_Poly.hxx>
+
 #include <BRep_Tool.hxx>
 #include <TopoDS_Face.hxx>
 #include <TopoDS.hxx>
 //purpose  : 
 //=======================================================================
 
-Standard_Boolean BRepExtrema_Poly::Distance (const TopoDS_Shape& S1,
-                                            const TopoDS_Shape& S2,
-                                            gp_Pnt& P1,
-                                            gp_Pnt& P2,
-                                            Standard_Real& dist)
+Standard_Boolean BRepExtrema_Poly::Distance (const TopoDS_Shape& S1, const TopoDS_Shape& S2,
+                                             gp_Pnt& P1, gp_Pnt& P2, Standard_Real& dist)
 {
-  Standard_Real dCur;
   dist = Precision::Infinite();
-  Standard_Integer i,i1,i2,n;
-  TopExp_Explorer exFace;
-  Handle(Poly_Triangulation) Tr;
+
   TopLoc_Location L;
-  Standard_Integer nbn1 = 0;
+  Handle(Poly_Triangulation) Tr;
+  TopExp_Explorer exFace;
 
+  Standard_Integer nbn1 = 0;
   for (exFace.Init(S1, TopAbs_FACE);
        exFace.More(); 
-       exFace.Next()) {
+       exFace.Next())
+  {
     const TopoDS_Face& F = TopoDS::Face(exFace.Current());
     Tr = BRep_Tool::Triangulation(F,L);
     if (!Tr.IsNull())
       nbn1 += Tr->NbNodes();
   }
+  if (nbn1 == 0) return Standard_False;
+
   Standard_Integer nbn2 = 0;
-      
   for (exFace.Init(S2, TopAbs_FACE);
        exFace.More(); 
-       exFace.Next()) {
+       exFace.Next())
+  {
     const TopoDS_Face& F = TopoDS::Face(exFace.Current());
     Tr = BRep_Tool::Triangulation(F,L);
     if (!Tr.IsNull())
       nbn2 += Tr->NbNodes();
   }
+  if (nbn2 == 0) return Standard_False;
 
-  if (nbn1 == 0 || nbn2 == 0) return Standard_False;
+  Standard_Integer i,n;
 
   TColgp_Array1OfPnt TP1(1,nbn1);
   nbn1 = 0;
   
   for (exFace.Init(S1, TopAbs_FACE);
        exFace.More(); 
-       exFace.Next()) {
+       exFace.Next())
+  {
     const TopoDS_Face& F = TopoDS::Face(exFace.Current());
     Tr = BRep_Tool::Triangulation(F,L);
-    if (!Tr.IsNull()) {
+    if (!Tr.IsNull())
+    {
       const TColgp_Array1OfPnt& Nod = Tr->Nodes();
       n = Tr->NbNodes();
-      
-      for (i = 1;i <= n; i++) {
-       nbn1++; 
-       TP1.SetValue(nbn1,Nod(i).Transformed(L));
+      for (i = 1; i <= n; i++)
+      {
+        nbn1++; 
+        TP1.SetValue(nbn1,Nod(i).Transformed(L));
       }
     }
   }
@@ -76,34 +78,37 @@ Standard_Boolean BRepExtrema_Poly::Distance (const TopoDS_Shape& S1,
   
   for (exFace.Init(S2, TopAbs_FACE);
        exFace.More(); 
-       exFace.Next()) {
+       exFace.Next())
+  {
     const TopoDS_Face& F = TopoDS::Face(exFace.Current());
     Tr = BRep_Tool::Triangulation(F,L);
-    if (!Tr.IsNull()) {
+    if (!Tr.IsNull())
+    {
       const TColgp_Array1OfPnt& Nod = Tr->Nodes();
       n = Tr->NbNodes();
-      
-      for (i = 1;i <= n; i++) {
-       nbn2++; 
-       TP2.SetValue(nbn2,Nod(i).Transformed(L));
+      for (i = 1; i <= n; i++)
+      {
+        nbn2++; 
+        TP2.SetValue(nbn2,Nod(i).Transformed(L));
       }
     }
   }
-  
-  for (i1 = 1; i1 <= nbn1; i1++) {
-    gp_Pnt& PP1 = TP1(i1);
-    
-    for (i2 = 1; i2 <= nbn2; i2++) {
-      gp_Pnt& PP2 = TP2(i2);
-      
-      dCur = PP1.Distance(PP2);
-      if (dist > dCur) {
-       P1 = PP1;
-       P2 = PP2;
-       dist = dCur;
+
+  Standard_Integer i1,i2;
+  for (i1 = 1; i1 <= nbn1; i1++)
+  {
+    const gp_Pnt& PP1 = TP1(i1);
+    for (i2 = 1; i2 <= nbn2; i2++)
+    {
+      const gp_Pnt& PP2 = TP2(i2);
+      const Standard_Real dCur = PP1.Distance(PP2);
+      if (dist > dCur)
+      {
+        P1 = PP1;
+        P2 = PP2;
+        dist = dCur;
       }
     }
   }
   return Standard_True;
 }
-
diff --git a/src/BRepExtrema/BRepExtrema_Poly.hxx b/src/BRepExtrema/BRepExtrema_Poly.hxx
new file mode 100644 (file)
index 0000000..41095ab
--- /dev/null
@@ -0,0 +1,34 @@
+// This file is generated by WOK (CPPExt).
+// Please do not edit this file; modify original file instead.
+// The copyright and license terms as defined for the original file apply to 
+// this header file considered to be the "object code" form of the original source.
+
+#ifndef _BRepExtrema_Poly_HeaderFile
+#define _BRepExtrema_Poly_HeaderFile
+
+#ifndef _Standard_HeaderFile
+#include <Standard.hxx>
+#endif
+#ifndef _Standard_Macro_HeaderFile
+#include <Standard_Macro.hxx>
+#endif
+
+#ifndef _Standard_Boolean_HeaderFile
+#include <Standard_Boolean.hxx>
+#endif
+#ifndef _Standard_Real_HeaderFile
+#include <Standard_Real.hxx>
+#endif
+class TopoDS_Shape;
+class gp_Pnt;
+
+
+class BRepExtrema_Poly
+{
+ public:
+
+  //! returns Standard_True if OK. <br>
+  Standard_EXPORT static Standard_Boolean Distance(const TopoDS_Shape& S1,const TopoDS_Shape& S2,gp_Pnt& P1,gp_Pnt& P2,Standard_Real& dist);
+};
+
+#endif
diff --git a/src/BRepExtrema/BRepExtrema_SeqOfSolution.hxx b/src/BRepExtrema/BRepExtrema_SeqOfSolution.hxx
new file mode 100644 (file)
index 0000000..3c07a20
--- /dev/null
@@ -0,0 +1,18 @@
+// This file is generated by WOK (CPPExt).
+// Please do not edit this file; modify original file instead.
+// The copyright and license terms as defined for the original file apply to 
+// this header file considered to be the "object code" form of the original source.
+
+#ifndef _BRepExtrema_SeqOfSolution_HeaderFile
+#define _BRepExtrema_SeqOfSolution_HeaderFile
+
+#ifndef _NCollection_Sequence_HeaderFile
+#include <NCollection_Sequence.hxx>
+#endif
+#ifndef _BRepExtrema_SolutionElem_HeaderFile
+#include <BRepExtrema_SolutionElem.hxx>
+#endif
+
+typedef NCollection_Sequence<BRepExtrema_SolutionElem> BRepExtrema_SeqOfSolution;
+
+#endif
diff --git a/src/BRepExtrema/BRepExtrema_SolutionElem.hxx b/src/BRepExtrema/BRepExtrema_SolutionElem.hxx
new file mode 100644 (file)
index 0000000..1bf1a19
--- /dev/null
@@ -0,0 +1,156 @@
+// This file is generated by WOK (CPPExt).
+// Please do not edit this file; modify original file instead.
+// The copyright and license terms as defined for the original file apply to 
+// this header file considered to be the "object code" form of the original source.
+
+#ifndef _BRepExtrema_SolutionElem_HeaderFile
+#define _BRepExtrema_SolutionElem_HeaderFile
+
+#ifndef _Standard_HeaderFile
+#include <Standard.hxx>
+#endif
+#ifndef _Standard_Macro_HeaderFile
+#include <Standard_Macro.hxx>
+#endif
+
+#ifndef _Standard_Real_HeaderFile
+#include <Standard_Real.hxx>
+#endif
+#ifndef _gp_Pnt_HeaderFile
+#include <gp_Pnt.hxx>
+#endif
+#ifndef _BRepExtrema_SupportType_HeaderFile
+#include <BRepExtrema_SupportType.hxx>
+#endif
+#ifndef _TopoDS_Vertex_HeaderFile
+#include <TopoDS_Vertex.hxx>
+#endif
+#ifndef _TopoDS_Edge_HeaderFile
+#include <TopoDS_Edge.hxx>
+#endif
+#ifndef _TopoDS_Face_HeaderFile
+#include <TopoDS_Face.hxx>
+#endif
+class gp_Pnt;
+class TopoDS_Vertex;
+class TopoDS_Edge;
+class TopoDS_Face;
+
+
+//! This class is used to store information relative to the <br>
+//! minimum distance between two shapes. <br>
+class BRepExtrema_SolutionElem
+{
+ public:
+
+  void* operator new(size_t,void* anAddress) 
+  {
+    return anAddress;
+  }
+  void* operator new(size_t size) 
+  {
+    return Standard::Allocate(size); 
+  }
+  void  operator delete(void *anAddress) 
+  {
+    if (anAddress) Standard::Free((Standard_Address&)anAddress); 
+  }
+
+  
+  Standard_EXPORT BRepExtrema_SolutionElem()
+  : myDist(0.), myPoint(0.,0.,0.), mySupType(BRepExtrema_IsVertex), myPar1(0.), myPar2(0.)
+  {
+  }
+  //! initialisation of the fields <br>
+  //! This constructor is used when the solution of a distance is a Vertex. <br>
+  //! The different initialized fields are: <br>
+  //!            _ the distance d <br>
+  //!            _ the solution point <br>
+  //!            _ the type of solution <br>
+  //!            _ and the Vertex. <br>
+  Standard_EXPORT BRepExtrema_SolutionElem(const Standard_Real d,const gp_Pnt& Pt,const BRepExtrema_SupportType SolType,const TopoDS_Vertex& vertex)
+  : myDist(d), myPoint(Pt), mySupType(SolType), myVertex(vertex), myPar1(0.), myPar2(0.)
+  {
+  }
+  //! initialisation of  the fiels. <br>
+  //! This constructor is used when the  solution of distance is on an Edge. <br>
+  //! The different initialized fields are: <br>
+  //!            _ the distance d, <br>
+  //!            _ the solution point, <br>
+  //!            _ the type of solution, <br>
+  //!            _ the Edge, <br>
+  //!            _ and the parameter t to locate the solution. <br>
+  Standard_EXPORT BRepExtrema_SolutionElem(const Standard_Real d,const gp_Pnt& Pt,const BRepExtrema_SupportType SolType,const TopoDS_Edge& edge,const Standard_Real t)
+  : myDist(d), myPoint(Pt), mySupType(SolType), myEdge(edge), myPar1(t), myPar2(0.)
+  {
+  }
+  //! initialisation of the fields <br>
+  //! This constructor is used when the  solution of distance is in <br>
+  //! a Face. The different initialized fields are: <br>
+  //!            _ the distance d, <br>
+  //!            _ the solution point, <br>
+  //!            _ the type of solution, <br>
+  //!            _ the Face, <br>
+  //!            _ and the parameter u et v to locate the solution. <br>
+  Standard_EXPORT BRepExtrema_SolutionElem(const Standard_Real d,const gp_Pnt& Pt,const BRepExtrema_SupportType SolType,const TopoDS_Face& face,const Standard_Real u,const Standard_Real v)
+  : myDist(d), myPoint(Pt), mySupType(SolType), myFace(face), myPar1(u), myPar2(v)
+  {
+  }
+  //! returns the value of the minimum distance. <br>
+  Standard_EXPORT Standard_Real Dist() const
+  {
+    return myDist;
+  }
+  //! returns the solution point. <br>
+  Standard_EXPORT const gp_Pnt & Point() const
+  {
+    return myPoint;
+  }
+  //! returns the Support type : <br>
+  //!      IsVertex => The solution is a vertex. <br>
+  //!      IsOnEdge => The solution belongs to an Edge. <br>
+  //!      IsInFace => The solution is inside a Face. <br>
+  Standard_EXPORT BRepExtrema_SupportType SupportKind() const
+  {
+    return mySupType;
+  }
+  //! returns the vertex if the solution is a Vertex. <br>
+  Standard_EXPORT const TopoDS_Vertex & Vertex() const
+  {
+    return myVertex;
+  }
+  //! returns the vertex if the solution is an Edge. <br>
+  Standard_EXPORT const TopoDS_Edge & Edge() const
+  {
+    return myEdge;
+  }
+  //! returns the vertex if the solution is an Face. <br>
+  Standard_EXPORT const TopoDS_Face & Face() const
+  {
+    return myFace;
+  }
+  //! returns the parameter t if the solution is on Edge. <br>
+  Standard_EXPORT void EdgeParameter(Standard_Real& par1) const
+  {
+    par1 = myPar1;
+  }
+  //! returns the parameters u et v if the solution is in a Face. <br>
+  Standard_EXPORT void FaceParameter(Standard_Real& par1,Standard_Real& par2) const
+  {
+    par1 = myPar1;
+    par2 = myPar2;
+  }
+
+ private:
+
+  Standard_Real myDist;
+  gp_Pnt myPoint;
+  BRepExtrema_SupportType mySupType;
+  TopoDS_Vertex myVertex;
+  TopoDS_Edge myEdge;
+  TopoDS_Face myFace;
+  Standard_Real myPar1;
+  Standard_Real myPar2;
+};
+
+#endif
diff --git a/src/BRepExtrema/BRepExtrema_SupportType.hxx b/src/BRepExtrema/BRepExtrema_SupportType.hxx
new file mode 100644 (file)
index 0000000..a3d03e6
--- /dev/null
@@ -0,0 +1,20 @@
+// This file is generated by WOK (CPPExt).
+// Please do not edit this file; modify original file instead.
+// The copyright and license terms as defined for the original file apply to 
+// this header file considered to be the "object code" form of the original source.
+
+#ifndef _BRepExtrema_SupportType_HeaderFile
+#define _BRepExtrema_SupportType_HeaderFile
+
+enum BRepExtrema_SupportType
+{
+  BRepExtrema_IsVertex,
+  BRepExtrema_IsOnEdge,
+  BRepExtrema_IsInFace
+};
+
+#ifndef _Standard_PrimitiveTypes_HeaderFile
+#include <Standard_PrimitiveTypes.hxx>
+#endif
+
+#endif
diff --git a/src/BRepExtrema/FILES b/src/BRepExtrema/FILES
new file mode 100644 (file)
index 0000000..87b4ece
--- /dev/null
@@ -0,0 +1,19 @@
+BRepExtrema_DistanceSS.hxx
+BRepExtrema_DistanceSS.cxx
+BRepExtrema_DistShapeShape.hxx
+BRepExtrema_DistShapeShape.cxx
+BRepExtrema_ExtCC.hxx
+BRepExtrema_ExtCC.cxx
+BRepExtrema_ExtCF.hxx
+BRepExtrema_ExtCF.cxx
+BRepExtrema_ExtFF.hxx
+BRepExtrema_ExtFF.cxx
+BRepExtrema_ExtPC.hxx
+BRepExtrema_ExtPC.cxx
+BRepExtrema_ExtPF.hxx
+BRepExtrema_ExtPF.cxx
+BRepExtrema_Poly.hxx
+BRepExtrema_Poly.cxx
+BRepExtrema_SeqOfSolution.hxx
+BRepExtrema_SolutionElem.hxx
+BRepExtrema_SupportType.hxx
index a34e294..7b47348 100755 (executable)
@@ -47,7 +47,8 @@ package Bnd
 uses    Standard,
         TCollection,
         TColStd,
-        gp
+        gp,
+       MMgt
 
 
 is  class Box;
@@ -59,6 +60,13 @@ is  class Box;
                                    (Box from Bnd,
                                     Array1OfBox from Bnd);
 
+   class Sphere;
+   class Array1OfSphere instantiates Array1 from TCollection
+                                    (Sphere from Bnd);
+   class HArray1OfSphere instantiates HArray1 from TCollection
+                                     (Sphere from Bnd,
+                                     Array1OfSphere from Bnd);
+
 
     class Box2d;
         ---Purpose: A rectangle parallel to the main axes.
diff --git a/src/Bnd/Bnd_Sphere.cdl b/src/Bnd/Bnd_Sphere.cdl
new file mode 100644 (file)
index 0000000..15f2978
--- /dev/null
@@ -0,0 +1,86 @@
+-- File:      Bnd_Sphere.cdl
+-- Created:   Fri Dec 3 17:39:44 2010
+-- Author:    Artem SHAL
+---Copyright: OPEN CASCADE 2010
+
+class Sphere from Bnd
+
+    ---Purpose: This class represents a bounding sphere of a geometric entity
+    --          (triangle, segment of line or whatever else).
+
+uses XYZ from gp
+
+is
+
+    Create returns Sphere;
+           ---Purpose: Empty constructor
+
+    Create (theCntr : XYZ from gp; theRad : Real; theU : Integer; theV : Integer)
+           returns Sphere;
+           ---Purpose: Constructor of a definite sphere
+
+    U (me) returns Integer;
+        ---C++: inline
+        ---Purpose: Returns the U parameter on shape
+
+    V (me) returns Integer;
+        ---C++: inline
+        ---Purpose: Returns the V parameter on shape
+
+    IsValid (me) returns Boolean;
+        ---C++: inline
+           ---Purpose: Returns validity status, indicating that this
+           --          sphere corresponds to a real entity
+
+    SetValid (me : in out; isValid : Boolean);
+        ---C++: inline
+
+    Center (me) returns XYZ from gp;
+        ---C++: inline
+           ---C++: return const &
+           ---Purpose: Returns center of sphere object
+
+    Radius (me) returns Real;
+        ---C++: inline
+           ---Purpose: Returns the radius value
+
+    Distances (me; theXYZ : XYZ from gp; theMin : in out Real; theMax : in out Real) is static;
+           ---Purpose: Calculate and return minimal and maximal distance to sphere.
+           --          NOTE: This function is tightly optimized; any modifications
+           --          may affect performance!
+           
+    SquareDistances (me; theXYZ : XYZ from gp; theMin : in out Real; theMax : in out Real) is static;
+           ---Purpose: Calculate and return minimal and maximal distance to sphere.
+           --          NOTE: This function is tightly optimized; any modifications
+           --          may affect performance!
+
+    Project (me; theNode : XYZ from gp; theProjNode : in out XYZ from gp; theDist : in out Real; theInside : in out Boolean)
+           ---Purpose: Projects a point on entity.
+           --             Returns true if success
+           returns Boolean;
+
+    Distance (me; theNode : XYZ from gp)
+           returns Real;
+           
+    SquareDistance (me; theNode : XYZ from gp)
+           returns Real;
+
+    Add (me : in out; theOther : Sphere from Bnd);
+
+    IsOut (me; theOther : Sphere from Bnd)
+           returns Boolean;
+
+    IsOut (me; thePnt : XYZ from gp; theMaxDist : in out Real)
+           returns Boolean;
+
+    SquareExtent (me) returns Real;
+
+fields
+
+    myCenter   : XYZ from gp;
+    myRadius   : Real;
+    myIsValid  : Boolean;
+    myU                : Integer;
+    myV                : Integer;
+
+end Sphere;
diff --git a/src/Bnd/Bnd_Sphere.cxx b/src/Bnd/Bnd_Sphere.cxx
new file mode 100644 (file)
index 0000000..5217d48
--- /dev/null
@@ -0,0 +1,102 @@
+#include <Bnd_Sphere.hxx>
+
+Bnd_Sphere::Bnd_Sphere()
+  : myCenter (0., 0., 0.),
+    myRadius (0.),
+    myIsValid (Standard_False),
+    myU (0),
+    myV (0)
+{}
+
+Bnd_Sphere::Bnd_Sphere( const gp_XYZ& theCenter, const Standard_Real theRadius,
+                        const Standard_Integer theU, const Standard_Integer theV )
+  : myCenter (theCenter),
+    myRadius (theRadius),
+    myIsValid (Standard_False),
+    myU (theU),
+    myV (theV)
+{}
+
+void Bnd_Sphere::SquareDistances( const gp_XYZ& theXYZ,
+                                  Standard_Real& theMin, Standard_Real& theMax ) const
+{
+  theMax = ( theXYZ - myCenter ).SquareModulus();
+  theMin = ( theMax - myRadius <0 ? 0.0 : theMax - myRadius * myRadius );
+  theMax += myRadius * myRadius;
+}
+
+void Bnd_Sphere::Distances( const gp_XYZ& theXYZ,
+                            Standard_Real& theMin, Standard_Real& theMax ) const
+{
+  theMax = ( theXYZ - myCenter ).Modulus();
+  theMin = ( theMax - myRadius <0 ? 0.0 : theMax - myRadius );
+  theMax += myRadius;
+}
+
+Standard_Boolean Bnd_Sphere::Project(const gp_XYZ& theNode, gp_XYZ& theProjNode, Standard_Real& theDist, Standard_Boolean& theInside) const
+{ 
+  theProjNode = myCenter;
+  theDist = ( theNode - theProjNode ).Modulus();
+  theInside = Standard_True;
+  return Standard_True;
+}
+
+Standard_Real Bnd_Sphere::Distance(const gp_XYZ& theNode) const
+{
+  return ( theNode - myCenter ).Modulus();
+}
+
+Standard_Real Bnd_Sphere::SquareDistance(const gp_XYZ& theNode) const
+{
+  return ( theNode - myCenter ).SquareModulus();
+}
+
+void Bnd_Sphere::Add( const Bnd_Sphere& theOther)
+{
+  if ( myRadius < 0.0 )
+  {
+    // not initialised yet
+    *this = theOther;
+    return;
+  }
+
+  const Standard_Real aDist = (myCenter - theOther.myCenter).Modulus();
+  if ( myRadius + aDist <= theOther.myRadius )
+  {
+    // the other sphere is larger and encloses this
+    *this = theOther;
+    return;
+  }
+
+  if ( theOther.myRadius + aDist <= myRadius )
+    return; // this sphere encloses other
+
+  // expansion
+  const Standard_Real dfR = ( aDist + myRadius + theOther.myRadius ) * 0.5;
+  const Standard_Real aParamOnDiam = ( dfR - myRadius ) / aDist;
+  myCenter = myCenter * ( 1.0 - aParamOnDiam ) + theOther.myCenter * aParamOnDiam;
+  myRadius = dfR;
+  myIsValid = Standard_False;
+}
+
+Standard_Boolean Bnd_Sphere::IsOut( const Bnd_Sphere& theOther ) const
+{ 
+  return (myCenter - theOther.myCenter).SquareModulus() > (myRadius + theOther.myRadius) * (myRadius + theOther.myRadius); 
+}
+
+Standard_Boolean Bnd_Sphere::IsOut( const gp_XYZ& theXYZ,
+                                    Standard_Real& theMaxDist) const
+{
+  Standard_Real aCurMinDist, aCurMaxDist;
+  Distances( theXYZ, aCurMinDist, aCurMaxDist );
+  if ( aCurMinDist > theMaxDist )
+    return Standard_True;
+  if( myIsValid && aCurMaxDist < theMaxDist )
+    theMaxDist = aCurMaxDist;
+  return Standard_False;
+}
+
+Standard_Real Bnd_Sphere::SquareExtent() const
+{ 
+  return 4 * myRadius * myRadius; 
+}
diff --git a/src/Bnd/Bnd_Sphere.lxx b/src/Bnd/Bnd_Sphere.lxx
new file mode 100644 (file)
index 0000000..5e48d30
--- /dev/null
@@ -0,0 +1,30 @@
+
+inline Standard_Integer Bnd_Sphere::U() const
+{
+  return myU;
+}
+
+inline Standard_Integer Bnd_Sphere::V() const
+{
+  return myV;
+}
+
+inline Standard_Boolean Bnd_Sphere::IsValid() const
+{
+  return myIsValid;
+}
+
+inline void Bnd_Sphere::SetValid(const Standard_Boolean isValid)
+{
+  myIsValid = isValid;
+}
+
+inline const gp_XYZ& Bnd_Sphere::Center() const
+{ 
+  return myCenter; 
+}
+
+inline Standard_Real Bnd_Sphere::Radius() const
+{ 
+  return myRadius; 
+}
index b2356f6..7739714 100755 (executable)
@@ -30,10 +30,15 @@ uses
     Adaptor3d,
     Adaptor2d,
     Geom,
-    Geom2d
+    Geom2d,
+       Bnd
 
 is
 
+    enumeration ExtFlag is ExtFlag_MIN, ExtFlag_MAX, ExtFlag_MINMAX;
+
+    enumeration ExtAlgo is ExtAlgo_Grad, ExtAlgo_Tree;
+
     class CurveTool;
     class Curve2dTool;
 
@@ -70,6 +75,7 @@ is
     private class FuncExtPS;
     class GenExtPS;
     class GenLocateExtPS; 
+    imported HUBTreeOfSphere;
     
     ----------------------------------------------
     --  generic classes for  CURVE-CURVE extremas:
index 4db7c28..d56de03 100755 (executable)
@@ -20,7 +20,9 @@ uses
     SequenceOfReal    from TColStd,
     Surface           from Adaptor3d,
     SurfacePtr        from Adaptor3d,
-    GenExtPS          from Extrema
+    GenExtPS          from Extrema,
+    ExtFlag                      from Extrema,
+    ExtAlgo                      from Extrema
 --    ExtPExtS from Extrema,
 --    ExtPRevS from Extrema
 
@@ -35,7 +37,9 @@ is
     Create returns ExtPS;
 
 
-    Create (P: Pnt from gp; S: Surface from Adaptor3d; TolU,TolV: Real)
+    Create (P: Pnt from gp; S: Surface from Adaptor3d; TolU,TolV: Real; 
+                       F : ExtFlag from Extrema = Extrema_ExtFlag_MINMAX; 
+                       A : ExtAlgo from Extrema = Extrema_ExtAlgo_Grad)
        returns ExtPS;
        ---Purpose: It calculates all the distances.
        --          NbU and NbV are used to locate the close points
@@ -48,7 +52,9 @@ is
     
     Create (P: Pnt from gp; S: Surface from Adaptor3d;
            Uinf, Usup, Vinf, Vsup: Real;
-           TolU,TolV: Real)
+           TolU,TolV: Real; 
+           F : ExtFlag from Extrema = Extrema_ExtFlag_MINMAX; 
+           A : ExtAlgo from Extrema = Extrema_ExtAlgo_Grad)
        returns ExtPS;
        ---Purpose: It calculates all the distances.
        --          NbU and NbV are used to locate the close points
@@ -114,6 +120,12 @@ is
        --          dUlVl is a square distance between <P> and the point
        --          of parameter LastUParameter and LastVParameter <PUlVl>.
     is static;
+    
+    SetFlag(me : in out; F : ExtFlag from Extrema)
+       is static;
+       
+    SetAlgo(me : in out; A : ExtAlgo from Extrema)
+       is static;
 
 
     Bidon(me) returns SurfacePtr from Adaptor3d
index 015d599..290e5b6 100755 (executable)
@@ -52,6 +52,9 @@ static Standard_Boolean IsoIsDeg  (const Adaptor3d_Surface& S,
       if(Step < Precision::PConfusion()) {
         return Standard_False;
       }
+      if(Step < Precision::PConfusion()) {
+        return Standard_False;
+      }
       D1NormMax=0.;
       for (T=U1;T<=U2;T=T+Step) 
       {
@@ -68,6 +71,9 @@ static Standard_Boolean IsoIsDeg  (const Adaptor3d_Surface& S,
       if(Step < Precision::PConfusion()) {
         return Standard_False;
       }
+      if(Step < Precision::PConfusion()) {
+        return Standard_False;
+      }
       D1NormMax=0.;
       for (T=V1;T<=V2;T=T+Step) 
       {
@@ -126,9 +132,13 @@ Extrema_ExtPS::Extrema_ExtPS()
 Extrema_ExtPS::Extrema_ExtPS(const gp_Pnt&          P,
                             const Adaptor3d_Surface& S,
                             const Standard_Real    TolU,
-                            const Standard_Real    TolV)
+                            const Standard_Real    TolV,
+           const Extrema_ExtFlag F,
+           const Extrema_ExtAlgo A)
 
 {
+  myExtPS.SetFlag(F);
+  myExtPS.SetAlgo(A);
   Initialize(S, S.FirstUParameter(), S.LastUParameter(), 
                S.FirstVParameter(), S.LastVParameter(), 
                TolU, TolV);
@@ -147,9 +157,13 @@ Extrema_ExtPS::Extrema_ExtPS(const gp_Pnt&          P,
                             const Standard_Real    Vinf,       
                             const Standard_Real    Vsup,
                             const Standard_Real    TolU,
-                            const Standard_Real    TolV)
+                            const Standard_Real    TolV,
+           const Extrema_ExtFlag F,
+           const Extrema_ExtAlgo A)
 
 {
+  myExtPS.SetFlag(F);
+  myExtPS.SetAlgo(A);
   Initialize(S, Uinf, Usup, Vinf, Vsup, TolU, TolV);
   Perform(P);
 }
@@ -336,3 +350,13 @@ void Extrema_ExtPS::TrimmedSquareDistances(Standard_Real& dUfVf,
   PUlVf = P21;
   PUlVl = P22;
 }
+
+void Extrema_ExtPS::SetFlag(const Extrema_ExtFlag F)
+{
+  myExtPS.SetFlag(F);
+}
+
+void Extrema_ExtPS::SetAlgo(const Extrema_ExtAlgo A)
+{
+  myExtPS.SetAlgo(A);
+}
\ No newline at end of file
index fa3b101..fcf936e 100755 (executable)
@@ -13,10 +13,15 @@ class   GenExtPS from Extrema
 
 uses   POnSurf       from Extrema,
        Pnt           from gp,
-       HArray2OfPnt  from TColgp,
        FuncExtPS     from Extrema,
        Surface       from Adaptor3d,
-       SurfacePtr    from Adaptor3d
+       SurfacePtr    from Adaptor3d,
+        HUBTreeOfSphere from Extrema,
+        ExtFlag from Extrema,
+       ExtAlgo from Extrema,
+       HArray1OfSphere from Bnd,
+       Vector        from math,
+       HArray2OfPnt from TColgp
 
 raises  NotDone      from StdFail,
        OutOfRange   from Standard,
@@ -27,7 +32,7 @@ is
 
     Create returns GenExtPS;
     
-    Create (P: Pnt; S: Surface from Adaptor3d; NbU,NbV: Integer; TolU,TolV: Real)
+    Create (P: Pnt; S: Surface from Adaptor3d; NbU,NbV: Integer; TolU,TolV: Real; F : ExtFlag from Extrema = Extrema_ExtFlag_MINMAX; A : ExtAlgo from Extrema = Extrema_ExtAlgo_Grad)
        returns GenExtPS;
        ---Purpose: It calculates all the distances.
         --          The function F(u,v)=distance(P,S(u,v)) has an 
@@ -44,7 +49,7 @@ is
 
 
     Create (P: Pnt; S: Surface from Adaptor3d; NbU,NbV: Integer; 
-           Umin, Usup, Vmin, Vsup: Real; TolU,TolV: Real)
+           Umin, Usup, Vmin, Vsup: Real; TolU,TolV: Real; F : ExtFlag from Extrema = Extrema_ExtFlag_MINMAX; A : ExtAlgo from Extrema = Extrema_ExtAlgo_Grad)
        returns GenExtPS;
        ---Purpose: It calculates all the distances.
         --          The function F(u,v)=distance(P,S(u,v)) has an 
@@ -77,6 +82,12 @@ is
         --          been initialized.  
     raises TypeMismatch from Standard
     is static;
+    
+    SetFlag(me : in out; F : ExtFlag from Extrema)
+       is static;
+       
+    SetAlgo(me : in out; A : ExtAlgo from Extrema)
+       is static;
 
 
     IsDone (me) returns Boolean
@@ -107,6 +118,12 @@ is
 
     Bidon(me) returns SurfacePtr from Adaptor3d
     is static private;
+    
+    BuildTree(me : in out)
+    is static private;
+    
+    FindSolution(me: in out; P : Pnt from gp; UV : Vector from math; PasU, PasV : Real; f : ExtFlag from Extrema)
+    is static private;
 
 fields
     myDone    : Boolean;
@@ -117,10 +134,14 @@ fields
     myvsup    : Real;
     myusample : Integer;
     myvsample : Integer;
-    mypoints  : HArray2OfPnt from TColgp;
     mytolu    : Real;
     mytolv    : Real;
+    mypoints  : HArray2OfPnt from TColgp;
+    mySphereUBTree : HUBTreeOfSphere from Extrema;
+    mySphereArray : HArray1OfSphere from Bnd;
     myF              : FuncExtPS from Extrema;
     myS       : SurfacePtr from Adaptor3d;
+    myFlag    : ExtFlag from Extrema;
+    myAlgo    : ExtAlgo from Extrema;
 
 end GenExtPS;
index 06d3f1f..1a1b132 100755 (executable)
 #include <math_Vector.hxx>
 #include <math_NewtonFunctionSetRoot.hxx>
 #include <GeomAbs_IsoType.hxx>
+#include <Bnd_Sphere.hxx>
+#include <Extrema_HUBTreeOfSphere.hxx>
+#include <Extrema_ExtFlag.hxx>
+#include <Bnd_Array1OfSphere.hxx>
+#include <Bnd_HArray1OfSphere.hxx>
 
+//IMPLEMENT_HARRAY1(Extrema_HArray1OfSphere)
+
+
+class Bnd_SphereUBTreeSelector : public Extrema_UBTreeOfSphere::Selector
+{
+ public:
+
+  Bnd_SphereUBTreeSelector (const Handle(Bnd_HArray1OfSphere)& theSphereArray,
+Bnd_Sphere& theSol)
+    : myXYZ(0,0,0),
+      mySphereArray(theSphereArray),
+      mySol(theSol)
+  {
+    //myXYZ = gp_Pnt(0, 0, 0);    
+  }
+
+  void DefineCheckPoint( const gp_Pnt& theXYZ )
+  { myXYZ = theXYZ; }
+
+  Bnd_Sphere& Sphere() const
+  { return mySol; }
+
+  virtual Standard_Boolean Reject( const Bnd_Sphere &theBnd ) const = 0;
+  
+  virtual Standard_Boolean Accept(const Standard_Integer& theObj) = 0;
+
+ protected:
+  gp_Pnt                      myXYZ;
+  const Handle(Bnd_HArray1OfSphere)& mySphereArray;
+  Bnd_Sphere&                                           mySol;
+
+};
+
+class Bnd_SphereUBTreeSelectorMin : public Bnd_SphereUBTreeSelector
+{
+public:
+  Bnd_SphereUBTreeSelectorMin (const Handle(Bnd_HArray1OfSphere)& theSphereArray,
+               Bnd_Sphere& theSol)
+               : Bnd_SphereUBTreeSelector(theSphereArray, theSol),
+                 myMinDist(RealLast())
+  {}
+  
+  void SetMinDist( const Standard_Real theMinDist )
+  { myMinDist = theMinDist; }
+
+  Standard_Real MinDist() const
+  { return myMinDist; }
+
+  Standard_Boolean Reject( const Bnd_Sphere &theBnd ) const
+  { 
+    Bnd_SphereUBTreeSelectorMin* me =
+      const_cast<Bnd_SphereUBTreeSelectorMin*>(this);
+    // myMinDist is decreased each time a nearer object is found
+    return theBnd.IsOut( myXYZ.XYZ(), me->myMinDist );
+  }
+
+  Standard_Boolean Accept(const Standard_Integer&);
+
+private:
+       Standard_Real   myMinDist;
+};
+
+Standard_Boolean Bnd_SphereUBTreeSelectorMin::Accept(const Standard_Integer& theInd)
+{
+  const Bnd_Sphere& aSph = mySphereArray->Value(theInd);
+  Standard_Real aCurDist;
+
+    if ( (aCurDist = aSph.SquareDistance(myXYZ.XYZ())) < mySol.SquareDistance(myXYZ.XYZ()) )
+    {
+      mySol = aSph;
+      if ( aCurDist < myMinDist ) 
+        myMinDist = aCurDist;
+
+      return Standard_True;
+    }
+
+  return Standard_False;
+}
+
+class Bnd_SphereUBTreeSelectorMax : public Bnd_SphereUBTreeSelector
+{
+public:
+  Bnd_SphereUBTreeSelectorMax (const Handle(Bnd_HArray1OfSphere)& theSphereArray,
+               Bnd_Sphere& theSol)
+               : Bnd_SphereUBTreeSelector(theSphereArray, theSol),
+                 myMaxDist(0)
+  {}
+
+  void SetMaxDist( const Standard_Real theMaxDist )
+  { myMaxDist = theMaxDist; }
+
+  Standard_Real MaxDist() const
+  { return myMaxDist; }
+
+  Standard_Boolean Reject( const Bnd_Sphere &theBnd ) const
+  { 
+    Bnd_SphereUBTreeSelectorMax* me =
+      const_cast<Bnd_SphereUBTreeSelectorMax*>(this);
+    // myMaxDist is decreased each time a nearer object is found
+    return theBnd.IsOut( myXYZ.XYZ(), me->myMaxDist );
+  }
+
+  Standard_Boolean Accept(const Standard_Integer&);
+
+private:
+       Standard_Real   myMaxDist;
+};
+
+Standard_Boolean Bnd_SphereUBTreeSelectorMax::Accept(const Standard_Integer& theInd)
+{
+  const Bnd_Sphere& aSph = mySphereArray->Value(theInd);
+  Standard_Real aCurDist;
+
+    if ( (aCurDist = aSph.SquareDistance(myXYZ.XYZ())) > mySol.SquareDistance(myXYZ.XYZ()) )
+    {
+      mySol = aSph;
+      if ( aCurDist > myMaxDist ) 
+        myMaxDist = aCurDist;
+
+      return Standard_True;
+    }
+
+  return Standard_False;
+}
 
 
 
 //=============================================================================
 
 /*-----------------------------------------------------------------------------
-Fonction:
-   Recherche de toutes les distances extremales entre le point P et la surface
-  S a partir d'un echantillonnage (NbU,NbV).
+Function:
+   Find all extremum distances between point P and surface
+  S using sampling (NbU,NbV).
 
-Methode:
-   L'algorithme part de l'hypothese que l'echantillonnage est suffisamment fin
+Method:
+   The algorithm bases on the hypothesis that sampling is precise enough 
   pour que, s'il existe N distances extremales entre le point et la surface,
   alors il existe aussi N extrema entre le point et la grille.
-  Ainsi, l'algorithme consiste a partir des extrema de la grille pour trouver
-  les extrema de la surface.
-   Les extrema sont calcules par l'algorithme math_FunctionSetRoot avec les
-  arguments suivants:
-  - F: Extrema_FuncExtPS cree a partir de P et S,
-  - UV: math_Vector dont les composantes sont les parametres de l'extremum sur
-    la grille,
-  - Tol: Min(TolU,TolV), (Prov.:math_FunctionSetRoot n'autorise pas un vecteur)
-  - UVinf: math_Vector dont les composantes sont les bornes inferieures de u et
-    v,
-  - UVsup: math_Vector dont les composantes sont les bornes superieures de u et
-    v.
-
-Traitement:
-  a- Constitution du tableau des distances (TbDist(0,NbU+1,0,NbV+1)):
-      Le tableau est volontairement etendu; les lignes 0 et NbU+1 et les
-     colonnes 0 et NbV+1 seront initialisees a RealFirst() ou RealLast()
-     pour simplifier les tests effectues dans l'etape b
-     (on n'a pas besoin de tester si le point est sur un bord de la grille).
-  b- Calcul des extrema:
-      On recherche d'abord les minima et ensuite les maxima. Ces 2 traitements
-     se passent de facon similaire:
-  b.a- Initialisations:
-      - des 'bords' du tableau TbDist (a RealLast() dans le cas des minima
-        et a RealLast() dans le cas des maxima),
-      - du tableau TbSel(0,NbU+1,0,NbV+1) de selection des points pour un
-        calcul d'extremum local (a 0). Lorsqu'un point sera selectionne,
-       il ne sera plus selectionnable, ainsi que ses points adjacents
-       (8 au maximum). Les adresses correspondantes seront mises a 1.
-  b.b- Calcul des minima (ou maxima):
-       On boucle sur toutes les distances du tableau TbDist:
-      - recherche d'un minimum (ou maximum) sur la grille,
-      - calcul de l'extremum sur la surface,
-      - mise a jour du tableau TbSel.
+  So, the algorithm consists in starting from extrema of the grid to find the 
+  extrema of the surface.
+  The extrema are calculated by the algorithm math_FunctionSetRoot with the
+  following arguments:
+  - F: Extrema_FuncExtPS created from P and S,
+  - UV: math_Vector the components which of are parameters of the extremum on the 
+    grid,
+  - Tol: Min(TolU,TolV), (Prov.:math_FunctionSetRoot does not autorize a vector)
+  - UVinf: math_Vector the components which of are lower limits of u and v,
+  - UVsup: math_Vector the components which of are upper limits of u and v.
+
+Processing:
+  a- Creation of the table of distances (TbDist(0,NbU+1,0,NbV+1)):
+     The table is expanded at will; lines 0 and NbU+1 and
+     columns 0 and NbV+1 are initialized at RealFirst() or RealLast()
+     to simplify the tests carried out at stage b
+     (there is no need to test if the point is on border of the grid).
+  b- Calculation of extrema:
+     First the minimums and then the maximums are found. These 2 procedured 
+     pass in a similar way:
+  b.a- Initialization:
+      - 'borders' of table  TbDist (RealLast() in case of minimums
+        and  RealLast() in case of maximums),
+      - table TbSel(0,NbU+1,0,NbV+1) of selection of points for 
+        calculation of local extremum (0). When a point will selected,
+       it will not be selectable, as well as the ajacent points 
+       (8 at least). The corresponding addresses will be set to 1.
+  b.b- Calculation of minimums (or maximums):
+       All distances from table TbDist are parsed in a loop:
+      - search minimum (or maximum) in the grid,
+      - calculate extremum on the surface,
+      - update table TbSel.
 -----------------------------------------------------------------------------*/
 
 static Standard_Boolean IsoIsDeg  (const Adaptor3d_Surface& S,
@@ -117,6 +244,8 @@ Extrema_GenExtPS::Extrema_GenExtPS()
 {
   myDone = Standard_False;
   myInit = Standard_False;
+  myFlag = Extrema_ExtFlag_MINMAX;
+  myAlgo = Extrema_ExtAlgo_Grad;
 }
 
 
@@ -125,8 +254,10 @@ Extrema_GenExtPS::Extrema_GenExtPS (const gp_Pnt&          P,
                              const Standard_Integer NbU, 
                              const Standard_Integer NbV,
                              const Standard_Real    TolU, 
-                             const Standard_Real    TolV) 
-: myF (P,S)
+                              const Standard_Real    TolV,
+                              const Extrema_ExtFlag F,
+                              const Extrema_ExtAlgo A) 
+  : myF (P,S), myFlag(F), myAlgo(A)
 {
   Initialize(S, NbU, NbV, TolU, TolV);
   Perform(P);
@@ -141,8 +272,10 @@ Extrema_GenExtPS::Extrema_GenExtPS (const gp_Pnt&          P,
                              const Standard_Real    Vmin,
                              const Standard_Real    Vsup,
                              const Standard_Real    TolU, 
-                             const Standard_Real    TolV) 
-: myF (P,S)
+                              const Standard_Real    TolV,
+                              const Extrema_ExtFlag F,
+                              const Extrema_ExtAlgo A) 
+  : myF (P,S), myFlag(F), myAlgo(A)
 {
   Initialize(S, NbU, NbV, Umin, Usup, Vmin, Vsup, TolU, TolV);
   Perform(P);
@@ -189,15 +322,12 @@ void Extrema_GenExtPS::Initialize(const Adaptor3d_Surface& S,
 
   myF.Initialize(S);
 
-  mypoints = new TColgp_HArray2OfPnt(0,myusample+1,0,myvsample+1);
-
-/*
-a- Constitution du tableau des distances (TbDist(0,myusample+1,0,myvsample+1)):
-   ---------------------------------------------------------------
-*/
-
-// Parametrage de l echantillon
+  mySphereUBTree.Clear();
 
+  if(myAlgo == Extrema_ExtAlgo_Grad)
+  {
+         //If flag was changed and extrema not reinitialized Extrema would fail
+    mypoints = new TColgp_HArray2OfPnt(0,myusample+1,0,myvsample+1);
   Standard_Real PasU = myusup - myumin;
   Standard_Real PasV = myvsup - myvmin;
   Standard_Real U0 = PasU / myusample / 100.;
@@ -218,24 +348,168 @@ a- Constitution du tableau des distances (TbDist(0,myusample+1,0,myvsample+1)):
       mypoints->SetValue(NoU,NoV,P1);
     }
   }
+  }
+
+  //mypoints = new TColgp_HArray2OfPnt(0,myusample+1,0,myvsample+1);
+
+/*
+a- Constitution du tableau des distances (TbDist(0,myusample+1,0,myvsample+1)):
+   ---------------------------------------------------------------
+*/
+
+// Parametrage de l echantillon
+
+
 }
 
+void Extrema_GenExtPS::BuildTree()
+{
+       if(mySphereUBTree.IsEmpty())
+       {
+         Standard_Real PasU = myusup - myumin;
+         Standard_Real PasV = myvsup - myvmin;
+         Standard_Real U0 = PasU / myusample / 100.;
+         Standard_Real V0 = PasV / myvsample / 100.;
+         gp_Pnt P1;
+         PasU = (PasU - U0) / (myusample - 1);
+         PasV = (PasV - V0) / (myvsample - 1);
+         U0 = U0/2. + myumin;
+         V0 = V0/2. + myvmin;
+
+       // Calcul des distances
+
+         Standard_Integer NoU, NoV;
+         //mySphereUBTree.Clear();
+         Extrema_UBTreeFillerOfSphere aFiller(mySphereUBTree.ChangeTree());
+         Standard_Integer i = myusample * myvsample;
+         Standard_Real U, V;
+         /*for ( NoU = 1; NoU <= myusample; NoU++) {
+               for ( NoV = 1; NoV <= myvsample; NoV++) {
+                       i++;
+               }
+         }*/
+         mySphereArray = new Bnd_HArray1OfSphere(0, i);
+         i = 0;
+         for ( NoU = 1, U = U0; NoU <= myusample; NoU++, U += PasU) {
+               for ( NoV = 1, V = V0; NoV <= myvsample; NoV++, V += PasV) {
+                 P1 = myS->Value(U, V);
+                 //mypoints->SetValue(NoU, NoV, P1);
+                 Bnd_Sphere aSph(P1.XYZ(), 0/*mytolu < mytolv ? mytolu : mytolv*/, NoU, NoV);
+                 aFiller.Add(i, aSph);
+                 mySphereArray->SetValue( i, aSph );
+                 i++;
+               }
+         }
+         aFiller.Fill();
+       }
+}
+
+void Extrema_GenExtPS::FindSolution(const gp_Pnt& P, const math_Vector& UV, const Standard_Real PasU, const Standard_Real PasV, const Extrema_ExtFlag f)
+{
+  math_Vector Tol(1,2);
+  Tol(1) = mytolu;
+  Tol(2) = mytolv;
 
+  math_Vector UVinf(1,2), UVsup(1,2);
+  UVinf(1) = myumin;
+  UVinf(2) = myvmin;
+  UVsup(1) = myusup;
+  UVsup(2) = myvsup;
+
+  math_Vector errors(1,2);
+  math_Vector root(1, 2);
+  Standard_Real eps = 1.e-9;
+  Standard_Integer nbsubsample = 11;
+
+  Standard_Integer aNbMaxIter = 100;
+
+  if (myF.HasDegIso())
+    aNbMaxIter = 150;
+
+  math_FunctionSetRoot S (myF,UV,Tol,UVinf,UVsup, aNbMaxIter);
+  if(S.IsDone()) {
+    root = S.Root();
+    myF.Value(root, errors);
+    if(f == Extrema_ExtFlag_MIN) 
+    {
+      if(Abs(errors(1)) > eps || Abs(errors(2)) > eps) {
+        //try to improve solution on subgrid of sample points
+        gp_Pnt PSol = myS->Value(root(1), root(2));
+        Standard_Real DistSol = P.SquareDistance(PSol);
+
+        Standard_Real u1 = Max(UV(1) - PasU, myumin), u2 = Min(UV(1) + PasU, myusup);
+        Standard_Real v1 = Max(UV(2) - PasV, myvmin), v2 = Min(UV(2) + PasV, myvsup);
+
+        if(u2 - u1 < 2.*PasU) {
+          if(Abs(u1 - myumin) < 1.e-9) {
+            u2 = u1 + 2.*PasU;
+            u2 = Min(u2, myusup);
+          }
+          if(Abs(u2 - myusup) < 1.e-9) {
+            u1 = u2 - 2.*PasU;
+            u1 = Max(u1, myumin);
+          }
+        }
+
+        if(v2 - v1 < 2.*PasV) {
+          if(Abs(v1 - myvmin) < 1.e-9) {
+            v2 = v1 + 2.*PasV;
+            v2 = Min(v2, myvsup);
+          }
+          if(Abs(v2 - myvsup) < 1.e-9) {
+            v1 = v2 - 2.*PasV;
+            v1 = Max(v1, myvmin);
+          }
+        }
+
+        Standard_Real du = (u2 - u1)/(nbsubsample-1);
+        Standard_Real dv = (v2 - v1)/(nbsubsample-1);
+        Standard_Real u, v;
+        Standard_Real dist;
+
+        Standard_Boolean NewSolution = Standard_False;
+        Standard_Integer Nu, Nv;
+        for (Nu = 1, u = u1; Nu < nbsubsample; Nu++, u += du) {
+          for (Nv = 1, v = v1; Nv < nbsubsample; Nv++, v += dv) {
+            gp_Pnt Puv = myS->Value(u, v);
+            dist = P.SquareDistance(Puv);
+
+            if(dist < DistSol) {
+              UV(1) = u;
+              UV(2) = v;
+              NewSolution = Standard_True;
+              DistSol = dist;
+            }
+          }
+        }
+
+        if(NewSolution) {
+          //try to precise
+          math_FunctionSetRoot S (myF,UV,Tol,UVinf,UVsup, aNbMaxIter);
+        }
+
+      }
+    }
+  }
+  myDone = Standard_True;
+}
+
+void Extrema_GenExtPS::SetFlag(const Extrema_ExtFlag F)
+{
+  myFlag = F;
+}
+
+void Extrema_GenExtPS::SetAlgo(const Extrema_ExtAlgo A)
+{
+  myAlgo = A;
+}
 
 void Extrema_GenExtPS::Perform(const gp_Pnt& P) 
 {  
+  //BuildTree();
   myDone = Standard_False;
   myF.SetPoint(P);
 
-
-/*
-b- Calcul des minima:
-   -----------------
-   b.a) Initialisations:
-*/
-
-// Parametrage de l echantillon
-
   Standard_Real PasU = myusup - myumin;
   Standard_Real PasV = myvsup - myvmin;
   Standard_Real U, U0 = PasU / myusample / 100.;
@@ -245,211 +519,123 @@ b- Calcul des minima:
   U0 = U0/2.+myumin;
   V0 = V0/2.+myvmin;
 
-//     - generales
-  math_Vector Tol(1, 2);
-  Tol(1) = mytolu;
-  Tol(2) = mytolv;
-  math_Vector UV(1,2), UVinf(1,2), UVsup(1,2);
-  UVinf(1) = myumin;
-  UVinf(2) = myvmin;
-  UVsup(1) = myusup;
-  UVsup(2) = myvsup;
+  //math_Vector Tol(1, 2);
+  math_Vector UV(1,2);
 
-//     - des 'bords' du tableau mytbdist
-  Standard_Integer NoU,NoV;
+  if(myAlgo == Extrema_ExtAlgo_Grad)
+  {
+    Standard_Integer NoU,NoV;
 
-  TColStd_Array2OfReal TheDist(0, myusample+1, 0, myvsample+1);
-  for ( NoU = 1, U = U0; NoU <= myusample; NoU++, U += PasU) {
-    for ( NoV = 1, V = V0; NoV <= myvsample; NoV++, V += PasV) {
-      TheDist(NoU, NoV) = P.SquareDistance(mypoints->Value(NoU, NoV));
+    TColStd_Array2OfReal TheDist(0, myusample+1, 0, myvsample+1);
+    for ( NoU = 1, U = U0; NoU <= myusample; NoU++, U += PasU) {
+      for ( NoV = 1, V = V0; NoV <= myvsample; NoV++, V += PasV) {
+        TheDist(NoU, NoV) = P.SquareDistance(mypoints->Value(NoU, NoV));
+      }
     }
-  }
-  
-  for (NoV = 0; NoV <= myvsample+1; NoV++) {
-    TheDist(0,NoV) = RealLast();
-    TheDist(myusample+1,NoV) = RealLast();
-  }
-  for (NoU = 1; NoU <= myusample; NoU++) {
-    TheDist(NoU,0) = RealLast();
-    TheDist(NoU,myvsample+1) = RealLast();
-  }
 
-//     - du tableau TbSel(0,myusample+1,0,myvsample+1) de selection des points
-  TColStd_Array2OfInteger TbSel(0,myusample+1,0,myvsample+1);
-  TbSel.Init(0);
-/*
-   b.b) Calcul des minima:
-*/
-//     - recherche d un minimum sur la grille
-  math_Vector errors(1,2);
-  math_Vector root(1, 2);
-  Standard_Real eps = 1.e-9;
-  Standard_Integer nbsubsample = 11;
-  Standard_Integer Nu, Nv;
-  Standard_Real Dist;
-  for (NoU = 1; NoU <= myusample; NoU++) {
-    for (NoV = 1; NoV <= myvsample; NoV++) {
-      if (TbSel(NoU,NoV) == 0) {
-       Dist = TheDist(NoU,NoV);
-       if ((TheDist(NoU-1,NoV-1) >= Dist) &&
-           (TheDist(NoU-1,NoV  ) >= Dist) &&
-           (TheDist(NoU-1,NoV+1) >= Dist) &&
-           (TheDist(NoU  ,NoV-1) >= Dist) &&
-           (TheDist(NoU  ,NoV+1) >= Dist) &&
-           (TheDist(NoU+1,NoV-1) >= Dist) &&
-           (TheDist(NoU+1,NoV  ) >= Dist) &&
-           (TheDist(NoU+1,NoV+1) >= Dist)) {
-
-//     - calcul de l extremum sur la surface:
-         UV(1) = U0 + (NoU - 1) * PasU;
-         UV(2) = V0 + (NoV - 1) * PasV;
-//  Modified by skv - Thu Sep 30 15:21:07 2004 OCC593 Begin
-//       math_FunctionSetRoot S (myF,UV,Tol,UVinf,UVsup);
-          // Default value for math_FunctionSetRoot.
-         Standard_Integer aNbMaxIter = 100;
-
-         if (myF.HasDegIso())
-           aNbMaxIter = 150;
-
-         math_FunctionSetRoot S (myF,UV,Tol,UVinf,UVsup, aNbMaxIter);
-         if(S.IsDone()) {
-           root = S.Root();
-           myF.Value(root, errors);
-           if(Abs(errors(1)) > eps || Abs(errors(2)) > eps) {
-             //try to improve solution on subgrid of sample points
-             gp_Pnt PSol = myS->Value(root(1), root(2));
-             Standard_Real DistSol = P.SquareDistance(PSol);
-
-             Standard_Real u1 = Max(UV(1) - PasU, myumin), u2 = Min(UV(1) + PasU, myusup);
-             Standard_Real v1 = Max(UV(2) - PasV, myvmin), v2 = Min(UV(2) + PasV, myvsup);
-             
-             if(u2 - u1 < 2.*PasU) {
-               if(Abs(u1 - myumin) < 1.e-9) {
-                 u2 = u1 + 2.*PasU;
-                 u2 = Min(u2, myusup);
-               }
-               if(Abs(u2 - myusup) < 1.e-9) {
-                 u1 = u2 - 2.*PasU;
-                 u1 = Max(u1, myumin);
-               }
-             }
+    TColStd_Array2OfInteger TbSel(0,myusample+1,0,myvsample+1);
+    TbSel.Init(0);
 
-             if(v2 - v1 < 2.*PasV) {
-               if(Abs(v1 - myvmin) < 1.e-9) {
-                 v2 = v1 + 2.*PasV;
-                 v2 = Min(v2, myvsup);
-               }
-               if(Abs(v2 - myvsup) < 1.e-9) {
-                 v1 = v2 - 2.*PasV;
-                 v1 = Max(v1, myvmin);
-               }
-             }
-
-             Standard_Real du = (u2 - u1)/(nbsubsample-1);
-             Standard_Real dv = (v2 - v1)/(nbsubsample-1);
-             Standard_Real u, v;
-             Standard_Real dist;
-
-             Standard_Boolean NewSolution = Standard_False;
-             for (Nu = 1, u = u1; Nu < nbsubsample; Nu++, u += du) {
-               for (Nv = 1, v = v1; Nv < nbsubsample; Nv++, v += dv) {
-                 gp_Pnt Puv = myS->Value(u, v);
-                 dist = P.SquareDistance(Puv);
-                 
-                 if(dist < DistSol) {
-                   UV(1) = u;
-                   UV(2) = v;
-                   NewSolution = Standard_True;
-                   DistSol = dist;
-                 }
-               }
-             }
-             if(NewSolution) {
-               //try to precise
-               math_FunctionSetRoot S (myF,UV,Tol,UVinf,UVsup, aNbMaxIter);
-             }
+    Standard_Real Dist;
 
-           }
-         }
-//  Modified by skv - Thu Sep 30 15:21:07 2004 OCC593 End
-      
-//     - mise a jour du tableau TbSel    
-         for (Nu = NoU-1; Nu <= NoU+1; Nu++) {
-           for (Nv = NoV-1; Nv <= NoV+1; Nv++) {
-             TbSel(Nu,Nv) = 1;
-           }
-         }
-       }
-      } // if (TbSel(NoU,NoV)
-    } // for (NoV = 1; ...
-  } // for (NoU = 1; ...
-/*
-c- Calcul des maxima:
-   -----------------
-   c.a) Initialisations:
-*/
-//     - des 'bords' du tableau mytbdist
-  for (NoV = 0; NoV <= myvsample+1; NoV++) {
-    TheDist(0,NoV) = RealFirst();
-    TheDist(myusample+1,NoV) = RealFirst();
-  }
-  for (NoU = 1; NoU <= myusample; NoU++) {
-    TheDist(NoU,0) = RealFirst();
-    TheDist(NoU,myvsample+1) = RealFirst();
+    if(myFlag == Extrema_ExtFlag_MIN || myFlag == Extrema_ExtFlag_MINMAX) 
+    {
+      for (NoV = 0; NoV <= myvsample+1; NoV++) {
+        TheDist(0,NoV) = RealLast();
+        TheDist(myusample+1,NoV) = RealLast();
+      }
+      for (NoU = 1; NoU <= myusample; NoU++) {
+        TheDist(NoU,0) = RealLast();
+        TheDist(NoU,myvsample+1) = RealLast();
+      }
+      for (NoU = 1; NoU <= myusample; NoU++) {
+        for (NoV = 1; NoV <= myvsample; NoV++) {
+          if (TbSel(NoU,NoV) == 0) {
+            Dist = TheDist(NoU,NoV);
+            if ((TheDist(NoU-1,NoV-1) >= Dist) &&
+              (TheDist(NoU-1,NoV  ) >= Dist) &&
+              (TheDist(NoU-1,NoV+1) >= Dist) &&
+              (TheDist(NoU  ,NoV-1) >= Dist) &&
+              (TheDist(NoU  ,NoV+1) >= Dist) &&
+              (TheDist(NoU+1,NoV-1) >= Dist) &&
+              (TheDist(NoU+1,NoV  ) >= Dist) &&
+              (TheDist(NoU+1,NoV+1) >= Dist)) {
+                //Create array of UV vectors to calculate min
+                UV(1) = U0 + (NoU - 1) * PasU;
+                UV(2) = V0 + (NoV - 1) * PasV;
+                FindSolution(P, UV, PasU, PasV, Extrema_ExtFlag_MIN);
+            }
+          }
+        }
+      }
+    }
+    
+    if(myFlag == Extrema_ExtFlag_MAX || myFlag == Extrema_ExtFlag_MINMAX)
+    {
+      for (NoV = 0; NoV <= myvsample+1; NoV++) {
+        TheDist(0,NoV) = RealFirst();
+        TheDist(myusample+1,NoV) = RealFirst();
+      }
+      for (NoU = 1; NoU <= myusample; NoU++) {
+        TheDist(NoU,0) = RealFirst();
+        TheDist(NoU,myvsample+1) = RealFirst();
+      }
+      for (NoU = 1; NoU <= myusample; NoU++) {
+        for (NoV = 1; NoV <= myvsample; NoV++) {
+          if (TbSel(NoU,NoV) == 0) {
+            Dist = TheDist(NoU,NoV);
+            if ((TheDist(NoU-1,NoV-1) <= Dist) &&
+              (TheDist(NoU-1,NoV  ) <= Dist) &&
+              (TheDist(NoU-1,NoV+1) <= Dist) &&
+              (TheDist(NoU  ,NoV-1) <= Dist) &&
+              (TheDist(NoU  ,NoV+1) <= Dist) &&
+              (TheDist(NoU+1,NoV-1) <= Dist) &&
+              (TheDist(NoU+1,NoV  ) <= Dist) &&
+              (TheDist(NoU+1,NoV+1) <= Dist)) {
+                //Create array of UV vectors to calculate max
+                UV(1) = U0 + (NoU - 1) * PasU;
+                UV(2) = V0 + (NoV - 1) * PasV;
+                FindSolution(P, UV, PasU, PasV, Extrema_ExtFlag_MAX);
+            }
+          }
+        }
+      }
+    }
   }
-
-//     - du tableau TbSel(0,myusample+1,0,myvsample+1) de selection des points
-  for (NoU = 0; NoU <= myusample+1; NoU++) {
-    for (NoV = 0; NoV <= myvsample+1; NoV++) {
-      TbSel(NoU,NoV) = 0;
+  else
+  {
+    BuildTree();
+    if(myFlag == Extrema_ExtFlag_MIN || myFlag == Extrema_ExtFlag_MINMAX)
+    {
+      Bnd_Sphere aSol = mySphereArray->Value(0);
+      Bnd_SphereUBTreeSelectorMin aSelector(mySphereArray, aSol);
+      //aSelector.SetMaxDist( RealLast() );
+      aSelector.DefineCheckPoint( P );
+      Standard_Integer aNbSel = mySphereUBTree.Select( aSelector );
+      //TODO: check if no solution in binary tree
+      Bnd_Sphere& aSph = aSelector.Sphere();
+
+      UV(1) = U0 + (aSph.U() - 1) * PasU;
+      UV(2) = V0 + (aSph.V() - 1) * PasV;
+
+      FindSolution(P, UV, PasU, PasV, Extrema_ExtFlag_MIN);
+    }
+    if(myFlag == Extrema_ExtFlag_MAX || myFlag == Extrema_ExtFlag_MINMAX)
+    {
+      Bnd_Sphere aSol = mySphereArray->Value(0);
+      Bnd_SphereUBTreeSelectorMax aSelector(mySphereArray, aSol);
+      //aSelector.SetMaxDist( RealLast() );
+      aSelector.DefineCheckPoint( P );
+      Standard_Integer aNbSel = mySphereUBTree.Select( aSelector );
+      //TODO: check if no solution in binary tree
+      Bnd_Sphere& aSph = aSelector.Sphere();
+
+      UV(1) = U0 + (aSph.U() - 1) * PasU;
+      UV(2) = V0 + (aSph.V() - 1) * PasV;
+
+      FindSolution(P, UV, PasU, PasV, Extrema_ExtFlag_MAX);
     }
   }
-/*
-   c.b) Calcul des maxima:
-*/
-//     - recherche d un maximum sur la grille
-  for (NoU = 1; NoU <= myusample; NoU++) {
-    for (NoV = 1; NoV <= myvsample; NoV++) {
-      if (TbSel(NoU,NoV) == 0) {
-       Dist = TheDist(NoU,NoV);
-       if ((TheDist(NoU-1,NoV-1) <= Dist) &&
-           (TheDist(NoU-1,NoV  ) <= Dist) &&
-           (TheDist(NoU-1,NoV+1) <= Dist) &&
-           (TheDist(NoU  ,NoV-1) <= Dist) &&
-           (TheDist(NoU  ,NoV+1) <= Dist) &&
-           (TheDist(NoU+1,NoV-1) <= Dist) &&
-           (TheDist(NoU+1,NoV  ) <= Dist) &&
-           (TheDist(NoU+1,NoV+1) <= Dist)) {
-
-//     - calcul de l extremum sur la surface:
-         UV(1) = U0 + (NoU - 1) * PasU;
-         UV(2) = V0 + (NoV - 1) * PasV;
-//  Modified by skv - Thu Sep 30 15:21:07 2004 OCC593 Begin
-//       math_FunctionSetRoot S (myF,UV,Tol,UVinf,UVsup);
-          // Default value for math_FunctionSetRoot.
-         Standard_Integer aNbMaxIter = 100;
-
-         if (myF.HasDegIso())
-           aNbMaxIter = 150;
-
-         math_FunctionSetRoot S (myF,UV,Tol,UVinf,UVsup, aNbMaxIter);
-         if(S.IsDone()) {
-           root = S.Root();
-           myF.Value(root, errors);
-         }
-//  Modified by skv - Thu Sep 30 15:21:07 2004 OCC593 End
-      
-//     - mise a jour du tableau TbSel    
-         for (Nu = NoU-1; Nu <= NoU+1; Nu++) {
-           for (Nv = NoV-1; Nv <= NoV+1; Nv++) {
-             TbSel(Nu,Nv) = 1;
-           }
-         }
-       }
-      } // if (TbSel(NoU,NoV))
-    } // for (NoV = 1; ...)
-  } // for (NoU = 1; ...)
-  myDone = Standard_True;
 }
 //=============================================================================
 
@@ -476,4 +662,3 @@ Extrema_POnSurf Extrema_GenExtPS::Point (const Standard_Integer N) const
   return myF.Point(N);
 }
 //=============================================================================
-
diff --git a/src/Extrema/Extrema_HUBTreeOfSphere.cxx b/src/Extrema/Extrema_HUBTreeOfSphere.cxx
new file mode 100644 (file)
index 0000000..7efecee
--- /dev/null
@@ -0,0 +1,8 @@
+// File:      BestFitBnd_HUBTreeOfSphere.cxx
+// Created:   Thu Mar 17 14:30:42 2005
+// Author:    OPEN CASCADE Support
+// Copyright: OPEN CASCADE SA 2005
+
+#include <Extrema_HUBTreeOfSphere.hxx>
+
+IMPLEMENT_HUBTREE(Extrema_HUBTreeOfSphere,MMgt_TShared)
diff --git a/src/Extrema/Extrema_HUBTreeOfSphere.hxx b/src/Extrema/Extrema_HUBTreeOfSphere.hxx
new file mode 100644 (file)
index 0000000..3ac845c
--- /dev/null
@@ -0,0 +1,17 @@
+// File:      BestFitBnd_HUBTreeOfSphere.hxx
+// Created:   Thu Mar 17 14:30:42 2005
+// Author:    OPEN CASCADE Support
+// Copyright: OPEN CASCADE SA 2005
+
+#ifndef _Extrema_HUBTreeOfSphere_HeaderFile
+#define _Extrema_HUBTreeOfSphere_HeaderFile
+
+#include <NCollection_UBTree.hxx>
+#include <NCollection_UBTreeFiller.hxx>
+#include <Bnd_Sphere.hxx>
+
+typedef NCollection_UBTree<Standard_Integer,Bnd_Sphere> Extrema_UBTreeOfSphere;
+typedef NCollection_UBTreeFiller<Standard_Integer,Bnd_Sphere> Extrema_UBTreeFillerOfSphere;
+DEFINE_HUBTREE(Extrema_HUBTreeOfSphere, Standard_Integer, Bnd_Sphere, MMgt_TShared)
+
+#endif //_Extrema_HUBTreeOfSphere_HeaderFile
diff --git a/src/Extrema/FILES b/src/Extrema/FILES
new file mode 100644 (file)
index 0000000..d9705ff
--- /dev/null
@@ -0,0 +1,2 @@
+Extrema_HUBTreeOfSphere.hxx
+Extrema_HUBTreeOfSphere.cxx