Skip to content

Commit

Permalink
Add API function mkernel_mesh2d_delete_edge_by_index (#343 | GRIDEDIT…
Browse files Browse the repository at this point in the history
…-1224)
  • Loading branch information
ahmad-el-sayed authored Jun 18, 2024
1 parent 1a696ac commit 08036fa
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
7 changes: 7 additions & 0 deletions libs/MeshKernelApi/include/MeshKernelApi/MeshKernel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1007,6 +1007,13 @@ namespace meshkernelapi
double xUpperRightBoundingBox,
double yUpperRightBoundingBox);

/// @brief Deletes a mesh2d edge given the index of the edge.
/// The coordinates of the edge middle points are used for calculating the distances to the point.
/// @param[in] meshKernelId The id of the mesh state
/// @param[in] edgeIndex The index of the edge to delete
/// @returns Error code
MKERNEL_API int mkernel_mesh2d_delete_edge_by_index(int meshKernelId, int edgeIndex);

/// @brief Deletes all hanging edges. An hanging edge is an edge where one of the two nodes is not connected.
/// @param[in] meshKernelId The id of the mesh state
/// @returns Error code
Expand Down
19 changes: 19 additions & 0 deletions libs/MeshKernelApi/src/MeshKernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1876,6 +1876,25 @@ namespace meshkernelapi
return lastExitCode;
}

MKERNEL_API int mkernel_mesh2d_delete_edge_by_index(int meshKernelId, int edgeIndex)
{
lastExitCode = meshkernel::ExitCode::Success;
try
{
if (!meshKernelState.contains(meshKernelId))
{
throw meshkernel::MeshKernelError("The selected mesh kernel id does not exist.");
}

meshKernelUndoStack.Add(meshKernelState[meshKernelId].m_mesh2d->DeleteEdge(edgeIndex));
}
catch (...)
{
lastExitCode = HandleException();
}
return lastExitCode;
}

MKERNEL_API int mkernel_mesh2d_get_edge(int meshKernelId,
double xCoordinate,
double yCoordinate,
Expand Down
21 changes: 21 additions & 0 deletions libs/MeshKernelApi/tests/src/ApiTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1382,6 +1382,27 @@ TEST_F(CartesianApiTestFixture, DeleteHangingEdgesMesh2D_WithOneHangingEdges_Sho
ASSERT_EQ(mesh2d.num_valid_edges, 15);
}

TEST_F(CartesianApiTestFixture, DeleteEdgeByIndexThenDeleteHangingEdges)
{
MakeMesh();
int const meshKernelId = GetMeshKernelId();
meshkernelapi::Mesh2D mesh2d{};
int errorCode = mkernel_mesh2d_get_dimensions(meshKernelId, mesh2d);
int const initial_num_valid_edges = mesh2d.num_valid_edges;

// delete horizontal edge of lower left corner
errorCode = meshkernelapi::mkernel_mesh2d_delete_edge_by_index(meshKernelId, 0);
ASSERT_EQ(meshkernel::ExitCode::Success, errorCode);
errorCode = mkernel_mesh2d_get_dimensions(meshKernelId, mesh2d);
ASSERT_EQ(initial_num_valid_edges - 1, mesh2d.num_valid_edges);

// Execute
errorCode = meshkernelapi::mkernel_mesh2d_delete_hanging_edges(meshKernelId);
ASSERT_EQ(meshkernel::ExitCode::Success, errorCode);
errorCode = mkernel_mesh2d_get_dimensions(meshKernelId, mesh2d);
ASSERT_EQ(initial_num_valid_edges - 2, mesh2d.num_valid_edges);
}

TEST_F(CartesianApiTestFixture, ComputeOrthogonalizationMesh2D_WithOrthogonalMesh2D_ShouldOrthogonalize)
{
// Prepare
Expand Down

0 comments on commit 08036fa

Please sign in to comment.