Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove SwapVectorElements, use std::ranges::reverse instead #205

Merged
merged 1 commit into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions libs/MeshKernel/include/MeshKernel/Operations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,20 +468,6 @@ namespace meshkernel
return pointCoordinate;
}

/// @brief Swap the elements of a vector, such as the last elements becomes the first elements
/// @tparam T A type
/// @param[in] v The vector
template <class T>
void SwapVectorElements(std::vector<T>& v)
{
for (UInt i = 0; i < v.size() / 2; ++i)
{
const auto a = v[i];
v[i] = v[i + 1];
v[i + 1] = a;
}
}

/// @brief Computes dimensionless distances of a vector of points such as the first entry has distance 0 and the last entry has distance 1.
/// @param[in] v The vector of points
/// @param[in] projection The projection to use.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ void CurvilinearGridFromSplinesTransfinite::ComputeIntersections()
{
throw std::invalid_argument("CurvilinearGridFromSplinesTransfinite::Compute: At least two splines are intersecting twice.");
}
else if (m_splineType[i] == 0 && m_splineType[j] == 0)
if (m_splineType[i] == 0 && m_splineType[j] == 0)
{
// both undefined
}
Expand All @@ -356,7 +356,7 @@ void CurvilinearGridFromSplinesTransfinite::ComputeIntersections()
if (crossProductIntersection * m_splineType[i] < 0.0)
{
// switch j
SwapVectorElements(m_splines->m_splineNodes[j]);
std::ranges::reverse(m_splines->m_splineNodes[j]);
secondSplineRatio = static_cast<double>(numNodesJSpline) - 1.0 - secondSplineRatio;
}
}
Expand All @@ -366,7 +366,7 @@ void CurvilinearGridFromSplinesTransfinite::ComputeIntersections()
if (crossProductIntersection * m_splineType[j] > 0.0)
{
// switch i
SwapVectorElements(m_splines->m_splineNodes[i]);
std::ranges::reverse(m_splines->m_splineNodes[i]);
firstSplineRatio = static_cast<double>(numNodesISpline) - 1.0 - firstSplineRatio;
}
}
Expand Down Expand Up @@ -411,10 +411,7 @@ void CurvilinearGridFromSplinesTransfinite::ComputeIntersections()
{
break;
}
else
{
nSplineSortingHasNotChanged = false;
}
nSplineSortingHasNotChanged = false;
}

if (nSplineSortingHasNotChanged)
Expand Down Expand Up @@ -541,7 +538,7 @@ bool CurvilinearGridFromSplinesTransfinite::OrderSplines(UInt startFirst,
const auto secondIntersectionRatio = m_splineIntersectionRatios[i][k];

// all fine nothing to do, they are already sorted
if (secondIntersectionRatio == 0 || firstIntersectionRatio <= secondIntersectionRatio)
if (IsEqual(secondIntersectionRatio, 0.0) || firstIntersectionRatio <= secondIntersectionRatio)
{
continue;
}
Expand Down
Loading