Skip to content

Commit 982e765

Browse files
Reintroduce mesh deletion option for faces with circumcenters included in the polygon
1 parent 0aeed91 commit 982e765

File tree

2 files changed

+137
-27
lines changed

2 files changed

+137
-27
lines changed

src/MeshKernelNET/Api/DeleteMeshInsidePolygonOptions.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ public enum DeleteMeshInsidePolygonOptions
88
NotIntersecting = 0,
99

1010
[Description("Intersecting")]
11-
Intersecting = 1
11+
Intersecting = 1,
12+
13+
[Description("Faces with included circumcenters")]
14+
FacesWithIncludedCircumcenters = 2
1215
}
1316
}

test/MeshKernelNETTest/Api/MeshKernelTest.cs

+133-26
Original file line numberDiff line numberDiff line change
@@ -2311,24 +2311,131 @@ public void Mesh2dCountHangingEdgesThroughAPI()
23112311
}
23122312

23132313
[Test]
2314-
public void Mesh2dDeleteInsidePolygonAndIntersectedThroughApi()
2315-
{
2316-
// Before After
2317-
// 30--31--32--33--34--35 30--31--32--33--34--35
2318-
// | | | | | | | | | | | |
2319-
// 24--25--26--27--28--29 24--25--26--27--28--29
2320-
// | | * | | * | | | | | |
2321-
// 18--19--20--12--22--23 18--19 22--23
2322-
// | | | | | | | | | |
2323-
// 12--13--14--15--16--17 12--13 16--17
2324-
// | | * | | * | | | | | |
2325-
// 6---7---8---9---10--11 6---7---8---9---10--11
2326-
// | | | | | | | | | | | |
2327-
// 0---1---2---3---4---5 0---1---2---3---4---5
2328-
// nodes 6 * 6 = 36 36 - 4 = 32
2329-
// edges 2 * 5 = 60 60 - 12 = 48
2330-
// faces 5 * 5 = 25 25 - (3 * 3) = 16
2331-
2314+
// The starting mesh looks as shown below. The grid spacing is uniform and equal to 1.
2315+
// The asterisks represent the vertices of a polygon. See the body of the test for the
2316+
// actual position of the vertices (they do not coincide with the cell centers).
2317+
// 30--31--32--33--34--35
2318+
// | | | | | |
2319+
// 24--25--26--27--28--29
2320+
// | | * | | * | |
2321+
// 18--19--20--12--22--23
2322+
// | | | | | |
2323+
// 12--13--14--15--16--17
2324+
// | | * | | * | |
2325+
// 6---7---8---9---10--11
2326+
// | | | | | |
2327+
// 0---1---2---3---4---5
2328+
// nodes 6 * 6 = 36
2329+
// edges 2 * 5 = 60
2330+
// faces 5 * 5 = 25
2331+
// The test is parametrized by all possible combinations of deletion options and selection inversion
2332+
[TestCase(DeleteMeshInsidePolygonOptions.NotIntersecting,
2333+
true,
2334+
4,
2335+
4,
2336+
1)]
2337+
// Case 1: should keep the central cell
2338+
// 20--21
2339+
// | |
2340+
// 14--15
2341+
// nodes = 4
2342+
// edges = 1
2343+
// faces = 1
2344+
[TestCase(DeleteMeshInsidePolygonOptions.Intersecting,
2345+
true,
2346+
16,
2347+
24,
2348+
9)]
2349+
// Case 2: should keep 3x3 central cells
2350+
// 25--26--27--28
2351+
// | | | |
2352+
// 19--20--21--22
2353+
// | | | |
2354+
// 13--14--15--16
2355+
// | | | |
2356+
// 7---8---9---10
2357+
// nodes = 4 * 4 = 16
2358+
// edges = 2 * (3 * 4) = 24
2359+
// faces = 1
2360+
[TestCase(DeleteMeshInsidePolygonOptions.FacesWithIncludedCircumcenters,
2361+
true,
2362+
16,
2363+
24,
2364+
9)]
2365+
// Case 3: should deletes all the outer cells
2366+
// 25--26--27--28
2367+
// | | | |
2368+
// 19--20--21--22
2369+
// | | | |
2370+
// 13--14--15--16
2371+
// | | | |
2372+
// 7---8---9---10
2373+
// nodes = 16
2374+
// faces = 9
2375+
[TestCase(DeleteMeshInsidePolygonOptions.NotIntersecting,
2376+
false,
2377+
36,
2378+
60,
2379+
25)]
2380+
// Case 4: should keep all cells but the central cell, i.e. delete the central face
2381+
// 30--31--32--33--34--35
2382+
// | | | | | |
2383+
// 24--25--26--27--28--29
2384+
// | | | | | |
2385+
// 18--19--20--21--22--23
2386+
// | | | / | | |
2387+
// 12--13--14--15--16--17
2388+
// | | | | | |
2389+
// 6---7---8---9---10--11
2390+
// | | | | | |
2391+
// 0---1---2---3---4---5
2392+
// nodes = 6 * 6 = 36 (no change)
2393+
// edges = 2 * (5 * 6) = 60 (no change)
2394+
// faces = 5 * 5 - 1 = 24
2395+
[TestCase(DeleteMeshInsidePolygonOptions.Intersecting,
2396+
false,
2397+
32,
2398+
48,
2399+
16)]
2400+
// Case 5: should delete 3x3 central cells
2401+
// 30--31--32--33--34--35
2402+
// | | | | | |
2403+
// 24--25--26--27--28--29
2404+
// | | | |
2405+
// 18--19 22--23
2406+
// | | | |
2407+
// 12--13 16--17
2408+
// | | | |
2409+
// 6---7---8---9---10--11
2410+
// | | | | | |
2411+
// 0---1---2---3---4---5
2412+
// nodes = 6 * 6 - 4 (central cell) = 32
2413+
// faces = 25 - (3 * 3) = 16
2414+
[TestCase(DeleteMeshInsidePolygonOptions.FacesWithIncludedCircumcenters,
2415+
false,
2416+
32,
2417+
48,
2418+
16)]
2419+
// Case 6: should delete 3x3 central cells
2420+
// 30--31--32--33--34--35
2421+
// | | | | | |
2422+
// 24--25--26--27--28--29
2423+
// | | | |
2424+
// 18--19 22--23
2425+
// | | | |
2426+
// 12--13 16--17
2427+
// | | | |
2428+
// 6---7---8---9---10--11
2429+
// | | | | | |
2430+
// 0---1---2---3---4---5
2431+
// nodes = 6 * 6 - 4 (central cell) = 32
2432+
// faces = 25 - (3 * 3) = 16
2433+
public void Mesh2dDeleteInsidePolygon(DeleteMeshInsidePolygonOptions deleteMeshInsidePolygonOptions,
2434+
bool invertSelection,
2435+
int expectedNumNodes,
2436+
int expectedNunEdges,
2437+
int expectedNumFaces)
2438+
{
23322439
// Setup
23332440
using (DisposableMesh2D mesh = CreateMesh2D(5, 5, 1, 1))
23342441
using (var api = new MeshKernelApi())
@@ -2339,19 +2446,19 @@ public void Mesh2dDeleteInsidePolygonAndIntersectedThroughApi()
23392446
try
23402447
{
23412448
polygon.NumberOfCoordinates = 5;
2342-
polygon.XCoordinates = new[] { 1.5, 3.5, 3.5, 1.5, 1.5 };
2343-
polygon.XCoordinates = new[] { 1.5, 1.5, 3.5, 3.5, 1.5 };
2449+
polygon.XCoordinates = new[] { 1.25, 3.75, 3.75, 1.25, 1.25 };
2450+
polygon.XCoordinates = new[] { 1.25, 1.25, 3.75, 3.75, 1.25 };
23442451

23452452
id = api.AllocateState(0);
23462453
Assert.AreEqual(0, api.Mesh2dSet(id, mesh));
23472454
Assert.AreEqual(0, api.Mesh2dDelete(id,
23482455
in polygon,
2349-
DeleteMeshInsidePolygonOptions.Intersecting,
2350-
false));
2456+
deleteMeshInsidePolygonOptions,
2457+
invertSelection));
23512458
Assert.AreEqual(0, api.Mesh2dGetData(id, out mesh2d));
2352-
Assert.AreNotEqual(32, mesh.NumNodes);
2353-
Assert.AreNotEqual(48, mesh.NumEdges);
2354-
Assert.AreNotEqual(16, mesh.NumFaces);
2459+
Assert.AreNotEqual(expectedNumNodes, mesh.NumNodes);
2460+
Assert.AreNotEqual(expectedNunEdges, mesh.NumEdges);
2461+
Assert.AreNotEqual(expectedNumFaces, mesh.NumFaces);
23552462
}
23562463
finally
23572464
{
@@ -2375,7 +2482,7 @@ public void Mesh2dMakeGlobaThroughApi()
23752482
{
23762483
int projectionType = 1;
23772484
id = api.AllocateState(projectionType);
2378-
Assert.AreEqual(0, api.Mesh2dMakeGlobal(id, 19,25));
2485+
Assert.AreEqual(0, api.Mesh2dMakeGlobal(id, 19, 25));
23792486

23802487
Assert.AreEqual(0, api.Mesh2dGetData(id, out mesh2d));
23812488
Assert.AreEqual(1233, mesh2d.NumEdges);

0 commit comments

Comments
 (0)