From 9e3793c979fdba97fc39f8cd7294676956118850 Mon Sep 17 00:00:00 2001 From: Luca Carniato Date: Thu, 17 Oct 2024 15:10:36 +0200 Subject: [PATCH] Revert intersected/non-intersected inverted deletion options (#376 | GRIDEDIT-1452) Revert correct intersected/non-intersected faces deletion options (#369 | GRIDEDIT-1417) (cherry picked from commit 3f8bd9c6eb851d64f0d73411879c1cc8e0946885) --- libs/MeshKernel/src/Mesh2D.cpp | 4 +- libs/MeshKernel/tests/src/MeshTests.cpp | 74 ++++++++++++------------- 2 files changed, 38 insertions(+), 40 deletions(-) diff --git a/libs/MeshKernel/src/Mesh2D.cpp b/libs/MeshKernel/src/Mesh2D.cpp index 3c3daa509..da6635883 100644 --- a/libs/MeshKernel/src/Mesh2D.cpp +++ b/libs/MeshKernel/src/Mesh2D.cpp @@ -1744,7 +1744,7 @@ std::unique_ptr Mesh2D::DeleteMesh(const Polygons& polyg else if (deletionOption == InsideNotIntersected && invertDeletion) { excludedFace = [&isFaceCompletlyIncludedInPolygon, &faceIntersections](UInt f) - { return isFaceCompletlyIncludedInPolygon[f] || faceIntersections[f].faceIndex != constants::missing::uintValue; }; + { return isFaceCompletlyIncludedInPolygon[f] && faceIntersections[f].faceIndex == constants::missing::uintValue; }; } else if (deletionOption == InsideAndIntersected && !invertDeletion) { @@ -1754,7 +1754,7 @@ std::unique_ptr Mesh2D::DeleteMesh(const Polygons& polyg else if (deletionOption == InsideAndIntersected && invertDeletion) { excludedFace = [&isFaceCompletlyIncludedInPolygon, &faceIntersections](UInt f) - { return isFaceCompletlyIncludedInPolygon[f] && faceIntersections[f].faceIndex == constants::missing::uintValue; }; + { return isFaceCompletlyIncludedInPolygon[f] || faceIntersections[f].faceIndex != constants::missing::uintValue; }; } // Mark edges for deletion diff --git a/libs/MeshKernel/tests/src/MeshTests.cpp b/libs/MeshKernel/tests/src/MeshTests.cpp index 85c668b0a..6efd778f0 100644 --- a/libs/MeshKernel/tests/src/MeshTests.cpp +++ b/libs/MeshKernel/tests/src/MeshTests.cpp @@ -716,8 +716,8 @@ class MeshDeletion : public ::testing::TestWithParamDeleteMesh(polygon, deleteOption, invertSelection); // Assert - const auto numValidNodes = mesh->GetNumValidNodes(); - ASSERT_EQ(numNodes, numValidNodes); + ASSERT_EQ(numNodes, mesh->GetNumValidNodes()); // Test the undo action has been computed correctly undoAction->Restore(); @@ -776,44 +775,43 @@ INSTANTIATE_TEST_SUITE_P(Mesh, MeshDeletion, ::testing::ValuesIn(MeshDeletion::G class MeshDeletionWithInnerPolygons : public ::testing::TestWithParam, int>> { - static inline std::vector single_polygon_{ - {-0.722886114680926, 2.22765832371444}, - {1.50244688883463, 2.65710855246306}, - {3.04456361934103, 1.91533088462454}, - {3.47401384808964, 5.56565782898778}, - {-1.42562285263321, 5.70230108358961}, - {-0.722886114680926, 2.22765832371444}, + static inline std::vector firstPolygon_{ + {-0.5, -0.5}, + {7.5, -0.5}, + {7.5, 7.5}, + {-0.5, 7.5}, + {-0.5, -0.5}, + {meshkernel::constants::missing::innerOuterSeparator, meshkernel::constants::missing::innerOuterSeparator}, + {1.5, 1.5}, + {4.5, 1.5}, + {4.5, 4.5}, + {1.5, 4.5}, + {1.5, 1.5}, }; - static inline std::vector double_polygon_{ - {-0.722886114680926, 2.22765832371444}, - {1.50244688883463, 2.65710855246306}, - {3.04456361934103, 1.91533088462454}, - {3.47401384808964, 5.56565782898778}, - {-1.42562285263321, 5.70230108358961}, - {-0.722886114680926, 2.22765832371444}, - {meshkernel::constants::missing::doubleValue, meshkernel::constants::missing::doubleValue}, - {3.59021337251456, -1.90949318892618}, - {6.02802927483664, -1.86121960670198}, - {5.88320852816404, 2.09721413568238}, - {2.55233135469427, 0.600733086732198}, - {3.59021337251456, -1.90949318892618}, - }; + static inline std::vector secondPolygon_{ + {-0.5, -0.5}, + {7.5, -0.5}, + {7.5, 7.5}, + {-0.5, 7.5}, + {-0.5, -0.5}, + {meshkernel::constants::missing::innerOuterSeparator, meshkernel::constants::missing::innerOuterSeparator}, + {1.5, 1.5}, + {4.5, 1.5}, + {4.5, 4.5}, + {2.7, 4.5}, + {2.7, 3.3}, + {1.5, 3.3}, + {1.5, 1.5}}; public: [[nodiscard]] static std::vector, int>> GetData() { return { - {meshkernel::Mesh2D::DeleteMeshOptions::InsideAndIntersected, false, single_polygon_, 23}, - {meshkernel::Mesh2D::DeleteMeshOptions::InsideNotIntersected, false, single_polygon_, 30}, - {meshkernel::Mesh2D::DeleteMeshOptions::InsideAndIntersected, true, single_polygon_, 12}, - {meshkernel::Mesh2D::DeleteMeshOptions::InsideNotIntersected, true, single_polygon_, 23}, - {meshkernel::Mesh2D::DeleteMeshOptions::InsideAndIntersected, false, double_polygon_, 17}, - {meshkernel::Mesh2D::DeleteMeshOptions::InsideNotIntersected, false, double_polygon_, 29}, - {meshkernel::Mesh2D::DeleteMeshOptions::InsideAndIntersected, true, double_polygon_, 16}, - {meshkernel::Mesh2D::DeleteMeshOptions::InsideNotIntersected, true, double_polygon_, 29} - - }; + {meshkernel::Mesh2D::DeleteMeshOptions::InsideAndIntersected, false, firstPolygon_, 9}, + {meshkernel::Mesh2D::DeleteMeshOptions::InsideAndIntersected, true, firstPolygon_, 48}, + {meshkernel::Mesh2D::DeleteMeshOptions::InsideAndIntersected, false, secondPolygon_, 8}, + {meshkernel::Mesh2D::DeleteMeshOptions::InsideAndIntersected, true, secondPolygon_, 49}}; } }; @@ -823,7 +821,7 @@ TEST_P(MeshDeletionWithInnerPolygons, expected_results) auto const& [deleteOption, invertSelection, polygonNodes, numNodes] = GetParam(); // Setup - auto mesh = MakeRectangularMeshForTesting(6, 6, 1.0, meshkernel::Projection::cartesian); + auto mesh = MakeRectangularMeshForTesting(7, 7, 1.0, meshkernel::Projection::cartesian); const std::vector originalNodes(mesh->Nodes()); const std::vector originalEdges(mesh->Edges()); @@ -834,8 +832,8 @@ TEST_P(MeshDeletionWithInnerPolygons, expected_results) auto undoAction = mesh->DeleteMesh(polygon, deleteOption, invertSelection); // Assert - const auto numValidNodes = mesh->GetNumValidNodes(); - ASSERT_EQ(numNodes, numValidNodes); + const auto nodes = mesh->Nodes(); + ASSERT_EQ(numNodes, mesh->GetNumValidNodes()); // Test the undo action has been computed correctly undoAction->Restore();