diff --git a/libs/MeshKernel/include/MeshKernel/LandBoundaries.hpp b/libs/MeshKernel/include/MeshKernel/LandBoundaries.hpp index 19818a076..42c3c3bfa 100644 --- a/libs/MeshKernel/include/MeshKernel/LandBoundaries.hpp +++ b/libs/MeshKernel/include/MeshKernel/LandBoundaries.hpp @@ -56,7 +56,7 @@ namespace meshkernel DoNotProject = 0, ToOriginalMeshBoundary = 1, OuterMeshBoundaryToLandBoundaries = 2, - InnerAndOuterMeshBoundaryToLandboundaries = 3 + InnerAndOuterMeshBoundariesToLandboundaries = 3 }; /// @brief Default constructor @@ -79,8 +79,8 @@ namespace meshkernel void Administrate(); /// @brief Find the mesh boundary line closest to the land boundary (find_nearest_meshline). - /// @param[in] projectToLandBoundaryOption The option describing the projection to the land boundary. - void FindNearestMeshBoundary(ProjectionsOptions projectToLandBoundaryOption); + /// @param[in] projectionOption The option describing the projection to the land boundary. + void FindNearestMeshBoundary(ProjectionsOptions projectionOption); /// @brief Snap the mesh nodes to land boundaries (snap_to_landboundary) [[nodiscard]] std::unique_ptr SnapMeshToLandBoundaries() const; @@ -89,7 +89,9 @@ namespace meshkernel /// @return The number of land boundary nodes. auto GetNumNodes() const { return m_landBoundary.GetNumNodes(); } - std::vector m_meshNodesLandBoundarySegments; ///< Mesh nodes to land boundary mapping (lanseg_map) + /// @brief Gets the land boundary segment index + /// @param[in] node The mesh node index + const UInt& LandBoundarySegment(UInt node) const { return m_meshNodesLandBoundarySegments[node]; } private: /// @brief Build an additional boundary for not assigned nodes (connect_boundary_paths) @@ -183,6 +185,7 @@ namespace meshkernel Mesh2D& m_mesh; ///< A reference to mesh const Polygons m_polygons; ///< A copy of the polygons LandBoundary m_landBoundary; ///< The nodes on the land boundary + std::vector m_meshNodesLandBoundarySegments; ///< Mesh nodes to land boundary mapping (lanseg_map) std::vector m_polygonNodesCache; ///< Array of points (e.g. points of a face) std::vector> m_validLandBoundaries; ///< Start and end indices of valid land boundaries (lanseg_startend) std::vector m_nodeFaceIndices; ///< For each node, the indices of the faces including them diff --git a/libs/MeshKernel/src/FlipEdges.cpp b/libs/MeshKernel/src/FlipEdges.cpp index 99c8f9d22..bccc8cd6f 100644 --- a/libs/MeshKernel/src/FlipEdges.cpp +++ b/libs/MeshKernel/src/FlipEdges.cpp @@ -355,7 +355,7 @@ int FlipEdges::ComputeTopologyFunctional(UInt edge, if (m_projectToLandBoundary && m_landBoundaries.GetNumNodes() > 0) { - if (m_landBoundaries.m_meshNodesLandBoundarySegments[firstNode] != constants::missing::uintValue && m_landBoundaries.m_meshNodesLandBoundarySegments[secondNode] != constants::missing::uintValue) + if (m_landBoundaries.LandBoundarySegment(firstNode) != constants::missing::uintValue && m_landBoundaries.LandBoundarySegment(secondNode) != constants::missing::uintValue) { // Edge is associated with a land boundary -> keep the edge return largeTopologyFunctionalValue; @@ -390,7 +390,7 @@ int FlipEdges::ComputeTopologyFunctional(UInt edge, int FlipEdges::DifferenceFromOptimum(UInt nodeIndex, UInt firstNode, UInt secondNode) const { - if (m_landBoundaries.m_meshNodesLandBoundarySegments[nodeIndex] == constants::missing::uintValue) + if (m_landBoundaries.LandBoundarySegment(nodeIndex) == constants::missing::uintValue) { return static_cast(m_mesh.m_nodesNumEdges[nodeIndex]) - static_cast(OptimalNumberOfConnectedNodes(nodeIndex)); } @@ -448,7 +448,7 @@ int FlipEdges::DifferenceFromOptimum(UInt nodeIndex, UInt firstNode, UInt second auto otherNode = OtherNodeOfEdge(m_mesh.GetEdge(edgeIndex), nodeIndex); UInt num = 1; - while (m_landBoundaries.m_meshNodesLandBoundarySegments[otherNode] == constants::missing::uintValue && + while (m_landBoundaries.LandBoundarySegment(otherNode) == constants::missing::uintValue && !m_mesh.IsEdgeOnBoundary(edgeIndex) && currentEdgeIndexInNodeEdges != edgeIndexConnectingSecondNode) { @@ -459,7 +459,7 @@ int FlipEdges::DifferenceFromOptimum(UInt nodeIndex, UInt firstNode, UInt second } UInt firstEdgeInPathIndex = constants::missing::uintValue; - if (m_landBoundaries.m_meshNodesLandBoundarySegments[otherNode] != constants::missing::uintValue || + if (m_landBoundaries.LandBoundarySegment(otherNode) != constants::missing::uintValue || m_mesh.IsEdgeOnBoundary(edgeIndex)) { firstEdgeInPathIndex = edgeIndex; @@ -473,7 +473,7 @@ int FlipEdges::DifferenceFromOptimum(UInt nodeIndex, UInt firstNode, UInt second edgeIndex = m_mesh.m_nodesEdges[nodeIndex][currentEdgeIndexInNodeEdges]; otherNode = OtherNodeOfEdge(m_mesh.GetEdge(edgeIndex), nodeIndex); num = num + 1; - while (m_landBoundaries.m_meshNodesLandBoundarySegments[otherNode] == constants::missing::uintValue && + while (m_landBoundaries.LandBoundarySegment(otherNode) == constants::missing::uintValue && !m_mesh.IsEdgeOnBoundary(edgeIndex) && currentEdgeIndexInNodeEdges != edgeIndexConnectingFirstNode && edgeIndex != firstEdgeInPathIndex) @@ -488,7 +488,7 @@ int FlipEdges::DifferenceFromOptimum(UInt nodeIndex, UInt firstNode, UInt second } } - if ((m_landBoundaries.m_meshNodesLandBoundarySegments[otherNode] != constants::missing::uintValue || + if ((m_landBoundaries.LandBoundarySegment(otherNode) != constants::missing::uintValue || m_mesh.IsEdgeOnBoundary(edgeIndex)) && edgeIndex != firstEdgeInPathIndex) { diff --git a/libs/MeshKernel/src/LandBoundaries.cpp b/libs/MeshKernel/src/LandBoundaries.cpp index 2ec4146c1..d2e61daff 100644 --- a/libs/MeshKernel/src/LandBoundaries.cpp +++ b/libs/MeshKernel/src/LandBoundaries.cpp @@ -98,15 +98,15 @@ void LandBoundaries::Administrate() } } -void LandBoundaries::FindNearestMeshBoundary(ProjectionsOptions projectToLandBoundaryOption) +void LandBoundaries::FindNearestMeshBoundary(ProjectionsOptions projectionOption) { if (m_landBoundary.IsEmpty()) { return; } - if (projectToLandBoundaryOption != ProjectionsOptions::OuterMeshBoundaryToLandBoundaries && - projectToLandBoundaryOption != ProjectionsOptions::InnerAndOuterMeshBoundaryToLandboundaries) + if (projectionOption != ProjectionsOptions::OuterMeshBoundaryToLandBoundaries && + projectionOption != ProjectionsOptions::InnerAndOuterMeshBoundariesToLandboundaries) { return; } @@ -126,7 +126,7 @@ void LandBoundaries::FindNearestMeshBoundary(ProjectionsOptions projectToLandBou { const auto [_, numRejectedPaths] = MakePath(landBoundarySegment); - if (numRejectedPaths > 0 && projectToLandBoundaryOption == ProjectionsOptions::InnerAndOuterMeshBoundaryToLandboundaries) + if (numRejectedPaths > 0 && projectionOption == ProjectionsOptions::InnerAndOuterMeshBoundariesToLandboundaries) { m_findOnlyOuterMeshBoundary = false; MakePath(landBoundarySegment); diff --git a/libs/MeshKernel/src/OrthogonalizationAndSmoothing.cpp b/libs/MeshKernel/src/OrthogonalizationAndSmoothing.cpp index bcd0ad1f2..c87e89c5f 100644 --- a/libs/MeshKernel/src/OrthogonalizationAndSmoothing.cpp +++ b/libs/MeshKernel/src/OrthogonalizationAndSmoothing.cpp @@ -93,7 +93,7 @@ std::unique_ptr OrthogonalizationAndSmoothing::Initializ // if (m_projectOptions == LandBoundaries::ProjectionsOptions::OuterMeshBoundaryToLandBoundaries || - m_projectOptions == LandBoundaries::ProjectionsOptions::InnerAndOuterMeshBoundaryToLandboundaries) + m_projectOptions == LandBoundaries::ProjectionsOptions::InnerAndOuterMeshBoundariesToLandboundaries) { m_landBoundaries->FindNearestMeshBoundary(m_projectOptions); } diff --git a/libs/MeshKernel/tests/src/LandBoundaryTests.cpp b/libs/MeshKernel/tests/src/LandBoundaryTests.cpp index d064397a8..fecfb22a5 100644 --- a/libs/MeshKernel/tests/src/LandBoundaryTests.cpp +++ b/libs/MeshKernel/tests/src/LandBoundaryTests.cpp @@ -28,16 +28,16 @@ TEST(LandBoundaries, OneLandBoundary) landboundaries.FindNearestMeshBoundary(meshkernel::LandBoundaries::ProjectionsOptions ::OuterMeshBoundaryToLandBoundaries); // Checks - EXPECT_EQ(1, landboundaries.m_meshNodesLandBoundarySegments[0]); - EXPECT_EQ(0, landboundaries.m_meshNodesLandBoundarySegments[1]); - EXPECT_EQ(2, landboundaries.m_meshNodesLandBoundarySegments[2]); - EXPECT_EQ(2, landboundaries.m_meshNodesLandBoundarySegments[3]); - EXPECT_EQ(3, landboundaries.m_meshNodesLandBoundarySegments[4]); - EXPECT_EQ(1, landboundaries.m_meshNodesLandBoundarySegments[5]); - EXPECT_EQ(1, landboundaries.m_meshNodesLandBoundarySegments[6]); - EXPECT_EQ(meshkernel::constants::missing::uintValue, landboundaries.m_meshNodesLandBoundarySegments[7]); - EXPECT_EQ(meshkernel::constants::missing::uintValue, landboundaries.m_meshNodesLandBoundarySegments[8]); - EXPECT_EQ(meshkernel::constants::missing::uintValue, landboundaries.m_meshNodesLandBoundarySegments[9]); + EXPECT_EQ(1, landboundaries.LandBoundarySegment(0)); + EXPECT_EQ(0, landboundaries.LandBoundarySegment(1)); + EXPECT_EQ(2, landboundaries.LandBoundarySegment(2)); + EXPECT_EQ(2, landboundaries.LandBoundarySegment(3)); + EXPECT_EQ(3, landboundaries.LandBoundarySegment(4)); + EXPECT_EQ(1, landboundaries.LandBoundarySegment(5)); + EXPECT_EQ(1, landboundaries.LandBoundarySegment(6)); + EXPECT_EQ(meshkernel::constants::missing::uintValue, landboundaries.LandBoundarySegment(7)); + EXPECT_EQ(meshkernel::constants::missing::uintValue, landboundaries.LandBoundarySegment(8)); + EXPECT_EQ(meshkernel::constants::missing::uintValue, landboundaries.LandBoundarySegment(9)); } TEST(LandBoundaries, TwoLandBoundaries) @@ -61,20 +61,20 @@ TEST(LandBoundaries, TwoLandBoundaries) auto polygons = meshkernel::Polygons(); // Execute - auto landboundaries = std::make_shared(landBoundaryPolygon, *mesh, polygons); - landboundaries->FindNearestMeshBoundary(meshkernel::LandBoundaries::ProjectionsOptions::OuterMeshBoundaryToLandBoundaries); + auto landboundaries = meshkernel::LandBoundaries(landBoundaryPolygon, *mesh, polygons); + landboundaries.FindNearestMeshBoundary(meshkernel::LandBoundaries::ProjectionsOptions::OuterMeshBoundaryToLandBoundaries); // Checks - EXPECT_EQ(2, landboundaries->m_meshNodesLandBoundarySegments[0]); - EXPECT_EQ(1, landboundaries->m_meshNodesLandBoundarySegments[1]); - EXPECT_EQ(1, landboundaries->m_meshNodesLandBoundarySegments[2]); - EXPECT_EQ(3, landboundaries->m_meshNodesLandBoundarySegments[3]); - EXPECT_EQ(3, landboundaries->m_meshNodesLandBoundarySegments[4]); - EXPECT_EQ(2, landboundaries->m_meshNodesLandBoundarySegments[5]); - EXPECT_EQ(2, landboundaries->m_meshNodesLandBoundarySegments[6]); - EXPECT_EQ(meshkernel::constants::missing::uintValue, landboundaries->m_meshNodesLandBoundarySegments[7]); - EXPECT_EQ(meshkernel::constants::missing::uintValue, landboundaries->m_meshNodesLandBoundarySegments[8]); - EXPECT_EQ(meshkernel::constants::missing::uintValue, landboundaries->m_meshNodesLandBoundarySegments[9]); + EXPECT_EQ(2, landboundaries.LandBoundarySegment(0)); + EXPECT_EQ(1, landboundaries.LandBoundarySegment(1)); + EXPECT_EQ(1, landboundaries.LandBoundarySegment(2)); + EXPECT_EQ(3, landboundaries.LandBoundarySegment(3)); + EXPECT_EQ(3, landboundaries.LandBoundarySegment(4)); + EXPECT_EQ(2, landboundaries.LandBoundarySegment(5)); + EXPECT_EQ(2, landboundaries.LandBoundarySegment(6)); + EXPECT_EQ(meshkernel::constants::missing::uintValue, landboundaries.LandBoundarySegment(7)); + EXPECT_EQ(meshkernel::constants::missing::uintValue, landboundaries.LandBoundarySegment(8)); + EXPECT_EQ(meshkernel::constants::missing::uintValue, landboundaries.LandBoundarySegment(9)); } TEST(LandBoundaries, OneCrossingLandBoundary) @@ -93,20 +93,20 @@ TEST(LandBoundaries, OneCrossingLandBoundary) auto polygons = meshkernel::Polygons(); // Execute - auto landboundaries = std::make_shared(landBoundaryPolygon, *mesh, polygons); - landboundaries->FindNearestMeshBoundary(meshkernel::LandBoundaries::ProjectionsOptions ::OuterMeshBoundaryToLandBoundaries); + auto landboundaries = meshkernel::LandBoundaries(landBoundaryPolygon, *mesh, polygons); + landboundaries.FindNearestMeshBoundary(meshkernel::LandBoundaries::ProjectionsOptions ::OuterMeshBoundaryToLandBoundaries); // Checks - EXPECT_EQ(0, landboundaries->m_meshNodesLandBoundarySegments[0]); - EXPECT_EQ(0, landboundaries->m_meshNodesLandBoundarySegments[1]); - EXPECT_EQ(2, landboundaries->m_meshNodesLandBoundarySegments[2]); - EXPECT_EQ(2, landboundaries->m_meshNodesLandBoundarySegments[3]); - EXPECT_EQ(1, landboundaries->m_meshNodesLandBoundarySegments[4]); - EXPECT_EQ(1, landboundaries->m_meshNodesLandBoundarySegments[5]); - EXPECT_EQ(1, landboundaries->m_meshNodesLandBoundarySegments[6]); - EXPECT_EQ(meshkernel::constants::missing::uintValue, landboundaries->m_meshNodesLandBoundarySegments[7]); - EXPECT_EQ(meshkernel::constants::missing::uintValue, landboundaries->m_meshNodesLandBoundarySegments[8]); - EXPECT_EQ(meshkernel::constants::missing::uintValue, landboundaries->m_meshNodesLandBoundarySegments[9]); + EXPECT_EQ(0, landboundaries.LandBoundarySegment(0)); + EXPECT_EQ(0, landboundaries.LandBoundarySegment(1)); + EXPECT_EQ(2, landboundaries.LandBoundarySegment(2)); + EXPECT_EQ(2, landboundaries.LandBoundarySegment(3)); + EXPECT_EQ(1, landboundaries.LandBoundarySegment(4)); + EXPECT_EQ(1, landboundaries.LandBoundarySegment(5)); + EXPECT_EQ(1, landboundaries.LandBoundarySegment(6)); + EXPECT_EQ(meshkernel::constants::missing::uintValue, landboundaries.LandBoundarySegment(7)); + EXPECT_EQ(meshkernel::constants::missing::uintValue, landboundaries.LandBoundarySegment(8)); + EXPECT_EQ(meshkernel::constants::missing::uintValue, landboundaries.LandBoundarySegment(9)); } TEST(LandBoundaries, TwoCrossingLandBoundary) @@ -129,20 +129,20 @@ TEST(LandBoundaries, TwoCrossingLandBoundary) auto polygons = meshkernel::Polygons(); // Execute - auto landboundaries = std::make_shared(landBoundaryPolygon, *mesh, polygons); - landboundaries->FindNearestMeshBoundary(meshkernel::LandBoundaries::ProjectionsOptions ::OuterMeshBoundaryToLandBoundaries); + auto landboundaries = meshkernel::LandBoundaries(landBoundaryPolygon, *mesh, polygons); + landboundaries.FindNearestMeshBoundary(meshkernel::LandBoundaries::ProjectionsOptions ::OuterMeshBoundaryToLandBoundaries); // Checks - EXPECT_EQ(2, landboundaries->m_meshNodesLandBoundarySegments[0]); - EXPECT_EQ(0, landboundaries->m_meshNodesLandBoundarySegments[1]); - EXPECT_EQ(1, landboundaries->m_meshNodesLandBoundarySegments[2]); - EXPECT_EQ(3, landboundaries->m_meshNodesLandBoundarySegments[3]); - EXPECT_EQ(3, landboundaries->m_meshNodesLandBoundarySegments[4]); - EXPECT_EQ(2, landboundaries->m_meshNodesLandBoundarySegments[5]); - EXPECT_EQ(2, landboundaries->m_meshNodesLandBoundarySegments[6]); - EXPECT_EQ(meshkernel::constants::missing::uintValue, landboundaries->m_meshNodesLandBoundarySegments[7]); - EXPECT_EQ(meshkernel::constants::missing::uintValue, landboundaries->m_meshNodesLandBoundarySegments[8]); - EXPECT_EQ(meshkernel::constants::missing::uintValue, landboundaries->m_meshNodesLandBoundarySegments[9]); + EXPECT_EQ(2, landboundaries.LandBoundarySegment(0)); + EXPECT_EQ(0, landboundaries.LandBoundarySegment(1)); + EXPECT_EQ(1, landboundaries.LandBoundarySegment(2)); + EXPECT_EQ(3, landboundaries.LandBoundarySegment(3)); + EXPECT_EQ(3, landboundaries.LandBoundarySegment(4)); + EXPECT_EQ(2, landboundaries.LandBoundarySegment(5)); + EXPECT_EQ(2, landboundaries.LandBoundarySegment(6)); + EXPECT_EQ(meshkernel::constants::missing::uintValue, landboundaries.LandBoundarySegment(7)); + EXPECT_EQ(meshkernel::constants::missing::uintValue, landboundaries.LandBoundarySegment(8)); + EXPECT_EQ(meshkernel::constants::missing::uintValue, landboundaries.LandBoundarySegment(9)); } TEST(LandBoundaries, LandBoundaryConstructorTestSinglePolyline) diff --git a/libs/MeshKernelApi/src/MeshKernel.cpp b/libs/MeshKernelApi/src/MeshKernel.cpp index f3aaa88f7..bfb29869d 100644 --- a/libs/MeshKernelApi/src/MeshKernel.cpp +++ b/libs/MeshKernelApi/src/MeshKernel.cpp @@ -505,7 +505,7 @@ namespace meshkernelapi // Construct all dependencies const auto polygon = meshkernel::Polygons(polygonNodes, meshKernelState[meshKernelId].m_projection); auto landBoundary = meshkernel::LandBoundaries(landBoundariesPoints, *meshKernelState[meshKernelId].m_mesh2d, polygon); - landBoundary.FindNearestMeshBoundary(meshkernel::LandBoundaries::ProjectionsOptions::InnerAndOuterMeshBoundaryToLandboundaries); + landBoundary.FindNearestMeshBoundary(meshkernel::LandBoundaries::ProjectionsOptions::InnerAndOuterMeshBoundariesToLandboundaries); // Execute algorithm meshKernelUndoStack.Add(landBoundary.SnapMeshToLandBoundaries());