Index: Ringtoets/Revetment/src/Ringtoets.Revetment.Forms/Factories/WaveConditionsChartDataFactory.cs =================================================================== diff -u -rf1f94637a6b45b394493bf16a078b317c02d329b -rfb7d1c7fd44684526a1a9ab6ec9b0b6f0e18fe73 --- Ringtoets/Revetment/src/Ringtoets.Revetment.Forms/Factories/WaveConditionsChartDataFactory.cs (.../WaveConditionsChartDataFactory.cs) (revision f1f94637a6b45b394493bf16a078b317c02d329b) +++ Ringtoets/Revetment/src/Ringtoets.Revetment.Forms/Factories/WaveConditionsChartDataFactory.cs (.../WaveConditionsChartDataFactory.cs) (revision fb7d1c7fd44684526a1a9ab6ec9b0b6f0e18fe73) @@ -71,6 +71,17 @@ Style = GetRevetmentBoundaryStyle() }; } + /// + /// Create with default styling for revetment. + /// + /// The created . + public static ChartLineData CreateRevetmentBaseChartData() + { + return new ChartLineData(Resources.WaveConditionsChartDataFactory_Revetment_DisplayName) + { + Style = new ChartLineStyle(Color.Gray, 2, DashStyle.Dash) + }; + } /// /// Updates the name of based on . Index: Ringtoets/Revetment/src/Ringtoets.Revetment.Forms/Factories/WaveConditionsChartDataPointsFactory.cs =================================================================== diff -u -rf1f94637a6b45b394493bf16a078b317c02d329b -rfb7d1c7fd44684526a1a9ab6ec9b0b6f0e18fe73 --- Ringtoets/Revetment/src/Ringtoets.Revetment.Forms/Factories/WaveConditionsChartDataPointsFactory.cs (.../WaveConditionsChartDataPointsFactory.cs) (revision f1f94637a6b45b394493bf16a078b317c02d329b) +++ Ringtoets/Revetment/src/Ringtoets.Revetment.Forms/Factories/WaveConditionsChartDataPointsFactory.cs (.../WaveConditionsChartDataPointsFactory.cs) (revision fb7d1c7fd44684526a1a9ab6ec9b0b6f0e18fe73) @@ -20,10 +20,11 @@ // All rights reserved. using System.Linq; +using Core.Common.Base.Data; using Core.Common.Base.Geometry; using Core.Components.Charting.Data; +using Ringtoets.Common.Data.DikeProfiles; using Ringtoets.Common.Forms.Factories; -using Ringtoets.Common.Forms.Views; using Ringtoets.Revetment.Data; namespace Ringtoets.Revetment.Forms.Factories @@ -51,5 +52,81 @@ ? input.ForeshoreGeometry.ToArray() : new Point2D[0]; } + + /// + /// Create revetment geometry points in 2D space based on the provided . + /// + /// The to create the revetment geometry points for. + /// An array of points in 2D space or an empty array when: + /// + /// is null; + /// the is not set; + /// the is not set; + /// + /// + public static Point2D[] CreateRevetmentGeometryPoints(WaveConditionsInput input) + { + if (input == null + || double.IsNaN(input.LowerBoundaryRevetment) + || double.IsNaN(input.UpperBoundaryRevetment)) + { + return new Point2D[0]; + } + + Point2D baseStartPoint = GetBaseStartPoint(input); + + double startPointX = (input.LowerBoundaryRevetment - baseStartPoint.Y) / 3; + RoundedDouble heightDiff = input.UpperBoundaryRevetment - input.LowerBoundaryRevetment; + + return new[] + { + new Point2D(startPointX + baseStartPoint.X, input.LowerBoundaryRevetment), + new Point2D(heightDiff / 3 + startPointX, input.UpperBoundaryRevetment) + }; + } + + /// + /// Create revetment base geometry points in 2D space based on the provided . + /// + /// The to create the revetment base geometry points for. + /// An array of points in 2D space or an empty array when: + /// + /// is null; + /// the is not set; + /// the is not set; + /// + /// + public static Point2D[] CreateRevetmentBaseGeometryPoints(WaveConditionsInput input) + { + if (input == null + || double.IsNaN(input.LowerBoundaryRevetment) + || double.IsNaN(input.UpperBoundaryRevetment)) + { + return new Point2D[0]; + } + + Point2D startPoint = GetBaseStartPoint(input); + + double heightDiff = input.LowerBoundaryRevetment - startPoint.Y; + + return new[] + { + new Point2D(startPoint.X, startPoint.Y), + new Point2D(heightDiff / 3 + startPoint.X, input.LowerBoundaryRevetment) + }; + } + + private static Point2D GetBaseStartPoint(WaveConditionsInput input) + { + double startPointX = input.ForeshoreProfile != null + ? input.ForeshoreGeometry.Last().X + : 0; + + double startPointY = input.ForeshoreProfile != null + ? input.ForeshoreGeometry.Last().Y + : 0; + + return new Point2D(startPointX, startPointY); + } } } \ No newline at end of file Index: Ringtoets/Revetment/test/Ringtoets.Revetment.Forms.Test/Factories/WaveConditionsChartDataFactoryTest.cs =================================================================== diff -u -rf1f94637a6b45b394493bf16a078b317c02d329b -rfb7d1c7fd44684526a1a9ab6ec9b0b6f0e18fe73 --- Ringtoets/Revetment/test/Ringtoets.Revetment.Forms.Test/Factories/WaveConditionsChartDataFactoryTest.cs (.../WaveConditionsChartDataFactoryTest.cs) (revision f1f94637a6b45b394493bf16a078b317c02d329b) +++ Ringtoets/Revetment/test/Ringtoets.Revetment.Forms.Test/Factories/WaveConditionsChartDataFactoryTest.cs (.../WaveConditionsChartDataFactoryTest.cs) (revision fb7d1c7fd44684526a1a9ab6ec9b0b6f0e18fe73) @@ -70,6 +70,18 @@ } [Test] + public void CreateRevetmentBaseChartData_ReturnsEmptyChartLineDataWithDefaultStyling() + { + // Call + ChartLineData data = WaveConditionsChartDataFactory.CreateRevetmentBaseChartData(); + + // Assert + Assert.IsEmpty(data.Points); + Assert.AreEqual("Bekleding", data.Name); + AssertEqualStyle(data.Style, Color.Gray, 2, DashStyle.Dash); + } + + [Test] public void UpdateForeshoreGeometryChartDataName_InputNull_NameSetToDefaultName() { // Setup Index: Ringtoets/Revetment/test/Ringtoets.Revetment.Forms.Test/Factories/WaveConditionsChartDataPointsFactoryTest.cs =================================================================== diff -u -rf1f94637a6b45b394493bf16a078b317c02d329b -rfb7d1c7fd44684526a1a9ab6ec9b0b6f0e18fe73 --- Ringtoets/Revetment/test/Ringtoets.Revetment.Forms.Test/Factories/WaveConditionsChartDataPointsFactoryTest.cs (.../WaveConditionsChartDataPointsFactoryTest.cs) (revision f1f94637a6b45b394493bf16a078b317c02d329b) +++ Ringtoets/Revetment/test/Ringtoets.Revetment.Forms.Test/Factories/WaveConditionsChartDataPointsFactoryTest.cs (.../WaveConditionsChartDataPointsFactoryTest.cs) (revision fb7d1c7fd44684526a1a9ab6ec9b0b6f0e18fe73) @@ -19,6 +19,9 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System.Collections.Generic; +using System.Linq; +using Core.Common.Base.Data; using Core.Common.Base.Geometry; using NUnit.Framework; using Ringtoets.Common.Data.TestUtil; @@ -41,7 +44,7 @@ } [Test] - public void CreateForeshoreGeometryPoints_DikeProfileNull_ReturnsEmptyPointsArray() + public void CreateForeshoreGeometryPoints_ForeshoreProfileNull_ReturnsEmptyPointsArray() { // Setup var input = new WaveConditionsInput @@ -57,7 +60,7 @@ } [Test] - public void CreateForeshoreGeometryPoints_DikeProfileSetUseForeshoreFalse_ReturnsEmptyPointsArray() + public void CreateForeshoreGeometryPoints_ForeshoreProfileSetUseForeshoreFalse_ReturnsEmptyPointsArray() { // Setup var input = new WaveConditionsInput @@ -78,7 +81,7 @@ } [Test] - public void CreateForeshoreGeometryPoints_DikeProfileSetUseForeshoreTrue_ReturnsForeshoreGeometryPointsArray() + public void CreateForeshoreGeometryPoints_ForeshoreProfileSetUseForeshoreTrue_ReturnsForeshoreGeometryPointsArray() { // Setup var foreshoreGeometry = new[] @@ -98,5 +101,208 @@ // Assert CollectionAssert.AreEqual(foreshoreGeometry, points); } + + [Test] + public void CreateRevetmentGeometryPoints_InputNull_ReturnsEmptyPointsArray() + { + // Call + Point2D[] points = WaveConditionsChartDataPointsFactory.CreateRevetmentGeometryPoints(null); + + // Assert + CollectionAssert.IsEmpty(points); + } + + [Test] + [TestCaseSource(nameof(GetInputWithoutRevetmentBoundaries), new object[] + { + "CreateRevetmentGeometryPoints_BoundariesNotSet_ReturnsEmptyPointsArray({0})" + })] + public void CreateRevetmentGeometryPoints_BoundariesNotSet_ReturnsEmptyPointsArray(WaveConditionsInput input) + { + // Call + Point2D[] points = WaveConditionsChartDataPointsFactory.CreateRevetmentGeometryPoints(input); + + // Assert + CollectionAssert.IsEmpty(points); + } + + [Test] + public void CreateRevetmentGeometryPoints_InputWithoutForeshoreProfile_ReturnRevetmentGeometryPointsArray() + { + // Setup + const double lowerBoundaryRevetment = 2; + const double upperBoundaryRevetment = 8; + + var input = new WaveConditionsInput + { + LowerBoundaryRevetment = (RoundedDouble) lowerBoundaryRevetment, + UpperBoundaryRevetment = (RoundedDouble) upperBoundaryRevetment + }; + + // Call + Point2D[] points = WaveConditionsChartDataPointsFactory.CreateRevetmentGeometryPoints(input); + + // Assert + CollectionAssert.AreEqual(new[] + { + new Point2D(lowerBoundaryRevetment / 3, 2), + new Point2D(upperBoundaryRevetment / 3, 8) + }, points); + } + + [Test] + [TestCaseSource(nameof(GetForeshoreProfileGeometries), new object[] + { + "CreateRevetmentGeometryPoints_InputWithForeshoreProfile_ReturnRevetmentGeometryPointsArray({0})" + })] + public void CreateRevetmentGeometryPoints_InputWithForeshoreProfile_ReturnRevetmentGeometryPointsArray( + IEnumerable foreshoreProfileGeometry) + { + // Setup + const double lowerBoundaryRevetment = 2; + const double upperBoundaryRevetment = 8; + + var input = new WaveConditionsInput + { + LowerBoundaryRevetment = (RoundedDouble) lowerBoundaryRevetment, + UpperBoundaryRevetment = (RoundedDouble) upperBoundaryRevetment, + ForeshoreProfile = new TestForeshoreProfile(foreshoreProfileGeometry) + }; + + // Call + Point2D[] points = WaveConditionsChartDataPointsFactory.CreateRevetmentGeometryPoints(input); + + // Assert + Point2D lastGeometryPoint = foreshoreProfileGeometry.Last(); + + double startPointX = (lowerBoundaryRevetment - lastGeometryPoint.Y) / 3; + const double deltaY = upperBoundaryRevetment - lowerBoundaryRevetment; + var expectedGeometry = new[] + { + new Point2D(startPointX + lastGeometryPoint.X, lowerBoundaryRevetment), + new Point2D(deltaY / 3 + startPointX, upperBoundaryRevetment) + }; + + CollectionAssert.AreEqual(expectedGeometry, points); + } + + [Test] + public void CreateRevetmentBaseGeometryPoints_InputNull_ReturnsEmptyPointsArray() + { + // Call + Point2D[] points = WaveConditionsChartDataPointsFactory.CreateRevetmentBaseGeometryPoints(null); + + // Assert + CollectionAssert.IsEmpty(points); + } + + [Test] + [TestCaseSource(nameof(GetInputWithoutRevetmentBoundaries), new object[] + { + "CreateRevetmentBaseGeometryPoints_BoundariesNotSet_ReturnsEmptyPointsArray({0})" + })] + public void CreateRevetmentBaseGeometryPoints_BoundariesNotSet_ReturnsEmptyPointsArray(WaveConditionsInput input) + { + // Call + Point2D[] points = WaveConditionsChartDataPointsFactory.CreateRevetmentGeometryPoints(input); + + // Assert + CollectionAssert.IsEmpty(points); + } + + [Test] + public void CreateRevetmentBaseGeometryPoints_InputWithoutForeshoreProfile_ReturnRevetmentBaseGeometryPointsArray() + { + // Setup + const double lowerBoundaryRevetment = 2; + const double upperBoundaryRevetment = 8; + + var input = new WaveConditionsInput + { + LowerBoundaryRevetment = (RoundedDouble)lowerBoundaryRevetment, + UpperBoundaryRevetment = (RoundedDouble)upperBoundaryRevetment + }; + + // Call + Point2D[] points = WaveConditionsChartDataPointsFactory.CreateRevetmentBaseGeometryPoints(input); + + // Assert + CollectionAssert.AreEqual(new[] + { + new Point2D(0, 0), + new Point2D(lowerBoundaryRevetment / 3, 2) + }, points); + } + + + [Test] + [TestCaseSource(nameof(GetForeshoreProfileGeometries), new object[] + { + "CreateRevetmentBaseGeometryPoints_InputWithForeshoreProfile_ReturnRevetmentBaseGeometryPointsArray({0})" + })] + public void CreateRevetmentBaseGeometryPoints_InputWithForeshoreProfile_ReturnRevetmentBaseGeometryPointsArray( + IEnumerable foreshoreProfileGeometry) + { + // Setup + const double lowerBoundaryRevetment = 2; + const double upperBoundaryRevetment = 8; + + var input = new WaveConditionsInput + { + LowerBoundaryRevetment = (RoundedDouble)lowerBoundaryRevetment, + UpperBoundaryRevetment = (RoundedDouble)upperBoundaryRevetment, + ForeshoreProfile = new TestForeshoreProfile(foreshoreProfileGeometry) + }; + + // Call + Point2D[] points = WaveConditionsChartDataPointsFactory.CreateRevetmentBaseGeometryPoints(input); + + // Assert + Point2D lastGeometryPoint = foreshoreProfileGeometry.Last(); + double deltaY = input.LowerBoundaryRevetment - lastGeometryPoint.Y; + + var expectedGeometry = new[] + { + new Point2D(lastGeometryPoint.X, lastGeometryPoint.Y), + new Point2D(deltaY / 3 + lastGeometryPoint.X, input.LowerBoundaryRevetment) + }; + + CollectionAssert.AreEqual(expectedGeometry, points); + } + + private static IEnumerable GetInputWithoutRevetmentBoundaries(string testNameFormat) + { + yield return new TestCaseData(new WaveConditionsInput()) + .SetName(string.Format(testNameFormat, "NoRevetmentBoundaries")); + yield return new TestCaseData(new WaveConditionsInput + { + LowerBoundaryRevetment = (RoundedDouble) 2 + }).SetName(string.Format(testNameFormat, "LowerBoundaryRevetmentSet")); + yield return new TestCaseData(new WaveConditionsInput + { + UpperBoundaryRevetment = (RoundedDouble) 7 + }).SetName(string.Format(testNameFormat, "UpperBoundaryRevetmentSet")); + } + + private static IEnumerable GetForeshoreProfileGeometries(string testNameFormat) + { + yield return new TestCaseData(new List + { + new Point2D(-10, -10), + new Point2D(-8, -7), + new Point2D(-5, -2) + }).SetName(string.Format(testNameFormat, "ForeshoreProfileNegativeCoordinates")); + yield return new TestCaseData(new List + { + new Point2D(-10, -10), + new Point2D(0, 0) + }).SetName(string.Format(testNameFormat, "ForeshoreProfileEndingOnOrigin")); + yield return new TestCaseData(new List + { + new Point2D(1, 1), + new Point2D(3, 5), + new Point2D(10, 7) + }).SetName(string.Format(testNameFormat, "ForeshoreProfilePositiveCoordinates")); + } } } \ No newline at end of file