Skip to content

Commit

Permalink
GRIDEDIT-1224: Import mkernel_mesh2d_delete_edge_by_index (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmad-el-sayed authored Jun 18, 2024
1 parent 3d8fb78 commit e4ed446
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/MeshKernelNET/Api/IMeshKernelApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,14 @@ int Mesh2dDelete(int meshKernelId,
int Mesh2dDeleteEdge(int meshKernelId, double xCoordinate, double yCoordinate, double xLowerLeftBoundingBox,
double yLowerLeftBoundingBox, double xUpperRightBoundingBox, double yUpperRightBoundingBox);

/// <summary>
/// Deletes a mesh 2d edge given the index of the edge
/// </summary>
/// <param name="meshKernelId">Id of the grid state</param>
/// <param name="edgeIndex">The index of the edge to delete</param>
/// <returns> true if the edge has been deleted, false if not </returns>
int Mesh2dDeleteEdgeByIndex(int meshKernelId, [In] int edgeIndex);

/// <summary>
/// Deletes all hanging edges. An hanging edge is an edge where one of the two nodes is not connected.
/// </summary>
Expand Down
5 changes: 5 additions & 0 deletions src/MeshKernelNET/Api/MeshKernelApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,11 @@ public int Mesh2dDeleteEdge(int meshKernelId, double xCoordinate, double yCoordi
return MeshKernelDll.Mesh2dDeleteEdge(meshKernelId, xCoordinate, yCoordinate, xLowerLeftBoundingBox, yLowerLeftBoundingBox, xUpperRightBoundingBox, yUpperRightBoundingBox);
}

public int Mesh2dDeleteEdgeByIndex(int meshKernelId, int edgeIndex)
{
return MeshKernelDll.Mesh2dDeleteEdgeByIndex(meshKernelId, edgeIndex);
}

public int Mesh2dDeleteHangingEdges(int meshKernelId)
{
return MeshKernelDll.Mesh2dDeleteHangingEdges(meshKernelId);
Expand Down
9 changes: 9 additions & 0 deletions src/MeshKernelNET/Native/MeshKernelDll.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1019,6 +1019,15 @@ internal static extern int Mesh2dDeleteEdge([In] int meshKernelId,
[In] double xUpperRightBoundingBox,
[In] double yUpperRightBoundingBox);

/// <summary>
/// Deletes a mesh 2d edge given the index of the edge
/// </summary>
/// <param name="meshKernelId">Id of the mesh state</param>
/// <param name="edgeIndex">The index of the edge to delete</param>
/// <returns>Error code</returns>
[DllImport(MeshKernelDllName, EntryPoint = "mkernel_mesh2d_delete_edge_by_index", CallingConvention = CallingConvention.Cdecl)]
internal static extern int Mesh2dDeleteEdgeByIndex([In] int meshKernelId, [In] int edgeIndex);

/// <summary>
/// Deletes all hanging edges. An hanging edge is an edge where one of the two nodes is not connected.
/// </summary>
Expand Down
37 changes: 37 additions & 0 deletions test/MeshKernelNETTest/Api/MeshKernelTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1056,6 +1056,43 @@ public void Mesh2dDeleteEdgeThroughAPI()
api.DeallocateState(id);
}
}
}

[Test]
public void Mesh2dDeleteEdgeByIndexThroughAPI()
{
//Setup

using (DisposableMesh2D mesh = CreateMesh2D(11, 11, 100, 100))
using (var api = new MeshKernelApi())
{
var id = 0;
var mesh2D = new DisposableMesh2D();
try
{
id = api.AllocateState(0);

Assert.AreEqual(0, api.Mesh2dSet(id, mesh));
int initNumEdges = mesh.NumEdges;

// Delete a valid edge
Assert.AreEqual(0, api.Mesh2dDeleteEdgeByIndex(id, 0));
// Expect the number of edges to decrease by 1
Assert.AreEqual(0, api.Mesh2dGetData(id, out mesh2D));
Assert.AreEqual(initNumEdges - 1, mesh2D.NumValidEdges);

// Delete an invalid edge
Assert.AreEqual(0, api.Mesh2dDeleteEdgeByIndex(id, 666));
// Expect the number of edges to remain unchanged
Assert.AreEqual(0, api.Mesh2dGetData(id, out mesh2D));
Assert.AreEqual(initNumEdges - 1, mesh2D.NumValidEdges);
}
finally
{
api.DeallocateState(id);
mesh2D.Dispose();
}
}
}

[Test]
Expand Down

0 comments on commit e4ed446

Please sign in to comment.