Skip to content

Commit

Permalink
GRIDEDIT-953 Fixed several sonarcloud warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
BillSenior committed Jun 17, 2024
1 parent 94007c3 commit 087591e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
56 changes: 34 additions & 22 deletions libs/MeshKernel/src/CurvilinearGrid/CurvilinearGridSplineToGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -259,40 +259,42 @@ bool meshkernel::CurvilinearGridSplineToGrid::SortSplines(Splines& splines,
const UInt innerStartIndex,
const UInt innerEndIndex,
VectorOfDoubleVectors& splineIntersections,
bool& jaChange) const
bool& splinesSwapped) const
{
UInt count = 0;

for (UInt i = outerStartIndex; i < outerEndIndex; ++i)
{
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;
}
}
}
Expand Down Expand Up @@ -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;
}
}
}
}
Expand Down

0 comments on commit 087591e

Please sign in to comment.