0024032: An exception raised during projection of the curve on the surface
[occt.git] / src / ProjLib / ProjLib_ComputeApproxOnPolarSurface.cxx
index c6c33a8..7f6bc8f 100755 (executable)
@@ -1,5 +1,22 @@
-// Author:     Bruno DUMORTIER
-//             <dub@fuegox>
+// Created by: Bruno DUMORTIER
+// Copyright (c) 1995-1999 Matra Datavision
+// Copyright (c) 1999-2012 OPEN CASCADE SAS
+//
+// The content of this file is subject to the Open CASCADE Technology Public
+// License Version 6.5 (the "License"). You may not use the content of this file
+// except in compliance with the License. Please obtain a copy of the License
+// at http://www.opencascade.org and read it completely before using this file.
+//
+// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
+// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
+//
+// The Original Code and all software distributed under the License is
+// distributed on an "AS IS" basis, without warranty of any kind, and the
+// Initial Developer 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 the rights and limitations under the License.
+
 #include <ProjLib_ComputeApproxOnPolarSurface.hxx>
 #include <AppCont_Function2d.hxx>
 #include <ElSLib.hxx>
@@ -303,10 +320,10 @@ class ProjLib_PolarFunction : public AppCont_Function2d
   ~ProjLib_PolarFunction() {}
   
   Standard_Real FirstParameter() const
-    {return (myCurve->FirstParameter()+1.e-9);}
+  {return (myCurve->FirstParameter()/*+1.e-9*/);}
   
   Standard_Real LastParameter() const
-    {return (myCurve->LastParameter()-1.e-9);}
+  {return (myCurve->LastParameter()/*-1.e-9*/);}
   
   gp_Pnt2d Value(const Standard_Real t) const {
     return Function_Value
@@ -851,6 +868,26 @@ Handle(Adaptor2d_HCurve2d)
     
     Curve->D0(Param.Value(1), pntproj) ;
     Extrema_ExtPS  aExtPS(pntproj, Surf->Surface(), TolU, TolV) ;
+    Standard_Real aMinSqDist = RealLast();
+    if (aExtPS.IsDone())
+    {
+      for (i = 1; i <= aExtPS.NbExt(); i++)
+      {
+        Standard_Real aSqDist = aExtPS.SquareDistance(i);
+        if (aSqDist < aMinSqDist)
+          aMinSqDist = aSqDist;
+      }
+    }
+    if (aMinSqDist > DistTol3d * DistTol3d) //try to project with less tolerance
+    {
+      TolU = Min(TolU, Precision::PConfusion());
+      TolV = Min(TolV, Precision::PConfusion());
+      aExtPS.Initialize(Surf->Surface(),
+                        Surf->Surface().FirstUParameter(), Surf->Surface().LastUParameter(), 
+                        Surf->Surface().FirstVParameter(), Surf->Surface().LastVParameter(),
+                        TolU, TolV);
+      aExtPS.Perform(pntproj);
+    }
 
     if( aExtPS.IsDone() && aExtPS.NbExt() >= 1 ) {
 
@@ -1553,8 +1590,8 @@ Handle(Geom2d_BSplineCurve)
     Standard_Integer NbKnots = NbCurves + 1;
     
     // The start and end nodes are not correct : Cf: opening of the interval
-    Knots( 1) -= 1.e-9;
-    Knots(NbKnots) += 1.e-9; 
+    //Knots( 1) -= 1.e-9;
+    //Knots(NbKnots) += 1.e-9; 
     
     
     TColStd_Array1OfInteger   Mults( 1, NbKnots);