0029712: Extrema algorithm raises exception
[occt.git] / src / Extrema / Extrema_ExtSS.cxx
index bf6451a..8675df6 100644 (file)
@@ -235,22 +235,25 @@ Standard_Boolean Extrema_ExtSS::IsDone() const
 
 Standard_Boolean Extrema_ExtSS::IsParallel() const
 {
+  if (!IsDone()) throw StdFail_NotDone();
   return myIsPar;
 }
 
 
 Standard_Real Extrema_ExtSS::SquareDistance(const Standard_Integer N) const
 {
-  if(!myDone) throw StdFail_NotDone();
-  if (myIsPar && N != 1) throw StdFail_InfiniteSolutions();
-  if ((N < 1) || (N > mySqDist.Length())) throw Standard_OutOfRange();
+  if (N < 1 || N > NbExt())
+  {
+    throw Standard_OutOfRange();
+  }
+
   return mySqDist.Value(N);
 }
 
 
 Standard_Integer Extrema_ExtSS::NbExt() const
 {
-  if(!myDone) throw StdFail_NotDone();
+  if (!IsDone()) throw StdFail_NotDone();
   return mySqDist.Length();
 }
 
@@ -260,7 +263,16 @@ void Extrema_ExtSS::Points(const Standard_Integer N,
                           Extrema_POnSurf&       P1,
                           Extrema_POnSurf&       P2) const
 {
-  if(!myDone) throw StdFail_NotDone();
+  if (IsParallel())
+  {
+    throw StdFail_InfiniteSolutions();
+  }
+
+  if (N < 1 || N > NbExt())
+  {
+    throw Standard_OutOfRange();
+  }
+
   P1 = myPOnS1.Value(N);
   P2 = myPOnS2.Value(N);
 }