From 692d569eae8f199cad609dbde8161998e8586ede Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 14 Nov 2024 02:53:00 +0000 Subject: Reuse existing vertices when processing boundary parts --- game/geoData.cpp | 50 +++++++++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 21 deletions(-) (limited to 'game/geoData.cpp') diff --git a/game/geoData.cpp b/game/geoData.cpp index f84f4e2..fcaea64 100644 --- a/game/geoData.cpp +++ b/game/geoData.cpp @@ -506,27 +506,35 @@ GeoData::setHeights(const std::span triangleStrip, const // Cut along each edge of triangleStrip AB, AC, BC, BD, CD, CE etc std::map *> boundaryTriangles; - auto doBoundaryPart - = [this, &boundaryTriangles](VertexHandle start, VertexHandle end, const Triangle<3> & triangle) { - boundaryTriangles.emplace(start, &triangle); - const auto endPoint = point(end); - while (!std::ranges::contains(vv_range(start), end) - && std::ranges::any_of(voh_range(start), [&](const auto & outHalf) { - const auto next = next_halfedge_handle(outHalf); - const auto startPoint = point(start); - const auto nextStartPoint = point(from_vertex_handle(next)); - const auto nextEndPoint = point(to_vertex_handle(next)); - if (linesCross(startPoint, endPoint, nextStartPoint, nextEndPoint)) { - if (const auto intersection = linesIntersectAt(startPoint.xy(), endPoint.xy(), - nextStartPoint.xy(), nextEndPoint.xy())) { - start = split(edge_handle(next), positionOnTriangle(*intersection, triangle)); - boundaryTriangles.emplace(start, &triangle); - return true; - } - } - return false; - })) { } - }; + auto doBoundaryPart = [this, &boundaryTriangles]( + VertexHandle start, VertexHandle end, const Triangle<3> & triangle) { + boundaryTriangles.emplace(start, &triangle); + const auto endPoint = point(end); + while (!std::ranges::contains(vv_range(start), end) + && std::ranges::any_of(voh_range(start), [&](const auto & outHalf) { + const auto next = next_halfedge_handle(outHalf); + const auto startPoint = point(start); + const auto nextStartPoint = point(from_vertex_handle(next)); + const auto nextEndPoint = point(to_vertex_handle(next)); + if (linesCross(startPoint, endPoint, nextStartPoint, nextEndPoint)) { + if (const auto intersection = linesIntersectAt( + startPoint.xy(), endPoint.xy(), nextStartPoint.xy(), nextEndPoint.xy())) { + const auto distS = glm::length(difference(*intersection, nextStartPoint.xy())); + const auto distE = glm::length(difference(*intersection, nextEndPoint.xy())); + if (const auto mdist = std::min({distS, distE}); mdist < 500.F) { + start = (mdist == distS) ? from_vertex_handle(next) : to_vertex_handle(next); + point(start) = positionOnTriangle(*intersection, triangle); + } + else { + start = split(edge_handle(next), positionOnTriangle(*intersection, triangle)); + } + boundaryTriangles.emplace(start, &triangle); + return true; + } + } + return false; + })) { } + }; auto doBoundary = [&doBoundaryPart, triangle = strip.begin()](const auto & verts) mutable { const auto & [a, b, c] = verts; doBoundaryPart(a, b, *triangle); -- cgit v1.2.3