From 477f9aa40136bd4924927c8f41bd1f557fe1b2fb Mon Sep 17 00:00:00 2001 From: bofdahof <172177156+bofdahof@users.noreply.github.com> Date: Wed, 12 Mar 2025 20:04:03 +1000 Subject: [PATCH] Mesh: apply std::ranges --- src/Mod/Mesh/App/Core/Evaluation.cpp | 3 +-- src/Mod/Mesh/App/Core/IO/WriterOBJ.cpp | 6 ++---- src/Mod/Mesh/App/Core/Segmentation.cpp | 2 +- src/Mod/Mesh/App/Core/TopoAlgorithm.cpp | 7 +++---- src/Mod/Mesh/Gui/MeshEditor.cpp | 11 +++++------ src/Mod/Mesh/Gui/MeshSelection.cpp | 8 ++++---- 6 files changed, 16 insertions(+), 21 deletions(-) diff --git a/src/Mod/Mesh/App/Core/Evaluation.cpp b/src/Mod/Mesh/App/Core/Evaluation.cpp index 2e5fd9954e..126eed55bf 100644 --- a/src/Mod/Mesh/App/Core/Evaluation.cpp +++ b/src/Mod/Mesh/App/Core/Evaluation.cpp @@ -403,8 +403,7 @@ void MeshEvalTopology::GetFacetManifolds(std::vector& raclFacetIndLi PointIndex ulPt1 = std::max(pI->_aulPoints[i], pI->_aulPoints[(i + 1) % 3]); std::pair edge = std::make_pair(ulPt0, ulPt1); - if (std::find(nonManifoldList.begin(), nonManifoldList.end(), edge) - != nonManifoldList.end()) { + if (std::ranges::find(nonManifoldList, edge) != nonManifoldList.end()) { raclFacetIndList.push_back(pI - rclFAry.begin()); } } diff --git a/src/Mod/Mesh/App/Core/IO/WriterOBJ.cpp b/src/Mod/Mesh/App/Core/IO/WriterOBJ.cpp index ae02241cf0..6e0ed76831 100644 --- a/src/Mod/Mesh/App/Core/IO/WriterOBJ.cpp +++ b/src/Mod/Mesh/App/Core/IO/WriterOBJ.cpp @@ -182,8 +182,7 @@ bool WriterOBJ::Save(std::ostream& out) for (auto it = rFacets.begin(); it != rFacets.end(); ++it, index++) { if (index == 0 || prev != Kd[index]) { prev = Kd[index]; - auto c_it = std::find(colors.begin(), colors.end(), prev); - if (c_it != colors.end()) { + if (auto c_it = std::ranges::find(colors, prev); c_it != colors.end()) { out << "usemtl material_" << (c_it - colors.begin()) << '\n'; } } @@ -224,8 +223,7 @@ bool WriterOBJ::Save(std::ostream& out) if (first || prev != Kd[it]) { first = false; prev = Kd[it]; - auto c_it = std::find(colors.begin(), colors.end(), prev); - if (c_it != colors.end()) { + if (auto c_it = std::ranges::find(colors, prev); c_it != colors.end()) { out << "usemtl material_" << (c_it - colors.begin()) << '\n'; } } diff --git a/src/Mod/Mesh/App/Core/Segmentation.cpp b/src/Mod/Mesh/App/Core/Segmentation.cpp index 569de82d22..f21245dbe8 100644 --- a/src/Mod/Mesh/App/Core/Segmentation.cpp +++ b/src/Mod/Mesh/App/Core/Segmentation.cpp @@ -53,7 +53,7 @@ void MeshSurfaceSegment::AddSegment(const std::vector& segm) MeshSegment MeshSurfaceSegment::FindSegment(FacetIndex index) const { for (const auto& segment : segments) { - if (std::find(segment.begin(), segment.end(), index) != segment.end()) { + if (std::ranges::find(segment, index) != segment.end()) { return segment; } } diff --git a/src/Mod/Mesh/App/Core/TopoAlgorithm.cpp b/src/Mod/Mesh/App/Core/TopoAlgorithm.cpp index 303029fac0..dfd38113f2 100644 --- a/src/Mod/Mesh/App/Core/TopoAlgorithm.cpp +++ b/src/Mod/Mesh/App/Core/TopoAlgorithm.cpp @@ -940,10 +940,10 @@ bool MeshTopoAlgorithm::CollapseVertex(const VertexCollapse& vc) const std::vector& faces = vc._circumFacets; // get neighbours that are not part of the faces to be removed for (int i = 0; i < 3; i++) { - if (std::find(faces.begin(), faces.end(), rFace2._aulNeighbours[i]) == faces.end()) { + if (std::ranges::find(faces, rFace2._aulNeighbours[i]) == faces.end()) { neighbour1 = rFace2._aulNeighbours[i]; } - if (std::find(faces.begin(), faces.end(), rFace3._aulNeighbours[i]) == faces.end()) { + if (std::ranges::find(faces, rFace3._aulNeighbours[i]) == faces.end()) { neighbour2 = rFace3._aulNeighbours[i]; } } @@ -1106,8 +1106,7 @@ bool MeshTopoAlgorithm::CollapseEdge(const EdgeCollapse& ec) for (FacetIndex nbIndex : f._aulNeighbours) { // get the neighbours of the facet that won't be invalidated if (nbIndex != FACET_INDEX_MAX) { - if (std::find(ec._removeFacets.begin(), ec._removeFacets.end(), nbIndex) - == ec._removeFacets.end()) { + if (std::ranges::find(ec._removeFacets, nbIndex) == ec._removeFacets.end()) { neighbours.push_back(nbIndex); } } diff --git a/src/Mod/Mesh/Gui/MeshEditor.cpp b/src/Mod/Mesh/Gui/MeshEditor.cpp index 3270210c15..9c15efd34f 100644 --- a/src/Mod/Mesh/Gui/MeshEditor.cpp +++ b/src/Mod/Mesh/Gui/MeshEditor.cpp @@ -323,9 +323,8 @@ void MeshFaceAddition::showMarker(SoPickedPoint* pp) SbVec3f face_pnt; for (int i = 0; i < 3; i++) { - int index = (int)f._aulPoints[i]; - if (std::find(faceView->index.begin(), faceView->index.end(), index) - != faceView->index.end()) { + int index = static_cast(f._aulPoints[i]); + if (std::ranges::find(faceView->index, index) != faceView->index.end()) { continue; // already inside } if (f._aulNeighbours[i] == MeshCore::FACET_INDEX_MAX @@ -524,9 +523,9 @@ void MeshFillHole::closeBridge() { // Do the hole-filling Gui::WaitCursor wc; - auto it = std::find(myPolygon.begin(), myPolygon.end(), myVertex1); - auto jt = std::find(myPolygon.begin(), myPolygon.end(), myVertex2); - if (it != myPolygon.end() && jt != myPolygon.end()) { + auto it = std::ranges::find(myPolygon, myVertex1); + if (auto jt = std::ranges::find(myPolygon, myVertex2); + it != myPolygon.end() && jt != myPolygon.end()) { // which iterator comes first if (jt < it) { std::swap(it, jt); diff --git a/src/Mod/Mesh/Gui/MeshSelection.cpp b/src/Mod/Mesh/Gui/MeshSelection.cpp index 5653350595..56876c9b52 100644 --- a/src/Mod/Mesh/Gui/MeshSelection.cpp +++ b/src/Mod/Mesh/Gui/MeshSelection.cpp @@ -568,10 +568,10 @@ void MeshSelection::pickFaceCallback(void* ud, SoEventCallback* n) if (!vp || !vp->isDerivedFrom()) { return; } - ViewProviderMesh* mesh = static_cast(vp); - MeshSelection* self = static_cast(ud); - std::list views = self->getViewProviders(); - if (std::find(views.begin(), views.end(), mesh) == views.end()) { + const auto mesh = static_cast(vp); + const auto self = static_cast(ud); + if (std::list views = self->getViewProviders(); + std::ranges::find(views, mesh) == views.end()) { return; } const SoDetail* detail = point->getDetail(/*mesh->getShapeNode()*/);