0024068: Wrong result done by projection algorithm
[occt.git] / src / Extrema / Extrema_GenExtPS.cxx
index 926202f..7f5d034 100755 (executable)
@@ -114,7 +114,8 @@ Standard_Boolean Bnd_SphereUBTreeSelectorMin::Accept(const Standard_Integer& the
   const Bnd_Sphere& aSph = mySphereArray->Value(theInd);
   Standard_Real aCurDist;
 
-    if ( (aCurDist = aSph.SquareDistance(myXYZ.XYZ())) < mySol.SquareDistance(myXYZ.XYZ()) )
+//    if ( (aCurDist = aSph.SquareDistance(myXYZ.XYZ())) < mySol.SquareDistance(myXYZ.XYZ()) )
+    if ( (aCurDist = aSph.Distance(myXYZ.XYZ())) < mySol.Distance(myXYZ.XYZ()) )
     {
       mySol = aSph;
       if ( aCurDist < myMinDist ) 
@@ -160,7 +161,8 @@ Standard_Boolean Bnd_SphereUBTreeSelectorMax::Accept(const Standard_Integer& the
   const Bnd_Sphere& aSph = mySphereArray->Value(theInd);
   Standard_Real aCurDist;
 
-    if ( (aCurDist = aSph.SquareDistance(myXYZ.XYZ())) > mySol.SquareDistance(myXYZ.XYZ()) )
+//    if ( (aCurDist = aSph.SquareDistance(myXYZ.XYZ())) > mySol.SquareDistance(myXYZ.XYZ()) )
+    if ( (aCurDist = aSph.Distance(myXYZ.XYZ())) > mySol.Distance(myXYZ.XYZ()) )
     {
       mySol = aSph;
       if ( aCurDist > myMaxDist ) 
@@ -705,6 +707,16 @@ void Extrema_GenExtPS::BuildTree()
   if ( ! mySphereUBTree.IsNull() )
     return;
 
+   if (myS->GetType() == GeomAbs_BSplineSurface) {
+     Handle(Geom_BSplineSurface) aBspl = myS->BSpline();
+     Standard_Integer aUValue = aBspl->UDegree() * aBspl->NbUKnots();
+     Standard_Integer aVValue = aBspl->VDegree() * aBspl->NbVKnots();
+     if (aUValue > myusample)
+       myusample = aUValue;
+     if (aVValue > myvsample)
+       myvsample = aVValue;
+   }
+
   Standard_Real PasU = myusup - myumin;
   Standard_Real PasV = myvsup - myvmin;
   Standard_Real U0 = PasU / myusample / 100.;
@@ -752,7 +764,6 @@ void Extrema_GenExtPS::FindSolution(const gp_Pnt& /*P*/,
   Tol(2) = mytolv;
 
   math_Vector UV(1, 2);
-
   theParams.Parameter(UV(1), UV(2));
 
   math_Vector UVinf(1,2), UVsup(1,2);
@@ -761,15 +772,9 @@ void Extrema_GenExtPS::FindSolution(const gp_Pnt& /*P*/,
   UVsup(1) = myusup;
   UVsup(2) = myvsup;
 
-  math_Vector errors(1,2);
-  math_Vector root(1, 2);
-
-  Standard_Integer aNbMaxIter = 100;
+  const Standard_Integer aNbMaxIter = 100;
+  math_FunctionSetRoot S (myF, UV, Tol, UVinf, UVsup, aNbMaxIter);
 
-  gp_Pnt PStart = theParams.Value();
-  
-  math_FunctionSetRoot S (myF,UV,Tol,UVinf,UVsup, aNbMaxIter);
-  
   myDone = Standard_True;
 }
 
@@ -960,7 +965,7 @@ Standard_Real Extrema_GenExtPS::SquareDistance (const Standard_Integer N) const
 }
 //=============================================================================
 
-Extrema_POnSurf Extrema_GenExtPS::Point (const Standard_Integer N) const
+const Extrema_POnSurf& Extrema_GenExtPS::Point (const Standard_Integer N) const
 {
   if (!IsDone()) { StdFail_NotDone::Raise(); }
   return myF.Point(N);