diff --git a/libs/MeshKernel/src/Mesh2D.cpp b/libs/MeshKernel/src/Mesh2D.cpp index da6635883..3c3daa509 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 6efd778f0..85c668b0a 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 - ASSERT_EQ(numNodes, mesh->GetNumValidNodes()); + const auto numValidNodes = mesh->GetNumValidNodes(); + ASSERT_EQ(numNodes, numValidNodes); // Test the undo action has been computed correctly undoAction->Restore(); @@ -775,43 +776,44 @@ INSTANTIATE_TEST_SUITE_P(Mesh, MeshDeletion, ::testing::ValuesIn(MeshDeletion::G class MeshDeletionWithInnerPolygons : public ::testing::TestWithParam, int>> { - 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 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 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}}; + 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}, + }; public: [[nodiscard]] static std::vector, int>> GetData() { return { - {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}}; + {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} + + }; } }; @@ -821,7 +823,7 @@ TEST_P(MeshDeletionWithInnerPolygons, expected_results) auto const& [deleteOption, invertSelection, polygonNodes, numNodes] = GetParam(); // Setup - auto mesh = MakeRectangularMeshForTesting(7, 7, 1.0, meshkernel::Projection::cartesian); + auto mesh = MakeRectangularMeshForTesting(6, 6, 1.0, meshkernel::Projection::cartesian); const std::vector originalNodes(mesh->Nodes()); const std::vector originalEdges(mesh->Edges()); @@ -832,8 +834,8 @@ TEST_P(MeshDeletionWithInnerPolygons, expected_results) auto undoAction = mesh->DeleteMesh(polygon, deleteOption, invertSelection); // Assert - const auto nodes = mesh->Nodes(); - ASSERT_EQ(numNodes, mesh->GetNumValidNodes()); + const auto numValidNodes = mesh->GetNumValidNodes(); + ASSERT_EQ(numNodes, numValidNodes); // Test the undo action has been computed correctly undoAction->Restore();