Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Factories/MacroStabilityInwardsChartDataPointsFactory.cs
===================================================================
diff -u -rcd90ebf744fb74f0d4b0dd6ee06f9c39b5faf213 -r3971a593f40814cb192b3f8413acd38a0f930e34
--- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Factories/MacroStabilityInwardsChartDataPointsFactory.cs (.../MacroStabilityInwardsChartDataPointsFactory.cs) (revision cd90ebf744fb74f0d4b0dd6ee06f9c39b5faf213)
+++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Factories/MacroStabilityInwardsChartDataPointsFactory.cs (.../MacroStabilityInwardsChartDataPointsFactory.cs) (revision 3971a593f40814cb192b3f8413acd38a0f930e34)
@@ -22,9 +22,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using Core.Common.Base.Data;
using Core.Common.Base.Geometry;
using Core.Common.Geometry;
using Core.Components.Chart.Data;
+using Ringtoets.MacroStabilityInwards.Data;
using Ringtoets.MacroStabilityInwards.Primitives;
namespace Ringtoets.MacroStabilityInwards.Forms.Factories
@@ -283,6 +285,90 @@
return GetLocalPointsFromGeometry(surfaceLine, surfaceLine?.DitchPolderSide);
}
+ ///
+ /// Creates grid points in 2D space based on the provided .
+ ///
+ /// The grid to create the grid points for.
+ ///
+ public static Point2D[] CreateGridPoints(MacroStabilityInwardsGrid grid)
+ {
+ if (grid == null
+ || grid.NumberOfHorizontalPoints == 0
+ || grid.NumberOfVerticalPoints == 0)
+ {
+ return new Point2D[0];
+ }
+
+ var points = new List();
+ IEnumerable interPolatedVerticalPositions = GetInterPolatedVerticalPositions(grid.ZBottom,
+ grid.ZTop,
+ grid.NumberOfVerticalPoints).ToArray();
+ foreach (RoundedDouble interPolatedVerticalPosition in interPolatedVerticalPositions)
+ {
+ points.AddRange(GetInterPolatedHorizontalPoints(grid.XLeft,
+ grid.XRight,
+ interPolatedVerticalPosition,
+ grid.NumberOfHorizontalPoints));
+ }
+
+ return points.ToArray();
+ }
+
+ private static IEnumerable GetInterPolatedVerticalPositions(RoundedDouble startPoint,
+ RoundedDouble endPoint,
+ int nrofPoints)
+ {
+ if (nrofPoints <= 1)
+ {
+ yield return startPoint;
+ yield break;
+ }
+
+ int nrofInterPolatedPoints = nrofPoints - 1;
+ RoundedDouble deltaZ = endPoint - startPoint;
+ RoundedDouble deltaZBetweenPoints = nrofPoints < 2
+ ? (RoundedDouble) 0.0
+ : (RoundedDouble) (deltaZ / nrofInterPolatedPoints);
+
+ RoundedDouble z = startPoint;
+ int nrOfRepetitions = nrofInterPolatedPoints < 0
+ ? 0
+ : nrofInterPolatedPoints;
+ for (var i = 0; i < nrOfRepetitions + 1; i++)
+ {
+ yield return z;
+ z += deltaZBetweenPoints;
+ }
+ }
+
+ private static IEnumerable GetInterPolatedHorizontalPoints(RoundedDouble startPoint,
+ RoundedDouble endPoint,
+ RoundedDouble zPoint,
+ int nrofPoints)
+ {
+ if (nrofPoints <= 1)
+ {
+ yield return new Point2D(startPoint, zPoint);
+ yield break;
+ }
+
+ int nrofInterPolatedPoints = nrofPoints - 1;
+ RoundedDouble deltaX = endPoint - startPoint;
+ RoundedDouble deltaXBetweenPoints = nrofPoints < 2
+ ? (RoundedDouble) 0
+ : (RoundedDouble) (deltaX / nrofInterPolatedPoints);
+
+ RoundedDouble x = startPoint;
+ int nrOfRepetitions = nrofInterPolatedPoints < 0
+ ? 0
+ : nrofInterPolatedPoints;
+ for (var i = 0; i < nrOfRepetitions + 1; i++)
+ {
+ yield return new Point2D(x, zPoint);
+ x += deltaXBetweenPoints;
+ }
+ }
+
private static Point2D[] GetLocalPointsFromGeometry(MacroStabilityInwardsSurfaceLine surfaceLine,
Point3D worldCoordinate)
{
Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Forms.Test/Factories/MacroStabilityInwardsChartDataPointsFactoryTest.cs
===================================================================
diff -u -r140635b34616f25ca853982955976632b6000c52 -r3971a593f40814cb192b3f8413acd38a0f930e34
--- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Forms.Test/Factories/MacroStabilityInwardsChartDataPointsFactoryTest.cs (.../MacroStabilityInwardsChartDataPointsFactoryTest.cs) (revision 140635b34616f25ca853982955976632b6000c52)
+++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Forms.Test/Factories/MacroStabilityInwardsChartDataPointsFactoryTest.cs (.../MacroStabilityInwardsChartDataPointsFactoryTest.cs) (revision 3971a593f40814cb192b3f8413acd38a0f930e34)
@@ -24,6 +24,7 @@
using Core.Common.Base.Data;
using Core.Common.Base.Geometry;
using NUnit.Framework;
+using Ringtoets.MacroStabilityInwards.Data;
using Ringtoets.MacroStabilityInwards.Forms.Factories;
using Ringtoets.MacroStabilityInwards.Primitives;
@@ -52,7 +53,7 @@
Point2D[] points = MacroStabilityInwardsChartDataPointsFactory.CreateSurfaceLinePoints(surfaceLine);
// Assert
- AssertEqualPointCollections(surfaceLine.LocalGeometry, points);
+ AssertEqualPointCollection(surfaceLine.LocalGeometry, points);
}
[Test]
@@ -848,8 +849,68 @@
}, areas.ElementAt(1));
}
- private static void AssertEqualPointCollections(IEnumerable points, IEnumerable chartPoints)
+ [Test]
+ public void CreateGridPoints_MacroStabilityInwardsGridNull_ReturnsEmptyPoints()
{
+ // Call
+ Point2D[] gridPoints = MacroStabilityInwardsChartDataPointsFactory.CreateGridPoints(null);
+
+ // Assert
+ CollectionAssert.IsEmpty(gridPoints);
+ }
+
+ [Test]
+ [TestCaseSource(nameof(GetGridSettingsNoGridPoints))]
+ public void CreateGridPoints_MacroStabilityInwardsGridNumberOfPointsNoGrid_ReturnsEmptyPoints(MacroStabilityInwardsGrid grid)
+ {
+ // Call
+ Point2D[] gridPoints = MacroStabilityInwardsChartDataPointsFactory.CreateGridPoints(grid);
+
+ // Assert
+ CollectionAssert.IsEmpty(gridPoints);
+ }
+
+ [Test]
+ [TestCaseSource(nameof(GetGridSettingsOnePoint))]
+ public void CreateGridPoints_MacroStabilityInwardsGridNumberOfPointsOnePoint_AlwaysReturnsBottomLeftPoint(
+ MacroStabilityInwardsGrid grid)
+ {
+ // Call
+ Point2D[] gridPoints = MacroStabilityInwardsChartDataPointsFactory.CreateGridPoints(grid);
+
+ // Assert
+ AssertEqualPointCollection(new[]
+ {
+ new Point2D(grid.XLeft, grid.ZBottom)
+ }, gridPoints);
+ }
+
+ [Test]
+ [TestCaseSource(nameof(GetGridSettingsOnlyHorizontalPoints))]
+ public void CreateGridPoints_MacroStabilityInwardsGridNumberOfPointsOnlyHorizontalPoints_ReturnsGridPointsAtBottom(
+ MacroStabilityInwardsGrid grid, Point2D[] expectedPoints)
+ {
+ // Call
+ Point2D[] gridPoints = MacroStabilityInwardsChartDataPointsFactory.CreateGridPoints(grid);
+
+ // Assert
+ AssertEqualPointCollection(expectedPoints, gridPoints);
+ }
+
+ [Test]
+ [TestCaseSource(nameof(GetGridSettingsOnlyVerticalPoints))]
+ public void CreateGridPoints_CreateGridPoints_MacroStabilityInwardsGridNumberOfPointsOnlyVerticallPoints_ReturnsGridPointsAtLeftSide
+ (MacroStabilityInwardsGrid grid, Point2D[] expectedPoints)
+ {
+ // Call
+ Point2D[] gridPoints = MacroStabilityInwardsChartDataPointsFactory.CreateGridPoints(grid);
+
+ // Assert
+ AssertEqualPointCollection(expectedPoints, gridPoints);
+ }
+
+ private static void AssertEqualPointCollection(IEnumerable points, IEnumerable chartPoints)
+ {
CollectionAssert.AreEqual(points, chartPoints);
}
@@ -861,7 +922,7 @@
var lastPoint = new Point2D(last.X, last.Y);
Point2D localCoordinate = point.ProjectIntoLocalCoordinates(firstPoint, lastPoint);
- AssertEqualPointCollections(new[]
+ AssertEqualPointCollection(new[]
{
new Point2D(new RoundedDouble(2, localCoordinate.X), new RoundedDouble(2, localCoordinate.Y))
}, chartPoints);
@@ -879,5 +940,142 @@
return surfaceLine;
}
+
+ #region TestData
+
+ private static IEnumerable GetGridSettingsNoGridPoints()
+ {
+ yield return new TestCaseData(new MacroStabilityInwardsGrid
+ {
+ NumberOfHorizontalPoints = 0,
+ XLeft = (RoundedDouble) 1,
+ XRight = (RoundedDouble) 2,
+ NumberOfVerticalPoints = 1,
+ ZTop = (RoundedDouble) 1,
+ ZBottom = (RoundedDouble) 3
+ });
+ yield return new TestCaseData(new MacroStabilityInwardsGrid
+ {
+ NumberOfHorizontalPoints = 1,
+ XLeft = (RoundedDouble) 1,
+ XRight = (RoundedDouble) 2,
+ NumberOfVerticalPoints = 0,
+ ZTop = (RoundedDouble) 1,
+ ZBottom = (RoundedDouble) 3
+ });
+ yield return new TestCaseData(new MacroStabilityInwardsGrid
+ {
+ NumberOfHorizontalPoints = 0,
+ XLeft = (RoundedDouble) 1,
+ XRight = (RoundedDouble) 2,
+ NumberOfVerticalPoints = 0,
+ ZTop = (RoundedDouble) 1,
+ ZBottom = (RoundedDouble) 3
+ });
+ }
+
+ private static IEnumerable GetGridSettingsOnlyHorizontalPoints()
+ {
+ var gridRightLargerThanLeft = new MacroStabilityInwardsGrid
+ {
+ NumberOfHorizontalPoints = 4,
+ XLeft = (RoundedDouble) 1,
+ XRight = (RoundedDouble) (-2.0),
+ NumberOfVerticalPoints = 1,
+ ZTop = (RoundedDouble) 3,
+ ZBottom = (RoundedDouble) 1
+ };
+ yield return new TestCaseData(gridRightLargerThanLeft, new[]
+ {
+ new Point2D(gridRightLargerThanLeft.XLeft, gridRightLargerThanLeft.ZBottom),
+ new Point2D(0, gridRightLargerThanLeft.ZBottom),
+ new Point2D(-1, gridRightLargerThanLeft.ZBottom),
+ new Point2D(gridRightLargerThanLeft.XRight, gridRightLargerThanLeft.ZBottom)
+ }).SetName("XLeft > XRight");
+
+ var gridLeftLargerThanRight = new MacroStabilityInwardsGrid
+ {
+ NumberOfHorizontalPoints = 4,
+ XLeft = (RoundedDouble) 1,
+ XRight = (RoundedDouble) 4,
+ NumberOfVerticalPoints = 1,
+ ZTop = (RoundedDouble) 3,
+ ZBottom = (RoundedDouble) 1
+ };
+ yield return new TestCaseData(gridLeftLargerThanRight, new[]
+ {
+ new Point2D(gridLeftLargerThanRight.XLeft, gridLeftLargerThanRight.ZBottom),
+ new Point2D(2, gridLeftLargerThanRight.ZBottom),
+ new Point2D(3, gridLeftLargerThanRight.ZBottom),
+ new Point2D(gridLeftLargerThanRight.XRight, gridLeftLargerThanRight.ZBottom)
+ }).SetName("XLeft < XRight");
+ }
+
+ private static IEnumerable GetGridSettingsOnlyVerticalPoints()
+ {
+ var gridTopLargerThanBottom = new MacroStabilityInwardsGrid
+ {
+ NumberOfHorizontalPoints = 1,
+ XLeft = (RoundedDouble) 1,
+ XRight = (RoundedDouble) 3,
+ NumberOfVerticalPoints = 4,
+ ZTop = (RoundedDouble) 4,
+ ZBottom = (RoundedDouble) 1
+ };
+ yield return new TestCaseData(gridTopLargerThanBottom, new[]
+ {
+ new Point2D(gridTopLargerThanBottom.XLeft, gridTopLargerThanBottom.ZBottom),
+ new Point2D(gridTopLargerThanBottom.XLeft, 2),
+ new Point2D(gridTopLargerThanBottom.XLeft, 3),
+ new Point2D(gridTopLargerThanBottom.XLeft, gridTopLargerThanBottom.ZTop)
+ }).SetName("ZBottom < ZTop");
+
+ var gridBottomLargerThanTop = new MacroStabilityInwardsGrid
+ {
+ NumberOfHorizontalPoints = 1,
+ XLeft = (RoundedDouble) 1,
+ XRight = (RoundedDouble) 3,
+ NumberOfVerticalPoints = 4,
+ ZTop = (RoundedDouble) (-2),
+ ZBottom = (RoundedDouble) 1
+ };
+ yield return new TestCaseData(gridBottomLargerThanTop, new[]
+ {
+ new Point2D(gridBottomLargerThanTop.XLeft, gridBottomLargerThanTop.ZBottom),
+ new Point2D(gridBottomLargerThanTop.XLeft, 0),
+ new Point2D(gridBottomLargerThanTop.XLeft, -1),
+ new Point2D(gridBottomLargerThanTop.XLeft, gridBottomLargerThanTop.ZTop)
+ }).SetName("ZBottom > ZTop");
+ }
+
+ private static IEnumerable GetGridSettingsOnePoint()
+ {
+ var xLeft = (RoundedDouble) 1;
+ var zBottom = (RoundedDouble) 1;
+
+ var grid = new MacroStabilityInwardsGrid
+ {
+ NumberOfHorizontalPoints = 1,
+ XLeft = xLeft,
+ XRight = (RoundedDouble) 2,
+ NumberOfVerticalPoints = 1,
+ ZTop = (RoundedDouble) 3,
+ ZBottom = zBottom
+ };
+ yield return new TestCaseData(grid).SetName("XRight > XLeft, ZTop > ZBottom");
+
+ var inverseGrid = new MacroStabilityInwardsGrid
+ {
+ NumberOfHorizontalPoints = 1,
+ XLeft = xLeft,
+ XRight = (RoundedDouble) (-2),
+ NumberOfVerticalPoints = 1,
+ ZTop = (RoundedDouble) (-3),
+ ZBottom = zBottom
+ };
+ yield return new TestCaseData(inverseGrid).SetName("XRight < XLeft, ZTop < ZBottom");
+ }
+
+ #endregion
}
}
\ No newline at end of file