Salome HOME
Update viewer on delete an item
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_CurveBuilder.cpp
index 04966cbd655d14b0e8215592c79127d25687e408..ffec79e30a7aeed5a2549ded6b41cb449e35daa4 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 //
 // You should have received a copy of the GNU Lesser General Public
 // License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-// See http://www.salome-platform.org/ or
-// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
 #include "GeomAlgoAPI_CurveBuilder.h"
@@ -35,7 +34,7 @@
 #include <Precision.hxx>
 
 
-static void reorder(Handle(TColgp_HArray1OfPnt) thePoints);
+static void reorder(Handle(TColgp_HArray1OfPnt)& thePoints);
 
 //=================================================================================================
 GeomEdgePtr GeomAlgoAPI_CurveBuilder::edge(const std::list<GeomPointPtr>& thePoints,
@@ -52,17 +51,17 @@ GeomEdgePtr GeomAlgoAPI_CurveBuilder::edge(const std::list<GeomPointPtr>& thePoi
     aPoints->SetValue(i, aPoint->impl<gp_Pnt>());
   }
 
-  // Reorder points if required
-  if (theIsToReorder) {
-    reorder(aPoints);
-  }
-
   // If the curve to be closed - remove last point if it is too close to the first one
   bool isClose = aPoints->First().Distance(aPoints->Last()) <= gp::Resolution();
   if (isClose && theIsClosed) {
     aPoints->Resize(aPoints->Lower(), aPoints->Upper() - 1, Standard_True);
   }
 
+  // Reorder points if required
+  if (theIsToReorder) {
+    reorder(aPoints);
+  }
+
   // Initialize interpolator
   GeomAPI_Interpolate anInterp(aPoints, theIsClosed, gp::Resolution());
 
@@ -94,7 +93,7 @@ GeomEdgePtr GeomAlgoAPI_CurveBuilder::edge(const std::list<GeomPointPtr>& thePoi
 }
 
 //================   Auxiliary functions   ========================================================
-void reorder(Handle(TColgp_HArray1OfPnt) thePoints)
+void reorder(Handle(TColgp_HArray1OfPnt)& thePoints)
 {
   if (thePoints->Length() < 3) {
     return;
@@ -103,7 +102,7 @@ void reorder(Handle(TColgp_HArray1OfPnt) thePoints)
   int aNbPoints = thePoints->Length();
   int aNbDup = 0;
   gp_Pnt aPrevPnt = thePoints->Value(1);
-  for (int i = 1; i < aNbPoints - 1; i++) {
+  for (int i = 1; i < aNbPoints; i++) {
     gp_Pnt aPnt = thePoints->Value(i);
     int aNearest = 0;
     double aMinDist = RealLast();
@@ -118,7 +117,7 @@ void reorder(Handle(TColgp_HArray1OfPnt) thePoints)
       // Keep given order of points to use it in case of equidistant candidates
       //               .-<---<-.
       //              /         \
-                      // o  o  o  c  o->o->o->o->n  o  o
+      // o  o  o  c  o->o->o->o->n  o  o
       //          |  |           |
       //          i i+1       nearest
       gp_Pnt aNearestPnt = thePoints->Value(aNearest);