Index: DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.LayerCreator.Tests/Deltares.LayerOnSlopeTool.LayerCreator.Tests.csproj =================================================================== diff -u -r3183 -r3185 --- DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.LayerCreator.Tests/Deltares.LayerOnSlopeTool.LayerCreator.Tests.csproj (.../Deltares.LayerOnSlopeTool.LayerCreator.Tests.csproj) (revision 3183) +++ DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.LayerCreator.Tests/Deltares.LayerOnSlopeTool.LayerCreator.Tests.csproj (.../Deltares.LayerOnSlopeTool.LayerCreator.Tests.csproj) (revision 3185) @@ -30,6 +30,7 @@ + Index: DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.LayerCreator/LayerCreator.cs =================================================================== diff -u -r3183 -r3185 --- DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.LayerCreator/LayerCreator.cs (.../LayerCreator.cs) (revision 3183) +++ DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.LayerCreator/LayerCreator.cs (.../LayerCreator.cs) (revision 3185) @@ -201,7 +201,8 @@ private SurfaceLine DetermineSurfaceLineForGivenLayerData(SurfaceLine originalSurfaceLine, double layerThickness) { - return originalSurfaceLine.CreateLoweredSurfaceLineForGivenLayerThickness(layerThickness); + var surfacelineProcessor = new SurfacelineProcessor(originalSurfaceLine); + return surfacelineProcessor.CreateLoweredSurfaceLine(layerThickness); } } Index: DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.LayerCreator.Tests/SurfacelineProcessorTests.cs =================================================================== diff -u --- DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.LayerCreator.Tests/SurfacelineProcessorTests.cs (revision 0) +++ DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.LayerCreator.Tests/SurfacelineProcessorTests.cs (revision 3185) @@ -0,0 +1,253 @@ +// Copyright (C) Stichting Deltares 2020. All rights reserved. +// +// This file is part of the Dam Engine. +// +// The Dam Engine is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using Deltares.LayerOnSlopeTool.Data; +using NUnit.Framework; + +namespace Deltares.LayerOnSlopeTool.LayerCreator.Tests +{ + [TestFixture] + public class SurfacelineProcessorTests + { + private const double tolerance = 0.001; + + [Test] + public void TestDetermineLoweredSurfaceLineForGivenLayerThickness() + { + var originalSurfaceLine = CreateSimpleStraightSurfaceLine(); + var surfacelineProcessor = new SurfacelineProcessor(originalSurfaceLine); + var loweredSurfaceLine = surfacelineProcessor.CreateLoweredSurfaceLine(1); + Assert.AreEqual(11, loweredSurfaceLine.SurfaceLinePoints.Count); + Assert.AreEqual(0, loweredSurfaceLine.SurfaceLinePoints[0].XCoordinate, tolerance); + Assert.AreEqual(0, loweredSurfaceLine.SurfaceLinePoints[0].ZCoordinate, tolerance); + Assert.AreEqual(5, loweredSurfaceLine.SurfaceLinePoints[1].XCoordinate, tolerance); + Assert.AreEqual(0, loweredSurfaceLine.SurfaceLinePoints[1].ZCoordinate, tolerance); + Assert.AreEqual(10, loweredSurfaceLine.SurfaceLinePoints[2].XCoordinate, tolerance); + Assert.AreEqual(0, loweredSurfaceLine.SurfaceLinePoints[2].ZCoordinate, tolerance); + Assert.AreEqual(12, loweredSurfaceLine.SurfaceLinePoints[3].XCoordinate, tolerance); + Assert.AreEqual(0, loweredSurfaceLine.SurfaceLinePoints[3].ZCoordinate, tolerance); + Assert.AreEqual(14, loweredSurfaceLine.SurfaceLinePoints[4].XCoordinate, tolerance); + Assert.AreEqual(0, loweredSurfaceLine.SurfaceLinePoints[4].ZCoordinate, tolerance); + Assert.AreEqual(14.01, loweredSurfaceLine.SurfaceLinePoints[5].XCoordinate, tolerance); + Assert.AreEqual(-1, loweredSurfaceLine.SurfaceLinePoints[5].ZCoordinate, tolerance); + Assert.AreEqual(15, loweredSurfaceLine.SurfaceLinePoints[6].XCoordinate, tolerance); + Assert.AreEqual(-1, loweredSurfaceLine.SurfaceLinePoints[6].ZCoordinate, tolerance); + Assert.AreEqual(15.99, loweredSurfaceLine.SurfaceLinePoints[7].XCoordinate, tolerance); + Assert.AreEqual(-1, loweredSurfaceLine.SurfaceLinePoints[7].ZCoordinate, tolerance); + Assert.AreEqual(16, loweredSurfaceLine.SurfaceLinePoints[8].XCoordinate, tolerance); + Assert.AreEqual(0, loweredSurfaceLine.SurfaceLinePoints[8].ZCoordinate, tolerance); + Assert.AreEqual(22, loweredSurfaceLine.SurfaceLinePoints[9].XCoordinate, tolerance); + Assert.AreEqual(0, loweredSurfaceLine.SurfaceLinePoints[9].ZCoordinate, tolerance); + Assert.AreEqual(30, loweredSurfaceLine.SurfaceLinePoints[10].XCoordinate, tolerance); + Assert.AreEqual(0, loweredSurfaceLine.SurfaceLinePoints[10].ZCoordinate, tolerance); + + } + + [Test] + public void TestDetermineLoweredSurfaceLineForGivenLayerThicknessWithAckwardPoints() + { + var originalSurfaceLine = CreateSimpleStraightSurfaceLineWithAckwardPoints(); + var surfacelineProcessor = new SurfacelineProcessor(originalSurfaceLine); + var loweredSurfaceLine = surfacelineProcessor.CreateLoweredSurfaceLine(1); + Assert.AreEqual(11, loweredSurfaceLine.SurfaceLinePoints.Count); + Assert.AreEqual(0, loweredSurfaceLine.SurfaceLinePoints[0].XCoordinate, tolerance); + Assert.AreEqual(0, loweredSurfaceLine.SurfaceLinePoints[0].ZCoordinate, tolerance); + Assert.AreEqual(5, loweredSurfaceLine.SurfaceLinePoints[1].XCoordinate, tolerance); + Assert.AreEqual(0, loweredSurfaceLine.SurfaceLinePoints[1].ZCoordinate, tolerance); + Assert.AreEqual(10, loweredSurfaceLine.SurfaceLinePoints[2].XCoordinate, tolerance); + Assert.AreEqual(0, loweredSurfaceLine.SurfaceLinePoints[2].ZCoordinate, tolerance); + Assert.AreEqual(12, loweredSurfaceLine.SurfaceLinePoints[3].XCoordinate, tolerance); + Assert.AreEqual(0, loweredSurfaceLine.SurfaceLinePoints[3].ZCoordinate, tolerance); + Assert.AreEqual(14, loweredSurfaceLine.SurfaceLinePoints[4].XCoordinate, tolerance); + Assert.AreEqual(0, loweredSurfaceLine.SurfaceLinePoints[4].ZCoordinate, tolerance); + Assert.AreEqual(14.01, loweredSurfaceLine.SurfaceLinePoints[5].XCoordinate, tolerance); + Assert.AreEqual(-1, loweredSurfaceLine.SurfaceLinePoints[5].ZCoordinate, tolerance); + Assert.AreEqual(15.5, loweredSurfaceLine.SurfaceLinePoints[6].XCoordinate, tolerance); + Assert.AreEqual(-1, loweredSurfaceLine.SurfaceLinePoints[6].ZCoordinate, tolerance); + Assert.AreEqual(15.99, loweredSurfaceLine.SurfaceLinePoints[7].XCoordinate, tolerance); + Assert.AreEqual(-1, loweredSurfaceLine.SurfaceLinePoints[7].ZCoordinate, tolerance); + Assert.AreEqual(16, loweredSurfaceLine.SurfaceLinePoints[8].XCoordinate, tolerance); + Assert.AreEqual(0, loweredSurfaceLine.SurfaceLinePoints[8].ZCoordinate, tolerance); + Assert.AreEqual(22, loweredSurfaceLine.SurfaceLinePoints[9].XCoordinate, tolerance); + Assert.AreEqual(0, loweredSurfaceLine.SurfaceLinePoints[9].ZCoordinate, tolerance); + Assert.AreEqual(30, loweredSurfaceLine.SurfaceLinePoints[10].XCoordinate, tolerance); + Assert.AreEqual(0, loweredSurfaceLine.SurfaceLinePoints[10].ZCoordinate, tolerance); + + } + + private SurfaceLine CreateSimpleStraightSurfaceLine() + { + var surfaceLine = new SurfaceLine(); + surfaceLine.SurfaceLineId = "SimpleStraightSurfaceLine"; + var point = new SurfaceLinePoint + { + XCoordinate = 0, + ZCoordinate = 0, + PointType = CharacteristicPointType.SurfaceLevelOutside + }; + surfaceLine.SurfaceLinePoints.Add(point); + var pointA = new SurfaceLinePoint + { + XCoordinate = 5, + ZCoordinate = 0, + PointType = CharacteristicPointType.None + }; + surfaceLine.SurfaceLinePoints.Add(pointA); + var point1 = new SurfaceLinePoint + { + XCoordinate = 10, + ZCoordinate = 0, + PointType = CharacteristicPointType.DikeToeAtRiver + }; + surfaceLine.SurfaceLinePoints.Add(point1); + var point2 = new SurfaceLinePoint + { + XCoordinate = 12, + ZCoordinate = 0, + PointType = CharacteristicPointType.DikeTopAtRiver + }; + surfaceLine.SurfaceLinePoints.Add(point2); + var point3 = new SurfaceLinePoint + { + XCoordinate = 14, + ZCoordinate = 0, + PointType = CharacteristicPointType.DikeTopAtPolder + }; + surfaceLine.SurfaceLinePoints.Add(point3); + var point3A = new SurfaceLinePoint + { + XCoordinate = 15, + ZCoordinate = 0, + PointType = CharacteristicPointType.None + }; + surfaceLine.SurfaceLinePoints.Add(point3A); + var point4 = new SurfaceLinePoint + { + XCoordinate = 16, + ZCoordinate = 0, + PointType = CharacteristicPointType.DikeToeAtPolder + }; + surfaceLine.SurfaceLinePoints.Add(point4); + var point4A = new SurfaceLinePoint + { + XCoordinate = 22, + ZCoordinate = 0, + PointType = CharacteristicPointType.None + }; + surfaceLine.SurfaceLinePoints.Add(point4A); + var point5 = new SurfaceLinePoint + { + XCoordinate = 30, + ZCoordinate = 0, + PointType = CharacteristicPointType.SurfaceLevelInside + }; + surfaceLine.SurfaceLinePoints.Add(point5); + return surfaceLine; + } + + private SurfaceLine CreateSimpleStraightSurfaceLineWithAckwardPoints() + { + var surfaceLine = new SurfaceLine(); + surfaceLine.SurfaceLineId = "SimpleStraightSurfaceLine"; + var point = new SurfaceLinePoint + { + XCoordinate = 0, + ZCoordinate = 0, + PointType = CharacteristicPointType.SurfaceLevelOutside + }; + surfaceLine.SurfaceLinePoints.Add(point); + var pointA = new SurfaceLinePoint + { + XCoordinate = 5, + ZCoordinate = 0, + PointType = CharacteristicPointType.None + }; + surfaceLine.SurfaceLinePoints.Add(pointA); + var point1 = new SurfaceLinePoint + { + XCoordinate = 10, + ZCoordinate = 0, + PointType = CharacteristicPointType.DikeToeAtRiver + }; + surfaceLine.SurfaceLinePoints.Add(point1); + var point2 = new SurfaceLinePoint + { + XCoordinate = 12, + ZCoordinate = 0, + PointType = CharacteristicPointType.DikeTopAtRiver + }; + surfaceLine.SurfaceLinePoints.Add(point2); + var point3 = new SurfaceLinePoint + { + XCoordinate = 14, + ZCoordinate = 0, + PointType = CharacteristicPointType.DikeTopAtPolder + }; + surfaceLine.SurfaceLinePoints.Add(point3); + var point3A = new SurfaceLinePoint + { + // is less than 0.01 meter beyond the point that is to be lowered with offset of 0.01 m. So this point should NOT be found in the lowered line + XCoordinate = 14.001, + ZCoordinate = 0, + PointType = CharacteristicPointType.None + }; + surfaceLine.SurfaceLinePoints.Add(point3A); + var point3B = new SurfaceLinePoint + { + // make this 15.5 instead of 15 to be different from ordinary SimpleStraightSurfaceLine. + XCoordinate = 15.5, + ZCoordinate = 0, + PointType = CharacteristicPointType.None + }; + surfaceLine.SurfaceLinePoints.Add(point3B); + var point3C = new SurfaceLinePoint + { + // is less than 0.01 meter in front off the point that is to be lowered with offset of -0.01 m. So this point should NOT be found in the lowered line + XCoordinate = 15.999, + ZCoordinate = 0, + PointType = CharacteristicPointType.None + }; + surfaceLine.SurfaceLinePoints.Add(point3C); + var point4 = new SurfaceLinePoint + { + XCoordinate = 16, + ZCoordinate = 0, + PointType = CharacteristicPointType.DikeToeAtPolder + }; + surfaceLine.SurfaceLinePoints.Add(point4); + var point4A = new SurfaceLinePoint + { + XCoordinate = 22, + ZCoordinate = 0, + PointType = CharacteristicPointType.None + }; + surfaceLine.SurfaceLinePoints.Add(point4A); + var point5 = new SurfaceLinePoint + { + XCoordinate = 30, + ZCoordinate = 0, + PointType = CharacteristicPointType.SurfaceLevelInside + }; + surfaceLine.SurfaceLinePoints.Add(point5); + return surfaceLine; + } + } +} \ No newline at end of file Index: DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.LayerCreator/Deltares.LayerOnSlopeTool.LayerCreator.csproj =================================================================== diff -u -r3183 -r3185 --- DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.LayerCreator/Deltares.LayerOnSlopeTool.LayerCreator.csproj (.../Deltares.LayerOnSlopeTool.LayerCreator.csproj) (revision 3183) +++ DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.LayerCreator/Deltares.LayerOnSlopeTool.LayerCreator.csproj (.../Deltares.LayerOnSlopeTool.LayerCreator.csproj) (revision 3185) @@ -46,6 +46,7 @@ + Index: DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.Data/SurfaceLine.cs =================================================================== diff -u -r3184 -r3185 --- DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.Data/SurfaceLine.cs (.../SurfaceLine.cs) (revision 3184) +++ DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.Data/SurfaceLine.cs (.../SurfaceLine.cs) (revision 3185) @@ -19,7 +19,6 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. -using System; using System.Collections.Generic; namespace Deltares.LayerOnSlopeTool.Data @@ -88,92 +87,5 @@ return surfaceLinePoint; } - /// - /// Creates the lowered surface line for given layer thickness. - /// - /// The layer thickness. - /// - public SurfaceLine CreateLoweredSurfaceLineForGivenLayerThickness(double layerThickness) - { - const double tolerance = 1e-4; - const double horizontalOffset = 0.01; - var loweredSurfaceLine = new SurfaceLine(); - var dikeTopPolder = GetSurfaceLinePointByType(CharacteristicPointType.DikeTopAtPolder); - var dikeToePolder = GetSurfaceLinePointByType(CharacteristicPointType.DikeToeAtPolder); - foreach (var point in SurfaceLinePoints) - { - if (point.XCoordinate <= dikeTopPolder.XCoordinate) - { - HandlePointsUpToAndIncludingDikeTopPolder(layerThickness, point, loweredSurfaceLine, dikeTopPolder, tolerance, horizontalOffset); - } - else - { - // Handle all points between dike top polder and dike toe polder (taking into account the horizontal offset). - if (point.XCoordinate > dikeTopPolder.XCoordinate + horizontalOffset && point.XCoordinate < dikeToePolder.XCoordinate - horizontalOffset) - { - var newPointLowered = new SurfaceLinePoint - { - XCoordinate = point.XCoordinate, - ZCoordinate = point.ZCoordinate - layerThickness, - PointType = point.PointType - }; - loweredSurfaceLine.SurfaceLinePoints.Add(newPointLowered); - } - else - { - HandlePointsAtDikeToePolderAndBeyond(layerThickness, point, dikeToePolder, tolerance, horizontalOffset, loweredSurfaceLine); - } - } - } - return loweredSurfaceLine; - } - - private static void HandlePointsAtDikeToePolderAndBeyond(double layerThickness, SurfaceLinePoint point, - SurfaceLinePoint dikeToePolder, double tolerance, double horizontalOffset, SurfaceLine loweredSurfaceLine) - { - if (Math.Abs(point.XCoordinate - dikeToePolder.XCoordinate) < tolerance) - { - var newPointAtDikeToe = new SurfaceLinePoint - { - XCoordinate = point.XCoordinate - horizontalOffset, - ZCoordinate = point.ZCoordinate - layerThickness, - PointType = CharacteristicPointType.None - }; - loweredSurfaceLine.SurfaceLinePoints.Add(newPointAtDikeToe); - } - - if (point.XCoordinate >= dikeToePolder.XCoordinate) - { - var newPointBeyondDikeToe = new SurfaceLinePoint - { - XCoordinate = point.XCoordinate, - ZCoordinate = point.ZCoordinate, - PointType = point.PointType - }; - loweredSurfaceLine.SurfaceLinePoints.Add(newPointBeyondDikeToe); - } - } - - private static void HandlePointsUpToAndIncludingDikeTopPolder(double layerThickness, SurfaceLinePoint point, - SurfaceLine loweredSurfaceLine, SurfaceLinePoint dikeTopPolder, double tolerance, double horizontalOffset) - { - var newPointUpToDikeTop = new SurfaceLinePoint - { - XCoordinate = point.XCoordinate, - ZCoordinate = point.ZCoordinate, - PointType = point.PointType - }; - loweredSurfaceLine.SurfaceLinePoints.Add(newPointUpToDikeTop); - if (Math.Abs(point.XCoordinate - dikeTopPolder.XCoordinate) < tolerance) - { - var newPointAtDikeTop = new SurfaceLinePoint - { - XCoordinate = point.XCoordinate + horizontalOffset, - ZCoordinate = point.ZCoordinate - layerThickness, - PointType = CharacteristicPointType.None - }; - loweredSurfaceLine.SurfaceLinePoints.Add(newPointAtDikeTop); - } - } } } \ No newline at end of file Index: DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.LayerCreator.Tests/LayerCreatorTests.cs =================================================================== diff -u -r3184 -r3185 --- DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.LayerCreator.Tests/LayerCreatorTests.cs (.../LayerCreatorTests.cs) (revision 3184) +++ DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.LayerCreator.Tests/LayerCreatorTests.cs (.../LayerCreatorTests.cs) (revision 3185) @@ -112,220 +112,5 @@ Assert.IsTrue(lines[0].Contains("Handling location")); } - [Test] - public void TestDetermineLoweredSurfaceLineForGivenLayerThickness() - { - var originalSurfaceLine = CreateSimpleStraightSurfaceLine(); - var loweredSurfaceLine = originalSurfaceLine.CreateLoweredSurfaceLineForGivenLayerThickness(1); - Assert.AreEqual(11,loweredSurfaceLine.SurfaceLinePoints.Count); - Assert.AreEqual(0, loweredSurfaceLine.SurfaceLinePoints[0].XCoordinate, Diff); - Assert.AreEqual(0, loweredSurfaceLine.SurfaceLinePoints[0].ZCoordinate, Diff); - Assert.AreEqual(5, loweredSurfaceLine.SurfaceLinePoints[1].XCoordinate, Diff); - Assert.AreEqual(0, loweredSurfaceLine.SurfaceLinePoints[1].ZCoordinate, Diff); - Assert.AreEqual(10, loweredSurfaceLine.SurfaceLinePoints[2].XCoordinate, Diff); - Assert.AreEqual(0, loweredSurfaceLine.SurfaceLinePoints[2].ZCoordinate, Diff); - Assert.AreEqual(12, loweredSurfaceLine.SurfaceLinePoints[3].XCoordinate, Diff); - Assert.AreEqual(0, loweredSurfaceLine.SurfaceLinePoints[3].ZCoordinate, Diff); - Assert.AreEqual(14, loweredSurfaceLine.SurfaceLinePoints[4].XCoordinate, Diff); - Assert.AreEqual(0, loweredSurfaceLine.SurfaceLinePoints[4].ZCoordinate, Diff); - Assert.AreEqual(14.01, loweredSurfaceLine.SurfaceLinePoints[5].XCoordinate, Diff); - Assert.AreEqual(-1, loweredSurfaceLine.SurfaceLinePoints[5].ZCoordinate, Diff); - Assert.AreEqual(15, loweredSurfaceLine.SurfaceLinePoints[6].XCoordinate, Diff); - Assert.AreEqual(-1, loweredSurfaceLine.SurfaceLinePoints[6].ZCoordinate, Diff); - Assert.AreEqual(15.99, loweredSurfaceLine.SurfaceLinePoints[7].XCoordinate, Diff); - Assert.AreEqual(-1, loweredSurfaceLine.SurfaceLinePoints[7].ZCoordinate, Diff); - Assert.AreEqual(16, loweredSurfaceLine.SurfaceLinePoints[8].XCoordinate, Diff); - Assert.AreEqual(0, loweredSurfaceLine.SurfaceLinePoints[8].ZCoordinate, Diff); - Assert.AreEqual(22, loweredSurfaceLine.SurfaceLinePoints[9].XCoordinate, Diff); - Assert.AreEqual(0, loweredSurfaceLine.SurfaceLinePoints[9].ZCoordinate, Diff); - Assert.AreEqual(30, loweredSurfaceLine.SurfaceLinePoints[10].XCoordinate, Diff); - Assert.AreEqual(0, loweredSurfaceLine.SurfaceLinePoints[10].ZCoordinate, Diff); - - } - - [Test] - public void TestDetermineLoweredSurfaceLineForGivenLayerThicknessWithAckwardPoints() - { - var originalSurfaceLine = CreateSimpleStraightSurfaceLineWithAckwardPoints(); - var loweredSurfaceLine = originalSurfaceLine.CreateLoweredSurfaceLineForGivenLayerThickness(1); - Assert.AreEqual(11, loweredSurfaceLine.SurfaceLinePoints.Count); - Assert.AreEqual(0, loweredSurfaceLine.SurfaceLinePoints[0].XCoordinate, Diff); - Assert.AreEqual(0, loweredSurfaceLine.SurfaceLinePoints[0].ZCoordinate, Diff); - Assert.AreEqual(5, loweredSurfaceLine.SurfaceLinePoints[1].XCoordinate, Diff); - Assert.AreEqual(0, loweredSurfaceLine.SurfaceLinePoints[1].ZCoordinate, Diff); - Assert.AreEqual(10, loweredSurfaceLine.SurfaceLinePoints[2].XCoordinate, Diff); - Assert.AreEqual(0, loweredSurfaceLine.SurfaceLinePoints[2].ZCoordinate, Diff); - Assert.AreEqual(12, loweredSurfaceLine.SurfaceLinePoints[3].XCoordinate, Diff); - Assert.AreEqual(0, loweredSurfaceLine.SurfaceLinePoints[3].ZCoordinate, Diff); - Assert.AreEqual(14, loweredSurfaceLine.SurfaceLinePoints[4].XCoordinate, Diff); - Assert.AreEqual(0, loweredSurfaceLine.SurfaceLinePoints[4].ZCoordinate, Diff); - Assert.AreEqual(14.01, loweredSurfaceLine.SurfaceLinePoints[5].XCoordinate, Diff); - Assert.AreEqual(-1, loweredSurfaceLine.SurfaceLinePoints[5].ZCoordinate, Diff); - Assert.AreEqual(15.5, loweredSurfaceLine.SurfaceLinePoints[6].XCoordinate, Diff); - Assert.AreEqual(-1, loweredSurfaceLine.SurfaceLinePoints[6].ZCoordinate, Diff); - Assert.AreEqual(15.99, loweredSurfaceLine.SurfaceLinePoints[7].XCoordinate, Diff); - Assert.AreEqual(-1, loweredSurfaceLine.SurfaceLinePoints[7].ZCoordinate, Diff); - Assert.AreEqual(16, loweredSurfaceLine.SurfaceLinePoints[8].XCoordinate, Diff); - Assert.AreEqual(0, loweredSurfaceLine.SurfaceLinePoints[8].ZCoordinate, Diff); - Assert.AreEqual(22, loweredSurfaceLine.SurfaceLinePoints[9].XCoordinate, Diff); - Assert.AreEqual(0, loweredSurfaceLine.SurfaceLinePoints[9].ZCoordinate, Diff); - Assert.AreEqual(30, loweredSurfaceLine.SurfaceLinePoints[10].XCoordinate, Diff); - Assert.AreEqual(0, loweredSurfaceLine.SurfaceLinePoints[10].ZCoordinate, Diff); - - } - private SurfaceLine CreateSimpleStraightSurfaceLine() - { - var surfaceLine = new SurfaceLine(); - surfaceLine.SurfaceLineId = "SimpleStraightSurfaceLine"; - var point = new SurfaceLinePoint - { - XCoordinate = 0, ZCoordinate = 0, PointType = CharacteristicPointType.SurfaceLevelOutside - }; - surfaceLine.SurfaceLinePoints.Add(point); - var pointA = new SurfaceLinePoint - { - XCoordinate = 5, - ZCoordinate = 0, - PointType = CharacteristicPointType.None - }; - surfaceLine.SurfaceLinePoints.Add(pointA); - var point1 = new SurfaceLinePoint - { - XCoordinate = 10, - ZCoordinate = 0, - PointType = CharacteristicPointType.DikeToeAtRiver - }; - surfaceLine.SurfaceLinePoints.Add(point1); - var point2 = new SurfaceLinePoint - { - XCoordinate = 12, - ZCoordinate = 0, - PointType = CharacteristicPointType.DikeTopAtRiver - }; - surfaceLine.SurfaceLinePoints.Add(point2); - var point3 = new SurfaceLinePoint - { - XCoordinate = 14, - ZCoordinate = 0, - PointType = CharacteristicPointType.DikeTopAtPolder - }; - surfaceLine.SurfaceLinePoints.Add(point3); - var point3A = new SurfaceLinePoint - { - XCoordinate = 15, - ZCoordinate = 0, - PointType = CharacteristicPointType.None - }; - surfaceLine.SurfaceLinePoints.Add(point3A); - var point4 = new SurfaceLinePoint - { - XCoordinate = 16, - ZCoordinate = 0, - PointType = CharacteristicPointType.DikeToeAtPolder - }; - surfaceLine.SurfaceLinePoints.Add(point4); - var point4A = new SurfaceLinePoint - { - XCoordinate = 22, - ZCoordinate = 0, - PointType = CharacteristicPointType.None - }; - surfaceLine.SurfaceLinePoints.Add(point4A); - var point5 = new SurfaceLinePoint - { - XCoordinate = 30, - ZCoordinate = 0, - PointType = CharacteristicPointType.SurfaceLevelInside - }; - surfaceLine.SurfaceLinePoints.Add(point5); - return surfaceLine; - } - - private SurfaceLine CreateSimpleStraightSurfaceLineWithAckwardPoints() - { - var surfaceLine = new SurfaceLine(); - surfaceLine.SurfaceLineId = "SimpleStraightSurfaceLine"; - var point = new SurfaceLinePoint - { - XCoordinate = 0, - ZCoordinate = 0, - PointType = CharacteristicPointType.SurfaceLevelOutside - }; - surfaceLine.SurfaceLinePoints.Add(point); - var pointA = new SurfaceLinePoint - { - XCoordinate = 5, - ZCoordinate = 0, - PointType = CharacteristicPointType.None - }; - surfaceLine.SurfaceLinePoints.Add(pointA); - var point1 = new SurfaceLinePoint - { - XCoordinate = 10, - ZCoordinate = 0, - PointType = CharacteristicPointType.DikeToeAtRiver - }; - surfaceLine.SurfaceLinePoints.Add(point1); - var point2 = new SurfaceLinePoint - { - XCoordinate = 12, - ZCoordinate = 0, - PointType = CharacteristicPointType.DikeTopAtRiver - }; - surfaceLine.SurfaceLinePoints.Add(point2); - var point3 = new SurfaceLinePoint - { - XCoordinate = 14, - ZCoordinate = 0, - PointType = CharacteristicPointType.DikeTopAtPolder - }; - surfaceLine.SurfaceLinePoints.Add(point3); - var point3A = new SurfaceLinePoint - { - // is less than 0.01 meter beyond the point that is to be lowered with offset of 0.01 m. So this point should NOT be found in the lowered line - XCoordinate = 14.001, - ZCoordinate = 0, - PointType = CharacteristicPointType.None - }; - surfaceLine.SurfaceLinePoints.Add(point3A); - var point3B = new SurfaceLinePoint - { - // make this 15.5 instead of 15 to be different from ordinary SimpleStraightSurfaceLine. - XCoordinate = 15.5, - ZCoordinate = 0, - PointType = CharacteristicPointType.None - }; - surfaceLine.SurfaceLinePoints.Add(point3B); - var point3C = new SurfaceLinePoint - { - // is less than 0.01 meter in front off the point that is to be lowered with offset of -0.01 m. So this point should NOT be found in the lowered line - XCoordinate = 15.999, - ZCoordinate = 0, - PointType = CharacteristicPointType.None - }; - surfaceLine.SurfaceLinePoints.Add(point3C); - var point4 = new SurfaceLinePoint - { - XCoordinate = 16, - ZCoordinate = 0, - PointType = CharacteristicPointType.DikeToeAtPolder - }; - surfaceLine.SurfaceLinePoints.Add(point4); - var point4A = new SurfaceLinePoint - { - XCoordinate = 22, - ZCoordinate = 0, - PointType = CharacteristicPointType.None - }; - surfaceLine.SurfaceLinePoints.Add(point4A); - var point5 = new SurfaceLinePoint - { - XCoordinate = 30, - ZCoordinate = 0, - PointType = CharacteristicPointType.SurfaceLevelInside - }; - surfaceLine.SurfaceLinePoints.Add(point5); - return surfaceLine; - } } } \ No newline at end of file Index: DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.LayerCreator/SurfacelineProcessor.cs =================================================================== diff -u --- DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.LayerCreator/SurfacelineProcessor.cs (revision 0) +++ DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.LayerCreator/SurfacelineProcessor.cs (revision 3185) @@ -0,0 +1,134 @@ +// Copyright (C) Stichting Deltares 2019. All rights reserved. +// +// This file is part of the Dam Engine. +// +// The Dam Engine is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using Deltares.LayerOnSlopeTool.Data; + +namespace Deltares.LayerOnSlopeTool.LayerCreator +{ + /// + public class SurfacelineProcessor + { + private const double tolerance = 1e-4; + private const double horizontalOffset = 0.01; + private readonly SurfaceLine surfaceLine; + private SurfaceLinePoint dikeTopPolder; + private SurfaceLinePoint dikeToePolder; + + /// Initializes a new instance of the class. + /// The org surface line. + public SurfacelineProcessor(SurfaceLine orgSurfaceLine) + { + surfaceLine = orgSurfaceLine; + dikeTopPolder = surfaceLine.GetSurfaceLinePointByType(CharacteristicPointType.DikeTopAtPolder); + dikeToePolder = surfaceLine.GetSurfaceLinePointByType(CharacteristicPointType.DikeToeAtPolder); + + } + + /// Creates the lowered surface line. + /// The layer thickness. + /// + public SurfaceLine CreateLoweredSurfaceLine(double layerThickness) + { + var loweredSurfaceLine = new SurfaceLine(); + foreach (var point in surfaceLine.SurfaceLinePoints) + { + if (point.XCoordinate <= dikeTopPolder.XCoordinate) + { + HandlePointsUpToAndIncludingDikeTopPolder(layerThickness, point, loweredSurfaceLine); + } + else + { + if (point.XCoordinate > dikeTopPolder.XCoordinate + horizontalOffset && + point.XCoordinate < dikeToePolder.XCoordinate - horizontalOffset) + { + HandlePointsBetweenDiketopPolderAndDikeToePolder(layerThickness, point, loweredSurfaceLine); + } + else + { + HandlePointsAtDikeToePolderAndBeyond(layerThickness, point, loweredSurfaceLine); + } + } + } + return loweredSurfaceLine; + } + + private static void HandlePointsBetweenDiketopPolderAndDikeToePolder(double layerThickness, + SurfaceLinePoint point, SurfaceLine loweredSurfaceLine) + { + var newPointLowered = new SurfaceLinePoint + { + XCoordinate = point.XCoordinate, + ZCoordinate = point.ZCoordinate - layerThickness, + PointType = point.PointType + }; + loweredSurfaceLine.SurfaceLinePoints.Add(newPointLowered); + } + + private void HandlePointsAtDikeToePolderAndBeyond(double layerThickness, + SurfaceLinePoint point, SurfaceLine loweredSurfaceLine) + { + if (Math.Abs(point.XCoordinate - dikeToePolder.XCoordinate) < tolerance) + { + var newPointAtDikeToe = new SurfaceLinePoint + { + XCoordinate = point.XCoordinate - horizontalOffset, + ZCoordinate = point.ZCoordinate - layerThickness, + PointType = CharacteristicPointType.None + }; + loweredSurfaceLine.SurfaceLinePoints.Add(newPointAtDikeToe); + } + + if (point.XCoordinate >= dikeToePolder.XCoordinate) + { + var newPointBeyondDikeToe = new SurfaceLinePoint + { + XCoordinate = point.XCoordinate, + ZCoordinate = point.ZCoordinate, + PointType = point.PointType + }; + loweredSurfaceLine.SurfaceLinePoints.Add(newPointBeyondDikeToe); + } + } + + private void HandlePointsUpToAndIncludingDikeTopPolder(double layerThickness, SurfaceLinePoint point, + SurfaceLine loweredSurfaceLine) + { + var newPointUpToDikeTop = new SurfaceLinePoint + { + XCoordinate = point.XCoordinate, + ZCoordinate = point.ZCoordinate, + PointType = point.PointType + }; + loweredSurfaceLine.SurfaceLinePoints.Add(newPointUpToDikeTop); + if (Math.Abs(point.XCoordinate - dikeTopPolder.XCoordinate) < tolerance) + { + var newPointAtDikeTop = new SurfaceLinePoint + { + XCoordinate = point.XCoordinate + horizontalOffset, + ZCoordinate = point.ZCoordinate - layerThickness, + PointType = CharacteristicPointType.None + }; + loweredSurfaceLine.SurfaceLinePoints.Add(newPointAtDikeTop); + } + } + } +} \ No newline at end of file