From 272f46f548506680af212187ff420918241670fe Mon Sep 17 00:00:00 2001
From: Dan Goodliffe <dan@randomdan.homeip.net>
Date: Thu, 14 Nov 2024 01:12:42 +0000
Subject: Fix do bounary part iteration

Exit when current vertex is adjacent to the end
---
 game/geoData.cpp | 34 ++++++++++++++++------------------
 1 file changed, 16 insertions(+), 18 deletions(-)

diff --git a/game/geoData.cpp b/game/geoData.cpp
index bf9aee0..f84f4e2 100644
--- a/game/geoData.cpp
+++ b/game/geoData.cpp
@@ -510,24 +510,22 @@ GeoData::setHeights(const std::span<const GlobalPosition3D> triangleStrip, const
 			= [this, &boundaryTriangles](VertexHandle start, VertexHandle end, const Triangle<3> & triangle) {
 				  boundaryTriangles.emplace(start, &triangle);
 				  const auto endPoint = point(end);
-				  while (std::any_of(voh_begin(start), voh_end(start), [&](const auto & outHalf) {
-					  const auto next = next_halfedge_handle(outHalf);
-					  if (next == end) {
-						  return false;
-					  }
-					  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;
-				  })) { }
+				  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 doBoundary = [&doBoundaryPart, triangle = strip.begin()](const auto & verts) mutable {
 		const auto & [a, b, c] = verts;
-- 
cgit v1.2.3