Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GRIDEDIT-1390: curvilinear boundary incorrect separator #79

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 26 additions & 22 deletions src/MeshKernelNET/Api/MeshKernelApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ public int CurvilinearGridGetData(int meshKernelId, out DisposableCurvilinearGri
public int CurvilinearGetBoundariesAsPolygons(int meshKernelId, int lowerLeftN, int lowerLeftM, int upperRightN, int upperRightM, out DisposableGeometryList boundaryPolygons)
andreasbuykx marked this conversation as resolved.
Show resolved Hide resolved
{
int numberOfPolygonNodes = 0;
boundaryPolygons = new DisposableGeometryList();
int exitCode = MeshKernelDll.CurvilinearCountGetBoundariesAsPolygons(meshKernelId,
lowerLeftN,
lowerLeftM,
Expand All @@ -242,33 +243,36 @@ public int CurvilinearGetBoundariesAsPolygons(int meshKernelId, int lowerLeftN,
ref numberOfPolygonNodes);
if (exitCode != 0)
{
boundaryPolygons = new DisposableGeometryList();
return exitCode;
}

boundaryPolygons = new DisposableGeometryList();
boundaryPolygons.XCoordinates = new double[numberOfPolygonNodes];
boundaryPolygons.YCoordinates = new double[numberOfPolygonNodes];
double geometrySeparator = GetSeparator();
boundaryPolygons.GeometrySeparator = geometrySeparator;
boundaryPolygons.NumberOfCoordinates = numberOfPolygonNodes;

var geometryListNative = boundaryPolygons.CreateNativeObject();
exitCode = MeshKernelDll.CurvilinearGetBoundariesAsPolygons(meshKernelId,
lowerLeftN,
lowerLeftM,
upperRightN,
upperRightM,
ref geometryListNative);

if (exitCode != 0)
using(var exchangePolygons = new DisposableGeometryList())
{
boundaryPolygons = new DisposableGeometryList();
return exitCode;
exchangePolygons.NumberOfCoordinates = numberOfPolygonNodes;
exchangePolygons.XCoordinates = new double[numberOfPolygonNodes];
exchangePolygons.YCoordinates = new double[numberOfPolygonNodes];
exchangePolygons.GeometrySeparator = GetSeparator();
exchangePolygons.InnerOuterSeparator = GetInnerOuterSeparator();

var geometryListNative = exchangePolygons.CreateNativeObject();
exitCode = MeshKernelDll.CurvilinearGetBoundariesAsPolygons(meshKernelId,
lowerLeftN,
lowerLeftM,
upperRightN,
upperRightM,
ref geometryListNative);

if (exitCode != 0)
{
return exitCode;
}

boundaryPolygons.NumberOfCoordinates = exchangePolygons.NumberOfCoordinates;
boundaryPolygons.XCoordinates = geometryListNative.xCoordinates.CreateValueArray<double>(numberOfPolygonNodes);
boundaryPolygons.YCoordinates = geometryListNative.yCoordinates.CreateValueArray<double>(numberOfPolygonNodes);
boundaryPolygons.GeometrySeparator = exchangePolygons.GeometrySeparator;
boundaryPolygons.InnerOuterSeparator = exchangePolygons.InnerOuterSeparator;
}

boundaryPolygons.XCoordinates = geometryListNative.xCoordinates.CreateValueArray<double>(numberOfPolygonNodes);
boundaryPolygons.YCoordinates = geometryListNative.yCoordinates.CreateValueArray<double>(numberOfPolygonNodes);
return exitCode;
}

Expand Down
60 changes: 31 additions & 29 deletions test/MeshKernelNETTest/Api/MeshKernelCurvilinearTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Generic;
using GeoAPI.Geometries;
using MeshKernelNET.Api;
using NetTopologySuite.Algorithm;
using NetTopologySuite.Algorithm;
using NUnit.Framework;

namespace MeshKernelNETTest.Api
Expand Down Expand Up @@ -1059,44 +1059,46 @@ public void CurvilinearSetAndCovertThroughApi()

[Test]
public void CurvilinearGetBoundariesAsPolygons()
{
// Setup
using (var api = new MeshKernelApi())
{
var id = 0;
try
{
id = api.AllocateState(0);
var makeGridParameters = MakeGridParameters.CreateDefault();
makeGridParameters.GridType = 0;
makeGridParameters.NumberOfColumns = 3;
makeGridParameters.NumberOfRows = 3;
makeGridParameters.GridAngle = 0.0;
makeGridParameters.OriginXCoordinate = 0.0;
makeGridParameters.OriginYCoordinate = 0.0;
makeGridParameters.XGridBlockSize = 1.0;
makeGridParameters.YGridBlockSize = 1.0;
makeGridParameters.UpperRightCornerXCoordinate = 0.0;
makeGridParameters.UpperRightCornerYCoordinate = 0.0;
{
// Setup
using (var api = new MeshKernelApi())
{
var id = 0;
try
{
id = api.AllocateState(0);

var makeGridParameters = MakeGridParameters.CreateDefault();

makeGridParameters.GridType = 0;
makeGridParameters.NumberOfColumns = 3;
makeGridParameters.NumberOfRows = 3;
makeGridParameters.GridAngle = 0.0;
makeGridParameters.OriginXCoordinate = 0.0;
makeGridParameters.OriginYCoordinate = 0.0;
makeGridParameters.XGridBlockSize = 1.0;
makeGridParameters.YGridBlockSize = 1.0;
makeGridParameters.UpperRightCornerXCoordinate = 0.0;
makeGridParameters.UpperRightCornerYCoordinate = 0.0;

Assert.AreEqual(0, api.CurvilinearComputeRectangularGrid(id, makeGridParameters));
Assert.AreEqual(0, api.CurvilinearGetBoundariesAsPolygons(id, 0, 0, 3, 3, out DisposableGeometryList boundaryPolygons));

var expectedPolygonXCoordinates = new[] { 0, 1, 2, 3, 3, 3, 3, 2, 1, 0, 0, 0, 0 };
var expectedPolygonYCoordinates = new[] { 0, 0, 0, 0, 1, 2, 3, 3, 3, 3, 2, 1, 0 };

Assert.That(boundaryPolygons.GeometrySeparator,Is.EqualTo(api.GetSeparator()));
Assert.That(boundaryPolygons.InnerOuterSeparator,Is.EqualTo(api.GetInnerOuterSeparator()));
Assert.That(boundaryPolygons.XCoordinates, Is.EquivalentTo(expectedPolygonXCoordinates));
Assert.That(boundaryPolygons.YCoordinates, Is.EquivalentTo(expectedPolygonYCoordinates));

boundaryPolygons.Dispose();
}
finally
{
api.DeallocateState(id);
}
}
}
finally
{
api.DeallocateState(id);
}
}
}
}

Expand Down