Skip to content

Commit

Permalink
GRIDEDIT-779: refactor refinement loop
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasbuykx committed Nov 8, 2023
1 parent cb4b76a commit c8cf9ad
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions libs/MeshKernel/src/Polygon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,22 +264,20 @@ void RefineSegment(std::vector<meshkernel::Point>& refinedPolygon,
const auto& n0 = *nodeIterator;
const auto& n1 = *std::next(nodeIterator);

auto p = n0;

refinedPolygon.push_back(p);
refinedPolygon.push_back(n0);

const double segmentLength = ComputeDistance(n0, n1, projection);

auto n = std::lround(std::round(segmentLength / refinementDistance));
if (n * refinementDistance > segmentLength ||
meshkernel::IsEqual(n * refinementDistance, segmentLength, meshkernel::constants::geometric::refinementTolerance))
--n;

// Refined segment step size.
const meshkernel::Point delta = (n1 - n0) * refinementDistance / segmentLength;
double lengthAlongInterval = refinementDistance;

// Exit when the lengthAlongInterval is greater or equal than segmentLength
// To prevent very small refined segment lengths, also exit when lengthAlongInterval is a small fraction less (defined by refinementTolerance)
while (lengthAlongInterval < segmentLength && !meshkernel::IsEqual(lengthAlongInterval, segmentLength, meshkernel::constants::geometric::refinementTolerance))
for (auto i = 1; i <= n; ++i)
{
p += delta;
lengthAlongInterval += refinementDistance;
refinedPolygon.push_back(p);
refinedPolygon.push_back(n0 + i * delta);
}
}

Expand Down

0 comments on commit c8cf9ad

Please sign in to comment.