diff --git a/libs/MeshKernel/include/MeshKernel/CurvilinearGrid/CurvilinearGridSplineToGrid.hpp b/libs/MeshKernel/include/MeshKernel/CurvilinearGrid/CurvilinearGridSplineToGrid.hpp index 5aae732e1..7d1299e43 100644 --- a/libs/MeshKernel/include/MeshKernel/CurvilinearGrid/CurvilinearGridSplineToGrid.hpp +++ b/libs/MeshKernel/include/MeshKernel/CurvilinearGrid/CurvilinearGridSplineToGrid.hpp @@ -166,7 +166,7 @@ namespace meshkernel const UInt innerStartIndex, const UInt innerEndIndex, VectorOfDoubleVectors& splineIntersections, - bool& jaChange) const; + bool& splinesSwapped) const; /// @brief Compute a point at a distance along the spline Point ComputePoint(const Splines& splines, diff --git a/libs/MeshKernel/src/CurvilinearGrid/CurvilinearGridSplineToGrid.cpp b/libs/MeshKernel/src/CurvilinearGrid/CurvilinearGridSplineToGrid.cpp index 41ad946c1..ce5ef5549 100644 --- a/libs/MeshKernel/src/CurvilinearGrid/CurvilinearGridSplineToGrid.cpp +++ b/libs/MeshKernel/src/CurvilinearGrid/CurvilinearGridSplineToGrid.cpp @@ -190,7 +190,7 @@ bool meshkernel::CurvilinearGridSplineToGrid::ComputeInteractions(Splines& splin VectorOfDoubleVectors& splineIntersections) const { - std::fill(splineIntersections.begin(), splineIntersections.end(), DoubleVector(splines.GetNumSplines(), 0.0)); + std::ranges::fill(splineIntersections, DoubleVector(splines.GetNumSplines(), 0.0)); for (UInt splineI = 0; splineI < splines.GetNumSplines(); ++splineI) { @@ -259,7 +259,7 @@ bool meshkernel::CurvilinearGridSplineToGrid::SortSplines(Splines& splines, const UInt innerStartIndex, const UInt innerEndIndex, VectorOfDoubleVectors& splineIntersections, - bool& jaChange) const + bool& splinesSwapped) const { UInt count = 0; @@ -267,32 +267,34 @@ bool meshkernel::CurvilinearGridSplineToGrid::SortSplines(Splines& splines, { for (UInt j = innerStartIndex; j < innerEndIndex; ++j) { + if (splineIntersections[i][j] == 0.0) + { + continue; + } - if (splineIntersections[i][j] != 0.0) + for (UInt k = j + 1; k < innerEndIndex; ++k) { - for (UInt k = j + 1; k < innerEndIndex; ++k) + if (splineIntersections[i][k] == 0.0) { - if (splineIntersections[i][k] != 0.0) - { - - if (splineIntersections[i][j] > splineIntersections[i][k]) - { - splines.SwapSplines(j, k); + continue; + } - splineIntersections[j].swap(splineIntersections[k]); - SwapColumns(splineIntersections, j, k); + if (splineIntersections[i][j] > splineIntersections[i][k]) + { + splines.SwapSplines(j, k); - jaChange = true; - ++count; + splineIntersections[j].swap(splineIntersections[k]); + SwapColumns(splineIntersections, j, k); - if (count > splines.GetNumSplines()) - { - throw AlgorithmError("Problem in spline ordering, modify splines"); - } + splinesSwapped = true; + ++count; - return false; - } + if (count > splines.GetNumSplines()) + { + throw AlgorithmError("Problem in spline ordering, modify splines"); } + + return false; } } } @@ -791,18 +793,28 @@ void meshkernel::CurvilinearGridSplineToGrid::GenerateGridPointsAlongSpline(cons if (splineIndex < numMSplines) { - for (UInt i = startIndex; i < endIndex && index < gridPoints.size(); ++i) + for (UInt i = startIndex; i < endIndex; ++i) { gridNodes(position, i) = gridPoints[index]; ++index; + + if (index == gridPoints.size()) + { + break; + } } } else { - for (UInt i = startIndex; i < endIndex && index < gridPoints.size(); ++i) + for (UInt i = startIndex; i < endIndex; ++i) { gridNodes(i, position) = gridPoints[index]; ++index; + + if (index == gridPoints.size()) + { + break; + } } } }