From 6810d01af98a67f39a7698f7d16339eb58dbef25 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 31 Mar 2024 21:58:18 +0100 Subject: Factor out some helper lambdas into members --- game/geoData.cpp | 40 ++++++++++++++++++++++++---------------- game/geoData.h | 3 +++ 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/game/geoData.cpp b/game/geoData.cpp index 931eb6a..ccad9e0 100644 --- a/game/geoData.cpp +++ b/game/geoData.cpp @@ -352,6 +352,24 @@ GeoData::findBoundaryStart() const }); } +[[nodiscard]] RelativePosition3D +GeoData::difference(const HalfedgeHandle heh) const +{ + return point(to_vertex_handle(heh)) - point(from_vertex_handle(heh)); +} + +[[nodiscard]] RelativeDistance +GeoData::length(const HalfedgeHandle heh) const +{ + return glm::length(difference(heh)); +} + +[[nodiscard]] GlobalPosition3D +GeoData::centre(const HalfedgeHandle heh) const +{ + return point(from_vertex_handle(heh)) + (difference(heh) / 2.F); +} + void GeoData::update_vertex_normals_only() { @@ -385,16 +403,6 @@ GeoData::setHeights(const std::span triangleStrip) static const RelativeDistance MIN_ARC = 0.01F; static const RelativeDistance MAX_EDGE_LENGTH = 20'000.F; - auto diff = [this](const auto heh) { - return RelativePosition3D(point(to_vertex_handle(heh)) - point(from_vertex_handle(heh))); - }; - auto hehlength = [diff](const auto heh) { - return glm::length(diff(heh)); - }; - auto hehcentre = [this, diff](const auto heh) { - return point(from_vertex_handle(heh)) + (diff(heh) / 2.F); - }; - if (triangleStrip.size() < 3) { return; } @@ -412,13 +420,13 @@ GeoData::setHeights(const std::span triangleStrip) }); // Split faces with two large boundary sides boundaryWalk( - [this, hehlength](const auto boundaryHeh) { + [this](const auto boundaryHeh) { const auto nextHeh = next_halfedge_handle(boundaryHeh); const auto faceHandle = opposite_face_handle(boundaryHeh); if (faceHandle != opposite_face_handle(nextHeh)) { return; } - if (hehlength(boundaryHeh) < MAX_EDGE_LENGTH || hehlength(nextHeh) < MAX_EDGE_LENGTH) { + if (length(boundaryHeh) < MAX_EDGE_LENGTH || length(nextHeh) < MAX_EDGE_LENGTH) { return; } @@ -428,12 +436,12 @@ GeoData::setHeights(const std::span triangleStrip) }, *voh_begin(newVerts.front())); // Split long boundary edges - while ([hehlength, hehcentre, this, start = *voh_begin(newVerts.front())]() { + while ([this, start = *voh_begin(newVerts.front())]() { size_t countSplit = 0; boundaryWalk( - [this, &countSplit, hehlength, hehcentre](const auto boundaryHeh) { - if (hehlength(boundaryHeh) > MAX_EDGE_LENGTH) { - split(edge_handle(boundaryHeh), hehcentre(boundaryHeh)); + [this, &countSplit](const auto boundaryHeh) { + if (length(boundaryHeh) > MAX_EDGE_LENGTH) { + split(edge_handle(boundaryHeh), centre(boundaryHeh)); ++countSplit; } }, diff --git a/game/geoData.h b/game/geoData.h index 5671954..88eb304 100644 --- a/game/geoData.h +++ b/game/geoData.h @@ -109,6 +109,9 @@ protected: [[nodiscard]] static bool triangleOverlapsTriangle(const Triangle<2> &, const Triangle<2> &); [[nodiscard]] static bool triangleContainsTriangle(const Triangle<2> &, const Triangle<2> &); [[nodiscard]] HalfedgeHandle findBoundaryStart() const; + [[nodiscard]] RelativePosition3D difference(const HalfedgeHandle) const; + [[nodiscard]] RelativeDistance length(const HalfedgeHandle) const; + [[nodiscard]] GlobalPosition3D centre(const HalfedgeHandle) const; void update_vertex_normals_only(); -- cgit v1.2.3