// Copyright (C) Stichting Deltares 2025. 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.Linq; using Deltares.DamEngine.Calculators.DikesDesign; using Deltares.DamEngine.Data.General; using Deltares.DamEngine.Data.Geometry; using Deltares.DamEngine.Data.Geotechnics; using Deltares.DamEngine.Data.Standard.Validation; using Deltares.DamEngine.TestHelpers.Factories; using NUnit.Framework; namespace Deltares.DamEngine.Calculators.Tests.DikesDesign; [TestFixture] public class SurfaceLineHeightAdapterTest { [Test] public void ConstructNewSurfaceLineReturnsANewSurfaceLine() { var surfaceLine = new SurfaceLine2 { CharacteristicPoints = { GeometryMustContainPoint = true }, Geometry = new GeometryPointString() }; var location = new Location(); surfaceLine.EnsurePointOfType(0, 0, CharacteristicPointType.DikeToeAtRiver); surfaceLine.EnsurePointOfType(1, 1, CharacteristicPointType.DikeTopAtRiver); surfaceLine.EnsurePointOfType(2, 1, CharacteristicPointType.DikeTopAtPolder); surfaceLine.EnsurePointOfType(3, 0, CharacteristicPointType.DikeToeAtPolder); surfaceLine.EnsurePointOfType(100, 0, CharacteristicPointType.SurfaceLevelInside); var surfaceLineAdapter = new SurfaceLineHeightAdapter(surfaceLine, location, 0); SurfaceLine2 constructNewSurfaceLine = surfaceLineAdapter.ConstructNewSurfaceLine(1); Assert.That(constructNewSurfaceLine, Is.Not.Null); } [Test] public void AdaptedSurfaceLineHasSamePointAtToeRiver() { var surfaceLine = new SurfaceLine2 { CharacteristicPoints = { GeometryMustContainPoint = true }, Geometry = new GeometryPointString() }; var location = new Location(); const double newDikeHeight = 6.0; var pointAtToeRiver = new Point2D { X = 17, Z = 0 }; var pointAtTopRiver = new Point2D { X = 34.5, Z = 5 }; var pointAtTopPolder = new Point2D { X = 35, Z = 5 }; var pointAtToePolder = new Point2D { X = 36, Z = 0 }; surfaceLine.EnsurePointOfType(pointAtToeRiver.X, pointAtToePolder.Z, CharacteristicPointType.DikeToeAtRiver); surfaceLine.EnsurePointOfType(pointAtTopRiver.X, pointAtTopRiver.Z, CharacteristicPointType.DikeTopAtRiver); surfaceLine.EnsurePointOfType(pointAtTopPolder.X, pointAtTopPolder.Z, CharacteristicPointType.DikeTopAtPolder); surfaceLine.EnsurePointOfType(pointAtToePolder.X, pointAtToePolder.Z, CharacteristicPointType.DikeToeAtPolder); surfaceLine.EnsurePointOfType(100, 0, CharacteristicPointType.SurfaceLevelInside); var surfaceLineAdapter = new SurfaceLineHeightAdapter(surfaceLine, location, 0); SurfaceLine2 newSurfaceLine = surfaceLineAdapter.ConstructNewSurfaceLine(newDikeHeight); { Point2D newPointAtToeRiver = newSurfaceLine.CharacteristicPoints.GetPoint2D(CharacteristicPointType.DikeToeAtRiver); Assert.That(newPointAtToeRiver.LocationEquals(pointAtToeRiver), Is.True); Assert.That(newSurfaceLine.Geometry.Points.Any(p => p.LocationEquals(pointAtToeRiver)), Is.True); } } [Test] public void AdaptedSurfaceLineHasSameSlopeInside() { var line = new SurfaceLine2 { CharacteristicPoints = { GeometryMustContainPoint = true }, Geometry = new GeometryPointString() }; SurfaceLine2 surfaceLine = line; var location = new Location(); const double cToleranceSlope = 0.0001; const double newDikeHeight = 6.0; var pointAtToeRiver = new Point2D { X = 17, Z = 0 }; var pointAtTopRiver = new Point2D { X = 34.5, Z = 5 }; var pointAtTopPolder = new Point2D { X = 35, Z = 5 }; var pointAtToePolder = new Point2D { X = 36, Z = 0 }; surfaceLine.EnsurePointOfType(100, 0, CharacteristicPointType.SurfaceLevelInside); surfaceLine.EnsurePointOfType(pointAtToeRiver.X, pointAtToePolder.Z, CharacteristicPointType.DikeToeAtRiver); surfaceLine.EnsurePointOfType(pointAtTopRiver.X, pointAtTopRiver.Z, CharacteristicPointType.DikeTopAtRiver); surfaceLine.EnsurePointOfType(pointAtTopPolder.X, pointAtTopPolder.Z, CharacteristicPointType.DikeTopAtPolder); surfaceLine.EnsurePointOfType(pointAtToePolder.X, pointAtToePolder.Z, CharacteristicPointType.DikeToeAtPolder); var surfaceLineAdapter = new SurfaceLineHeightAdapter(surfaceLine, location, 0); SurfaceLine2 newSurfaceLine = surfaceLineAdapter.ConstructNewSurfaceLine(newDikeHeight); double oldSlope = TanSlopeInside(surfaceLine); double newSlope = TanSlopeInside(newSurfaceLine); Assert.That(newSlope, Is.EqualTo(oldSlope).Within(cToleranceSlope)); } [Test] public void AdaptedSurfaceLineHasCorrectNewPointAtTopRiver() { var surfaceLine = new SurfaceLine2 { CharacteristicPoints = { GeometryMustContainPoint = true }, Geometry = new GeometryPointString() }; var location = new Location(); const double newDikeHeight = 2.0; var pointAtToeRiver = new Point2D { X = 0, Z = 0 }; var pointAtTopRiver = new Point2D { X = 1, Z = 1 }; var pointAtTopPolder = new Point2D { X = 2, Z = 1 }; var pointAtToePolder = new Point2D { X = 3, Z = 0 }; surfaceLine.EnsurePointOfType(pointAtToeRiver.X, pointAtToeRiver.Z, CharacteristicPointType.DikeToeAtRiver); surfaceLine.EnsurePointOfType(pointAtTopRiver.X, pointAtTopRiver.Z, CharacteristicPointType.DikeTopAtRiver); surfaceLine.EnsurePointOfType(pointAtTopPolder.X, pointAtTopPolder.Z, CharacteristicPointType.DikeTopAtPolder); surfaceLine.EnsurePointOfType(pointAtToePolder.X, pointAtToePolder.Z, CharacteristicPointType.DikeToeAtPolder); surfaceLine.EnsurePointOfType(100, 0, CharacteristicPointType.SurfaceLevelInside); var surfaceLineAdapter = new SurfaceLineHeightAdapter(surfaceLine, location, 0); SurfaceLine2 newSurfaceLine = surfaceLineAdapter.ConstructNewSurfaceLine(newDikeHeight); Point2D actualPoint = newSurfaceLine.CharacteristicPoints.GetPoint2D(CharacteristicPointType.DikeTopAtRiver); var expectedPoint = new Point2D { X = 2, Z = 2 }; Assert.That(expectedPoint.LocationEquals(actualPoint), Is.True); } [Test] public void AdaptedSurfaceLineHasRemovedOldPointAtTopRiverCorrectly() { var surfaceLine = new SurfaceLine2 { CharacteristicPoints = { GeometryMustContainPoint = true }, Geometry = new GeometryPointString() }; var location = new Location(); const double newDikeHeight = 2.0; var pointAtToeRiver = new Point2D { X = 0, Z = 0 }; var pointAtTopRiver = new Point2D { X = 1, Z = 1 }; var pointAtTopPolder = new Point2D { X = 2, Z = 1 }; var pointAtToePolder = new Point2D { X = 3, Z = 0 }; surfaceLine.EnsurePointOfType(pointAtToeRiver.X, pointAtToeRiver.Z, CharacteristicPointType.DikeToeAtRiver); surfaceLine.EnsurePointOfType(pointAtTopRiver.X, pointAtTopRiver.Z, CharacteristicPointType.DikeTopAtRiver); surfaceLine.EnsurePointOfType(pointAtTopPolder.X, pointAtTopPolder.Z, CharacteristicPointType.DikeTopAtPolder); surfaceLine.EnsurePointOfType(pointAtToePolder.X, pointAtToePolder.Z, CharacteristicPointType.DikeToeAtPolder); surfaceLine.EnsurePointOfType(100, 0, CharacteristicPointType.SurfaceLevelInside); var surfaceLineAdapter = new SurfaceLineHeightAdapter(surfaceLine, location, 0); SurfaceLine2 newSurfaceLine = surfaceLineAdapter.ConstructNewSurfaceLine(newDikeHeight); Assert.That(newSurfaceLine.Geometry.Points.Any(p => p.LocationEquals(pointAtTopRiver)), Is.False); } [Test] public void AdaptedSurfaceLineWithoutShoulderHasCorrectNewPointAtTopPolder() { var line = new SurfaceLine2 { CharacteristicPoints = { GeometryMustContainPoint = true }, Geometry = new GeometryPointString() }; SurfaceLine2 surfaceLine = line; var location = new Location(); const double newDikeHeight = 2.0; var pointAtToeRiver = new Point2D { X = 0, Z = 0 }; var pointAtTopRiver = new Point2D { X = 1, Z = 1 }; var pointAtTopPolder = new Point2D { X = 2, Z = 1 }; var pointAtToePolder = new Point2D { X = 3, Z = 0 }; surfaceLine.EnsurePointOfType(pointAtToeRiver.X, pointAtToeRiver.Z, CharacteristicPointType.DikeToeAtRiver); surfaceLine.EnsurePointOfType(pointAtTopRiver.X, pointAtTopRiver.Z, CharacteristicPointType.DikeTopAtRiver); surfaceLine.EnsurePointOfType(pointAtTopPolder.X, pointAtTopPolder.Z, CharacteristicPointType.DikeTopAtPolder); surfaceLine.EnsurePointOfType(pointAtToePolder.X, pointAtToePolder.Z, CharacteristicPointType.DikeToeAtPolder); surfaceLine.EnsurePointOfType(100, 0, CharacteristicPointType.SurfaceLevelInside); var surfaceLineAdapter = new SurfaceLineHeightAdapter(surfaceLine, location, 0); SurfaceLine2 newSurfaceLine = surfaceLineAdapter.ConstructNewSurfaceLine(newDikeHeight); Point2D actualPoint = newSurfaceLine.CharacteristicPoints.GetPoint2D(CharacteristicPointType.DikeTopAtPolder); var expectedPoint = new Point2D { X = 3, Z = 2 }; Assert.That(expectedPoint.LocationEquals(actualPoint), Is.True); } [Test] public void AdaptedSurfaceLineWithoutShoulderHasCorrectlyRemovedOldPointAtTopPolder() { var surfaceLine = new SurfaceLine2 { CharacteristicPoints = { GeometryMustContainPoint = true }, Geometry = new GeometryPointString() }; var location = new Location(); const double newDikeHeight = 2.0; var pointAtToeRiver = new Point2D { X = 0, Z = 0 }; var pointAtTopRiver = new Point2D { X = 1, Z = 1 }; var pointAtTopPolder = new Point2D { X = 2, Z = 1 }; var pointAtToePolder = new Point2D { X = 3, Z = 0 }; surfaceLine.EnsurePointOfType(pointAtToeRiver.X, pointAtToeRiver.Z, CharacteristicPointType.DikeToeAtRiver); surfaceLine.EnsurePointOfType(pointAtTopRiver.X, pointAtTopRiver.Z, CharacteristicPointType.DikeTopAtRiver); surfaceLine.EnsurePointOfType(pointAtTopPolder.X, pointAtTopPolder.Z, CharacteristicPointType.DikeTopAtPolder); surfaceLine.EnsurePointOfType(pointAtToePolder.X, pointAtToePolder.Z, CharacteristicPointType.DikeToeAtPolder); surfaceLine.EnsurePointOfType(100, 0, CharacteristicPointType.SurfaceLevelInside); var surfaceLineAdapter = new SurfaceLineHeightAdapter(surfaceLine, location, 0); SurfaceLine2 newSurfaceLine = surfaceLineAdapter.ConstructNewSurfaceLine(newDikeHeight); Assert.That(newSurfaceLine.Geometry.Points.Any(p => p.LocationEquals(pointAtTopPolder)), Is.False); } [Test] public void AdaptedSurfaceLineWithoutShoulderHasCorrectNewPointAtToePolder() { var surfaceLine = new SurfaceLine2 { CharacteristicPoints = { GeometryMustContainPoint = true }, Geometry = new GeometryPointString() }; var location = new Location(); const double newDikeHeight = 2.0; var pointAtToeRiver = new Point2D { X = 0, Z = 0 }; var pointAtTopRiver = new Point2D { X = 2, Z = 1 }; var pointAtTopPolder = new Point2D { X = 3, Z = 1 }; var pointAtToePolder = new Point2D { X = 7, Z = 0 }; surfaceLine.EnsurePointOfType(pointAtToeRiver.X, pointAtToeRiver.Z, CharacteristicPointType.DikeToeAtRiver); surfaceLine.EnsurePointOfType(pointAtTopRiver.X, pointAtTopRiver.Z, CharacteristicPointType.DikeTopAtRiver); surfaceLine.EnsurePointOfType(pointAtTopPolder.X, pointAtTopPolder.Z, CharacteristicPointType.DikeTopAtPolder); surfaceLine.EnsurePointOfType(pointAtToePolder.X, pointAtToePolder.Z, CharacteristicPointType.DikeToeAtPolder); surfaceLine.EnsurePointOfType(100, 0, CharacteristicPointType.SurfaceLevelInside); var surfaceLineAdapter = new SurfaceLineHeightAdapter(surfaceLine, location, 0); SurfaceLine2 newSurfaceLine = surfaceLineAdapter.ConstructNewSurfaceLine(newDikeHeight); Point2D actualPoint = newSurfaceLine.CharacteristicPoints.GetPoint2D(CharacteristicPointType.DikeToeAtPolder); var expectedPoint = new Point2D { X = 13 }; Assert.That(expectedPoint.LocationEquals(actualPoint), Is.True); double oldSlope = TanSlopeInside(surfaceLine); double newSlope = TanSlopeInside(newSurfaceLine); Assert.That(newSlope, Is.EqualTo(oldSlope).Within(0.001)); } [Test] public void AdaptedSurfaceLineWithShoulderHasCorrectPointAtToePolder() { var surfaceLine = new SurfaceLine2 { CharacteristicPoints = { GeometryMustContainPoint = true }, Geometry = new GeometryPointString() }; var location = new Location(); const double newDikeHeight = 2.0; surfaceLine.EnsurePointOfType(0, 0, CharacteristicPointType.DikeToeAtRiver); surfaceLine.EnsurePointOfType(1, 1, CharacteristicPointType.DikeTopAtRiver); surfaceLine.EnsurePointOfType(2, 1, CharacteristicPointType.DikeTopAtPolder); surfaceLine.EnsurePointOfType(3, 0.5, CharacteristicPointType.ShoulderBaseInside); surfaceLine.EnsurePointOfType(4, 0.5, CharacteristicPointType.ShoulderTopInside); surfaceLine.EnsurePointOfType(5, 0, CharacteristicPointType.DikeToeAtPolder); surfaceLine.EnsurePointOfType(100, 0, CharacteristicPointType.SurfaceLevelInside); var surfaceLineAdapter = new SurfaceLineHeightAdapter(surfaceLine, location, 0); SurfaceLine2 newSurfaceLine = surfaceLineAdapter.ConstructNewSurfaceLine(newDikeHeight); var expectedPoint = new Point2D { X = 7, Z = 0 }; // Point2D actualPoint = newSurfaceLine.CharacteristicPoints.GetPoint2D(CharacteristicPointType.DikeToeAtPolder); Assert.That(expectedPoint.LocationEquals(actualPoint), Is.True); } [Test] public void AdaptedSurfaceLineHasRemovedShoulderPointsCorrectly() { var surfaceLine = new SurfaceLine2 { CharacteristicPoints = { GeometryMustContainPoint = true }, Geometry = new GeometryPointString() }; var location = new Location(); const double newDikeHeight = 3.0; var pointAtToeRiver = new Point2D { X = 0, Z = 0 }; var pointAtTopRiver = new Point2D { X = 1, Z = 1 }; var pointAtTopPolder = new Point2D { X = 2, Z = 1 }; var pointAtShoulderInsteek = new Point2D { X = 3, Z = 0.5 }; var pointAtShoulderTop = new Point2D { X = 4, Z = 0.5 }; var pointAtToePolder = new Point2D { X = 5, Z = 0 }; var pointAtSurfaceLevelInside = new Point2D { X = 100, Z = 0 }; surfaceLine.EnsurePointOfType(pointAtToeRiver.X, pointAtToeRiver.Z, CharacteristicPointType.DikeToeAtRiver); surfaceLine.EnsurePointOfType(pointAtTopRiver.X, pointAtTopRiver.Z, CharacteristicPointType.DikeTopAtRiver); surfaceLine.EnsurePointOfType(pointAtTopPolder.X, pointAtTopPolder.Z, CharacteristicPointType.DikeTopAtPolder); surfaceLine.EnsurePointOfType(pointAtShoulderInsteek.X, pointAtShoulderInsteek.Z, CharacteristicPointType.ShoulderBaseInside); surfaceLine.EnsurePointOfType(pointAtShoulderTop.X, pointAtShoulderTop.Z, CharacteristicPointType.ShoulderTopInside); surfaceLine.EnsurePointOfType(pointAtToePolder.X, pointAtToePolder.Z, CharacteristicPointType.DikeToeAtPolder); surfaceLine.EnsurePointOfType(pointAtSurfaceLevelInside.X, pointAtSurfaceLevelInside.Z, CharacteristicPointType.SurfaceLevelInside); var surfaceLineAdapter = new SurfaceLineHeightAdapter(surfaceLine, location, 0); SurfaceLine2 newSurfaceLine = surfaceLineAdapter.ConstructNewSurfaceLine(newDikeHeight); Assert.That(newSurfaceLine.CharacteristicPoints.GetPoint2D(CharacteristicPointType.ShoulderTopInside), Is.Null); Assert.That(newSurfaceLine.CharacteristicPoints.GetPoint2D(CharacteristicPointType.ShoulderBaseInside), Is.Null); Assert.That(newSurfaceLine.Geometry.Points.Any(p => p.LocationEquals(pointAtShoulderInsteek)), Is.False); Assert.That(newSurfaceLine.Geometry.Points.Any(p => p.LocationEquals(pointAtShoulderTop)), Is.False); Point2D newPointAtToePolder = newSurfaceLine.CharacteristicPoints.GetPoint2D(CharacteristicPointType.DikeToeAtPolder); Assert.That(newSurfaceLine.GetPointSegmentIncluding(pointAtTopRiver.X, newPointAtToePolder.X).Count(), Is.EqualTo(3)); Assert.That(newSurfaceLine.Geometry.Points.Count, Is.EqualTo(5)); } [Test] public void AdaptedSurfaceLineWithLargeShoulderHaveSameToeAtPolder() { var surfaceLine = new SurfaceLine2 { CharacteristicPoints = { GeometryMustContainPoint = true }, Geometry = new GeometryPointString() }; var location = new Location(); const double newDikeHeight = 1.5; var pointAtToeRiver = new Point2D { X = 0, Z = 0 }; var pointAtTopRiver = new Point2D { X = 1, Z = 1 }; var pointAtTopPolder = new Point2D { X = 2, Z = 1 }; var pointAtShoulderInsteek = new Point2D { X = 3, Z = 0.5 }; var pointAtShoulderTop = new Point2D { X = 5, Z = 0.5 }; var pointAtToePolder = new Point2D { X = 6, Z = 0 }; var pointAtSurfaceLevelInside = new Point2D { X = 100, Z = 0 }; surfaceLine.EnsurePointOfType(pointAtToeRiver.X, pointAtToeRiver.Z, CharacteristicPointType.DikeToeAtRiver); surfaceLine.EnsurePointOfType(pointAtTopRiver.X, pointAtTopRiver.Z, CharacteristicPointType.DikeTopAtRiver); surfaceLine.EnsurePointOfType(pointAtTopPolder.X, pointAtTopPolder.Z, CharacteristicPointType.DikeTopAtPolder); surfaceLine.EnsurePointOfType(pointAtShoulderInsteek.X, pointAtShoulderInsteek.Z, CharacteristicPointType.ShoulderBaseInside); surfaceLine.EnsurePointOfType(pointAtShoulderTop.X, pointAtShoulderTop.Z, CharacteristicPointType.ShoulderTopInside); surfaceLine.EnsurePointOfType(pointAtToePolder.X, pointAtToePolder.Z, CharacteristicPointType.DikeToeAtPolder); surfaceLine.EnsurePointOfType(pointAtSurfaceLevelInside.X, pointAtSurfaceLevelInside.Z, CharacteristicPointType.SurfaceLevelInside); var surfaceLineAdapter = new SurfaceLineHeightAdapter(surfaceLine, location, 0); SurfaceLine2 newSurfaceLine = surfaceLineAdapter.ConstructNewSurfaceLine(newDikeHeight); Assert.That(pointAtToePolder.LocationEquals(newSurfaceLine.CharacteristicPoints.GetPoint2D(CharacteristicPointType.DikeToeAtPolder)), Is.True); } [Test] public void AdaptedSurfaceLineWithLargeShoulderHaveSameTopAtShoulderInside() { var surfaceLine = new SurfaceLine2 { CharacteristicPoints = { GeometryMustContainPoint = true }, Geometry = new GeometryPointString() }; var location = new Location(); const double newDikeHeight = 3.0; var pointAtToeRiver = new Point2D { X = 0, Z = 0 }; var pointAtTopRiver = new Point2D { X = 1, Z = 2 }; var pointAtTopPolder = new Point2D { X = 2, Z = 2 }; var pointAtShoulderInsteek = new Point2D { X = 3, Z = 1 }; var pointAtShoulderTop = new Point2D { X = 5, Z = 1 }; var pointAtToePolder = new Point2D { X = 6, Z = 2 }; var pointAtSurfaceLevelInside = new Point2D { X = 100, Z = 0 }; surfaceLine.EnsurePointOfType(pointAtToeRiver.X, pointAtToeRiver.Z, CharacteristicPointType.DikeToeAtRiver); surfaceLine.EnsurePointOfType(pointAtTopRiver.X, pointAtTopRiver.Z, CharacteristicPointType.DikeTopAtRiver); surfaceLine.EnsurePointOfType(pointAtTopPolder.X, pointAtTopPolder.Z, CharacteristicPointType.DikeTopAtPolder); surfaceLine.EnsurePointOfType(pointAtShoulderInsteek.X, pointAtShoulderInsteek.Z, CharacteristicPointType.ShoulderBaseInside); surfaceLine.EnsurePointOfType(pointAtShoulderTop.X, pointAtShoulderTop.Z, CharacteristicPointType.ShoulderTopInside); surfaceLine.EnsurePointOfType(pointAtToePolder.X, pointAtToePolder.Z, CharacteristicPointType.DikeToeAtPolder); surfaceLine.EnsurePointOfType(pointAtSurfaceLevelInside.X, pointAtSurfaceLevelInside.Z, CharacteristicPointType.SurfaceLevelInside); var surfaceLineAdapter = new SurfaceLineHeightAdapter(surfaceLine, location, 0); SurfaceLine2 newSurfaceLine = surfaceLineAdapter.ConstructNewSurfaceLine(newDikeHeight); Assert.That(pointAtShoulderTop.LocationEquals(newSurfaceLine.CharacteristicPoints.GetPoint2D(CharacteristicPointType.ShoulderTopInside)), Is.True); } [Test] public void AdaptedSurfaceLineWithLargeShoulderShouldHaveACorrectIntersectionPoint() { var surfaceLine = new SurfaceLine2 { CharacteristicPoints = { GeometryMustContainPoint = true }, Geometry = new GeometryPointString() }; var location = new Location(); const double newDikeHeight = 3.0; var pointAtToeRiver = new Point2D { X = 0, Z = 0 }; var pointAtTopRiver = new Point2D { X = 1, Z = 2 }; var pointAtTopPolder = new Point2D { X = 2, Z = 2 }; var pointAtShoulderInsteek = new Point2D { X = 3, Z = 1 }; var pointAtShoulderTop = new Point2D { X = 5, Z = 1 }; var pointAtToePolder = new Point2D { X = 6, Z = 0 }; var pointAtSurfaceLevelInside = new Point2D { X = 100, Z = 0 }; surfaceLine.EnsurePointOfType(pointAtToeRiver.X, pointAtToeRiver.Z, CharacteristicPointType.DikeToeAtRiver); surfaceLine.EnsurePointOfType(pointAtTopRiver.X, pointAtTopRiver.Z, CharacteristicPointType.DikeTopAtRiver); surfaceLine.EnsurePointOfType(pointAtTopPolder.X, pointAtTopPolder.Z, CharacteristicPointType.DikeTopAtPolder); surfaceLine.EnsurePointOfType(pointAtShoulderInsteek.X, pointAtShoulderInsteek.Z, CharacteristicPointType.ShoulderBaseInside); surfaceLine.EnsurePointOfType(pointAtShoulderTop.X, pointAtShoulderTop.Z, CharacteristicPointType.ShoulderTopInside); surfaceLine.EnsurePointOfType(pointAtToePolder.X, pointAtToePolder.Z, CharacteristicPointType.DikeToeAtPolder); surfaceLine.EnsurePointOfType(pointAtSurfaceLevelInside.X, pointAtSurfaceLevelInside.Z, CharacteristicPointType.SurfaceLevelInside); var surfaceLineAdapter = new SurfaceLineHeightAdapter(surfaceLine, location, 0); SurfaceLine2 newSurfaceLine = surfaceLineAdapter.ConstructNewSurfaceLine(newDikeHeight); var expectedPoint = new Point2D { X = 4.5, Z = 1 }; Point2D actualPoint = newSurfaceLine.CharacteristicPoints.GetPoint2D(CharacteristicPointType.ShoulderBaseInside); Assert.That(expectedPoint.LocationEquals(actualPoint), Is.True); } [Test] public void AdaptedSurfaceLineWithSoulderAndDitchShouldNotCreateInvalidSurfaceLine() { SurfaceLine2 surfaceLine = FactoryForSurfaceLines.CreateRealisticSurfaceLineForHeightAdapter(); var location = new Location(); const double newDikeHeight = 19.2; ValidationResult validationError = surfaceLine.Validate().FirstOrDefault(vr => vr.MessageType == ValidationResultType.Error); if (validationError != null) { throw new SurfaceLineException(validationError.Text); } var surfaceLineAdapter = new SurfaceLineHeightAdapter(surfaceLine, location, 0); SurfaceLine2 newSurfaceLine = surfaceLineAdapter.ConstructNewSurfaceLine(newDikeHeight); validationError = newSurfaceLine.Validate().FirstOrDefault(vr => vr.MessageType == ValidationResultType.Error); if (validationError != null) { throw new SurfaceLineException(validationError.Text); } } /// /// This tests with a realistic surfaceline which contains all possible relevant characteristic points /// [Test] public void AdaptedSurfaceLineWithTrafficLoadPointsShouldAdjustThosePoints1() { SurfaceLine2 surfaceLine = FactoryForSurfaceLines.CreateRealisticSurfaceLineForHeightAdapter(); var location = new Location(); const double cTolerance = 0.0000001; const double newDikeHeight = 19.2; var surfaceLineAdapter = new SurfaceLineHeightAdapter(surfaceLine, location, 0); SurfaceLine2 newSurfaceLine = surfaceLineAdapter.ConstructNewSurfaceLine(newDikeHeight); Assert.That(newSurfaceLine.CharacteristicPoints.GetPoint2D(CharacteristicPointType.TrafficLoadOutside).Z, Is.EqualTo(newSurfaceLine.CharacteristicPoints.GetPoint2D(CharacteristicPointType.DikeTopAtPolder).Z).Within(cTolerance)); Assert.That(newSurfaceLine.CharacteristicPoints.GetPoint2D(CharacteristicPointType.TrafficLoadInside).Z, Is.EqualTo(newSurfaceLine.CharacteristicPoints.GetPoint2D(CharacteristicPointType.DikeTopAtPolder).Z).Within(cTolerance)); } /// /// This tests with a surfaceline that contains the minimum possible characteristic points /// [Test] public void AdaptedSurfaceLineWithTrafficLoadPointsShouldAdjustThosePoints2() { var surfaceLine = new SurfaceLine2 { CharacteristicPoints = { GeometryMustContainPoint = true }, Geometry = new GeometryPointString() }; var location = new Location(); const double newDikeHeight = 1.2; var pointDikeToeAtRiver = new Point2D { X = 0, Z = 0 }; var pointDikeTopAtRiver = new Point2D { X = 1, Z = 1 }; var pointTrafficLoadOutside = new Point2D { X = 1.1, Z = 1 }; var pointTrafficLoadInside = new Point2D { X = 1.9, Z = 1 }; var pointDikeTopAtPolder = new Point2D { X = 2, Z = 1 }; var pointDikeToeAtPolder = new Point2D { X = 3, Z = 0 }; surfaceLine.EnsurePointOfType(pointDikeToeAtRiver.X, pointDikeToeAtRiver.Z, CharacteristicPointType.DikeToeAtRiver); surfaceLine.EnsurePointOfType(pointDikeTopAtRiver.X, pointDikeTopAtRiver.Z, CharacteristicPointType.DikeTopAtRiver); surfaceLine.EnsurePointOfType(pointTrafficLoadOutside.X, pointTrafficLoadOutside.Z, CharacteristicPointType.TrafficLoadOutside); surfaceLine.EnsurePointOfType(pointTrafficLoadInside.X, pointTrafficLoadInside.Z, CharacteristicPointType.TrafficLoadInside); surfaceLine.EnsurePointOfType(pointDikeTopAtPolder.X, pointDikeTopAtPolder.Z, CharacteristicPointType.DikeTopAtPolder); surfaceLine.EnsurePointOfType(pointDikeToeAtPolder.X, pointDikeToeAtPolder.Z, CharacteristicPointType.DikeToeAtPolder); surfaceLine.EnsurePointOfType(100, 0, CharacteristicPointType.SurfaceLevelInside); var surfaceLineAdapter = new SurfaceLineHeightAdapter(surfaceLine, location, 0); SurfaceLine2 newSurfaceLine = surfaceLineAdapter.ConstructNewSurfaceLine(newDikeHeight); Assert.That(newSurfaceLine.CharacteristicPoints.GetPoint2D(CharacteristicPointType.TrafficLoadOutside).Z, Is.EqualTo(newSurfaceLine.CharacteristicPoints.GetPoint2D(CharacteristicPointType.DikeTopAtPolder).Z)); Assert.That(newSurfaceLine.CharacteristicPoints.GetPoint2D(CharacteristicPointType.TrafficLoadInside).Z, Is.EqualTo(newSurfaceLine.CharacteristicPoints.GetPoint2D(CharacteristicPointType.DikeTopAtPolder).Z)); } /// /// Test if dike with skewed dike table and points between characteristic points is constructed correctly with new height /// [Test] public void CanAdaptSurfaceLineWithSkewedDikeTableAndInBetweenPoints() { SurfaceLine2 surfaceLine = CreateSurfaceLineWithSkwewedDikeTableAndInBetweenPoints(); var location = new Location(); const double cTolerance = 0.001; const double newDikeHeight = 4.0; Assert.That(surfaceLine.Geometry.Points.Count, Is.EqualTo(10)); var surfaceLineAdapter = new SurfaceLineHeightAdapter(surfaceLine, location, 0); SurfaceLine2 newSurfaceLine = surfaceLineAdapter.ConstructNewSurfaceLine(newDikeHeight); Assert.That(newSurfaceLine.Geometry.Points.Count, Is.EqualTo(6)); Assert.That(newSurfaceLine.CharacteristicPoints.GetPoint2D(CharacteristicPointType.DikeTopAtRiver).X, Is.EqualTo(7.3333).Within(cTolerance)); Assert.That(newSurfaceLine.CharacteristicPoints.GetPoint2D(CharacteristicPointType.DikeTopAtRiver).Z, Is.EqualTo(4.0000).Within(cTolerance)); Assert.That(newSurfaceLine.CharacteristicPoints.GetPoint2D(CharacteristicPointType.DikeTopAtPolder).X, Is.EqualTo(9.3333).Within(cTolerance)); Assert.That(newSurfaceLine.CharacteristicPoints.GetPoint2D(CharacteristicPointType.DikeTopAtPolder).Z, Is.EqualTo(4.0000).Within(cTolerance)); Assert.That(newSurfaceLine.CharacteristicPoints.GetPoint2D(CharacteristicPointType.DikeToeAtPolder).X, Is.EqualTo(14.6666).Within(cTolerance)); Assert.That(newSurfaceLine.CharacteristicPoints.GetPoint2D(CharacteristicPointType.DikeToeAtPolder).Z, Is.EqualTo(0.0000).Within(cTolerance)); Assert.That(newSurfaceLine.CharacteristicPoints.GetPoint2D(CharacteristicPointType.SurfaceLevelInside).X, Is.EqualTo(100.000).Within(cTolerance)); Assert.That(newSurfaceLine.CharacteristicPoints.GetPoint2D(CharacteristicPointType.SurfaceLevelInside).Z, Is.EqualTo(0.0000).Within(cTolerance)); } [Test] public void AdaptedSurfaceLineWithNewDefinedTopExactOnOldTop() { var surfaceLine = new SurfaceLine2 { CharacteristicPoints = { GeometryMustContainPoint = true }, Geometry = new GeometryPointString() }; var location = new Location(); const double newDikeHeight = 2.0; surfaceLine.EnsurePointOfType(0, 0, CharacteristicPointType.DikeToeAtRiver); surfaceLine.EnsurePointOfType(1, 1, CharacteristicPointType.DikeTopAtRiver); surfaceLine.EnsurePointOfType(4, 1, CharacteristicPointType.DikeTopAtPolder); surfaceLine.EnsurePointOfType(5, 0, CharacteristicPointType.ShoulderBaseInside); surfaceLine.EnsurePointOfType(6, 0, CharacteristicPointType.ShoulderTopInside); surfaceLine.EnsurePointOfType(7, -1, CharacteristicPointType.DikeToeAtPolder); surfaceLine.EnsurePointOfType(100, 0, CharacteristicPointType.SurfaceLevelInside); location.UseNewDikeTopWidth = true; location.NewDikeTopWidth = 1; var surfaceLineAdapter = new SurfaceLineHeightAdapter(surfaceLine, location, 0); SurfaceLine2 newSurfaceLine = surfaceLineAdapter.ConstructNewSurfaceLine(newDikeHeight); var expectedNewTopRiver = new Point2D { X = 2, Z = 2 }; Point2D actualNewTopRiver = newSurfaceLine.CharacteristicPoints.GetPoint2D(CharacteristicPointType.DikeTopAtRiver); Assert.That(expectedNewTopRiver.LocationEquals(actualNewTopRiver), Is.True); var expectedNewTopPolder = new Point2D { X = 3, Z = 2 }; Point2D actualNewTopPolder = newSurfaceLine.CharacteristicPoints.GetPoint2D(CharacteristicPointType.DikeTopAtPolder); Assert.That(expectedNewTopPolder.LocationEquals(actualNewTopPolder), Is.True); var expectedShoulderBaseInside = new Point2D { X = 5, Z = 0 }; Point2D actualShoulderBaseInside = newSurfaceLine.CharacteristicPoints.GetPoint2D(CharacteristicPointType.ShoulderBaseInside); Assert.That(expectedShoulderBaseInside.LocationEquals(actualShoulderBaseInside), Is.True); Assert.That(newSurfaceLine.Geometry.Points.Count, Is.EqualTo(9)); } [Test] public void AdaptedSurfaceLineWithNewDefinedTopSmallerThanOldTop() { var surfaceLine = new SurfaceLine2 { CharacteristicPoints = { GeometryMustContainPoint = true }, Geometry = new GeometryPointString() }; var location = new Location(); const double newDikeHeight = 2.0; surfaceLine.EnsurePointOfType(0, 0, CharacteristicPointType.DikeToeAtRiver); surfaceLine.EnsurePointOfType(1, 1, CharacteristicPointType.DikeTopAtRiver); surfaceLine.EnsurePointOfType(4, 1, CharacteristicPointType.DikeTopAtPolder); surfaceLine.EnsurePointOfType(5, 0, CharacteristicPointType.ShoulderBaseInside); surfaceLine.EnsurePointOfType(6, 0, CharacteristicPointType.ShoulderTopInside); surfaceLine.EnsurePointOfType(7, -1, CharacteristicPointType.DikeToeAtPolder); surfaceLine.EnsurePointOfType(100, 0, CharacteristicPointType.SurfaceLevelInside); location.UseNewDikeTopWidth = true; location.NewDikeTopWidth = 0.8; var surfaceLineAdapter = new SurfaceLineHeightAdapter(surfaceLine, location, 0); SurfaceLine2 newSurfaceLine = surfaceLineAdapter.ConstructNewSurfaceLine(newDikeHeight); var expectedNewTopRiver = new Point2D { X = 2, Z = 2 }; Point2D actualNewTopRiver = newSurfaceLine.CharacteristicPoints.GetPoint2D(CharacteristicPointType.DikeTopAtRiver); Assert.That(expectedNewTopRiver.LocationEquals(actualNewTopRiver), Is.True); var expectedNewTopPolder = new Point2D { X = 2.8, Z = 2 }; Point2D actualNewTopPolder = newSurfaceLine.CharacteristicPoints.GetPoint2D(CharacteristicPointType.DikeTopAtPolder); Assert.That(expectedNewTopPolder.LocationEquals(actualNewTopPolder), Is.True); var expectedNewPoint = new Point2D { X = 3.8, Z = 1 }; Point2D actualNewPoint = newSurfaceLine.Geometry.Points[4]; Assert.That(expectedNewPoint.LocationEquals(actualNewPoint), Is.True); var expectedShoulderBaseInside = new Point2D { X = 5, Z = 0 }; Point2D actualShoulderBaseInside = newSurfaceLine.CharacteristicPoints.GetPoint2D(CharacteristicPointType.ShoulderBaseInside); Assert.That(expectedShoulderBaseInside.LocationEquals(actualShoulderBaseInside), Is.True); Assert.That(newSurfaceLine.Geometry.Points.Count, Is.EqualTo(10)); } [Test] public void AdaptedSurfaceLineWithNewDefinedTopWiderThanOldTopBeyondShoulder() { var surfaceLine = new SurfaceLine2 { CharacteristicPoints = { GeometryMustContainPoint = true }, Geometry = new GeometryPointString() }; var location = new Location(); const double newDikeHeight = 2.0; surfaceLine.EnsurePointOfType(0, 0, CharacteristicPointType.DikeToeAtRiver); surfaceLine.EnsurePointOfType(1, 1, CharacteristicPointType.DikeTopAtRiver); surfaceLine.EnsurePointOfType(4, 1, CharacteristicPointType.DikeTopAtPolder); surfaceLine.EnsurePointOfType(5, 0, CharacteristicPointType.ShoulderBaseInside); surfaceLine.EnsurePointOfType(6, 0, CharacteristicPointType.ShoulderTopInside); surfaceLine.EnsurePointOfType(7, -1, CharacteristicPointType.DikeToeAtPolder); surfaceLine.EnsurePointOfType(100, -1, CharacteristicPointType.SurfaceLevelInside); location.UseNewDikeTopWidth = true; location.NewDikeTopWidth = 3; var surfaceLineAdapter = new SurfaceLineHeightAdapter(surfaceLine, location, 0); SurfaceLine2 newSurfaceLine = surfaceLineAdapter.ConstructNewSurfaceLine(newDikeHeight); var expectedNewTopRiver = new Point2D { X = 2, Z = 2 }; Point2D actualNewTopRiver = newSurfaceLine.CharacteristicPoints.GetPoint2D(CharacteristicPointType.DikeTopAtRiver); Assert.That(expectedNewTopRiver.LocationEquals(actualNewTopRiver), Is.True); var expectedNewTopPolder = new Point2D { X = 5, Z = 2 }; Point2D actualNewTopPolder = newSurfaceLine.CharacteristicPoints.GetPoint2D(CharacteristicPointType.DikeTopAtPolder); Assert.That(expectedNewTopPolder.LocationEquals(actualNewTopPolder), Is.True); var expectedToeInside = new Point2D { X = 8, Z = -1 }; Point2D actualToeInside = newSurfaceLine.CharacteristicPoints.GetPoint2D(CharacteristicPointType.DikeToeAtPolder); Assert.That(expectedToeInside.LocationEquals(actualToeInside), Is.True); Assert.That(newSurfaceLine.Geometry.Points.Count, Is.EqualTo(5)); } [Test] public void AdaptedSurfaceLineWithNewDefinedTopWiderThanOldTopOnShoulderTopInside() { var surfaceLine = new SurfaceLine2 { CharacteristicPoints = { GeometryMustContainPoint = true }, Geometry = new GeometryPointString() }; var location = new Location(); const double newDikeHeight = 2.0; surfaceLine.EnsurePointOfType(0, 0, CharacteristicPointType.DikeToeAtRiver); surfaceLine.EnsurePointOfType(1, 1, CharacteristicPointType.DikeTopAtRiver); surfaceLine.EnsurePointOfType(4, 1, CharacteristicPointType.DikeTopAtPolder); surfaceLine.EnsurePointOfType(5, 0, CharacteristicPointType.ShoulderBaseInside); surfaceLine.EnsurePointOfType(6, 0, CharacteristicPointType.ShoulderTopInside); surfaceLine.EnsurePointOfType(7, -1, CharacteristicPointType.DikeToeAtPolder); surfaceLine.EnsurePointOfType(100, -1, CharacteristicPointType.SurfaceLevelInside); location.UseNewDikeTopWidth = true; location.NewDikeTopWidth = 2; var surfaceLineAdapter = new SurfaceLineHeightAdapter(surfaceLine, location, 0); SurfaceLine2 newSurfaceLine = surfaceLineAdapter.ConstructNewSurfaceLine(newDikeHeight); var expectedNewTopRiver = new Point2D { X = 2, Z = 2 }; Point2D actualNewTopRiver = newSurfaceLine.CharacteristicPoints.GetPoint2D(CharacteristicPointType.DikeTopAtRiver); Assert.That(expectedNewTopRiver.LocationEquals(actualNewTopRiver), Is.True); var expectedNewTopPolder = new Point2D { X = 4, Z = 2 }; Point2D actualNewTopPolder = newSurfaceLine.CharacteristicPoints.GetPoint2D(CharacteristicPointType.DikeTopAtPolder); Assert.That(expectedNewTopPolder.LocationEquals(actualNewTopPolder), Is.True); var expectedToeInside = new Point2D { X = 7, Z = -1 }; Point2D actualToeInside = newSurfaceLine.CharacteristicPoints.GetPoint2D(CharacteristicPointType.DikeToeAtPolder); Assert.That(expectedToeInside.LocationEquals(actualToeInside), Is.True); Assert.That(newSurfaceLine.Geometry.Points.Count, Is.EqualTo(6)); } [Test] public void AdaptedSurfaceLineWithNewDefinedTopWiderThanOldTopIntersectingShoulder() { var surfaceLine = new SurfaceLine2 { CharacteristicPoints = { GeometryMustContainPoint = true }, Geometry = new GeometryPointString() }; var location = new Location(); const double newDikeHeight = 2.0; surfaceLine.EnsurePointOfType(0, 0, CharacteristicPointType.DikeToeAtRiver); surfaceLine.EnsurePointOfType(1, 1, CharacteristicPointType.DikeTopAtRiver); surfaceLine.EnsurePointOfType(4, 1, CharacteristicPointType.DikeTopAtPolder); surfaceLine.EnsurePointOfType(5, 0, CharacteristicPointType.ShoulderBaseInside); surfaceLine.EnsurePointOfType(6, 0, CharacteristicPointType.ShoulderTopInside); surfaceLine.EnsurePointOfType(7, -1, CharacteristicPointType.DikeToeAtPolder); surfaceLine.EnsurePointOfType(100, -1, CharacteristicPointType.SurfaceLevelInside); location.UseNewDikeTopWidth = true; location.NewDikeTopWidth = 1.5; var surfaceLineAdapter = new SurfaceLineHeightAdapter(surfaceLine, location, 0); SurfaceLine2 newSurfaceLine = surfaceLineAdapter.ConstructNewSurfaceLine(newDikeHeight); var expectedNewTopRiver = new Point2D { X = 2, Z = 2 }; Point2D actualNewTopRiver = newSurfaceLine.CharacteristicPoints.GetPoint2D(CharacteristicPointType.DikeTopAtRiver); Assert.That(expectedNewTopRiver.LocationEquals(actualNewTopRiver), Is.True); var expectedNewTopPolder = new Point2D { X = 3.5, Z = 2 }; Point2D actualNewTopPolder = newSurfaceLine.CharacteristicPoints.GetPoint2D(CharacteristicPointType.DikeTopAtPolder); Assert.That(expectedNewTopPolder.LocationEquals(actualNewTopPolder), Is.True); var expectedShoulderBaseInside = new Point2D { X = 5.5, Z = 0 }; Point2D actualShoulderBaseInside = newSurfaceLine.CharacteristicPoints.GetPoint2D(CharacteristicPointType.ShoulderBaseInside); Assert.That(expectedShoulderBaseInside.LocationEquals(actualShoulderBaseInside), Is.True); var expectedShoulderTopInside = new Point2D { X = 6, Z = 0 }; Point2D actualShoulderTopInside = newSurfaceLine.CharacteristicPoints.GetPoint2D(CharacteristicPointType.ShoulderTopInside); Assert.That(expectedShoulderTopInside.LocationEquals(actualShoulderTopInside), Is.True); var expectedToeInside = new Point2D { X = 7, Z = -1 }; Point2D actualToeInside = newSurfaceLine.CharacteristicPoints.GetPoint2D(CharacteristicPointType.DikeToeAtPolder); Assert.That(expectedToeInside.LocationEquals(actualToeInside), Is.True); Assert.That(newSurfaceLine.Geometry.Points.Count, Is.EqualTo(7)); } [Test] public void AdaptedSurfaceLineWithNewDefinedInsideSlope() { var surfaceLine = new SurfaceLine2 { CharacteristicPoints = { GeometryMustContainPoint = true }, Geometry = new GeometryPointString() }; var location = new Location(); const double newDikeHeight = 2.0; surfaceLine.EnsurePointOfType(0, 0, CharacteristicPointType.DikeToeAtRiver); surfaceLine.EnsurePointOfType(1, 1, CharacteristicPointType.DikeTopAtRiver); surfaceLine.EnsurePointOfType(4, 1, CharacteristicPointType.DikeTopAtPolder); surfaceLine.EnsurePointOfType(5, 0, CharacteristicPointType.ShoulderBaseInside); surfaceLine.EnsurePointOfType(6, 0, CharacteristicPointType.ShoulderTopInside); surfaceLine.EnsurePointOfType(7, -1, CharacteristicPointType.DikeToeAtPolder); surfaceLine.EnsurePointOfType(100, -1, CharacteristicPointType.SurfaceLevelInside); location.UseNewDikeSlopeInside = true; location.NewDikeSlopeInside = 0.5; var surfaceLineAdapter = new SurfaceLineHeightAdapter(surfaceLine, location, 0); SurfaceLine2 newSurfaceLine = surfaceLineAdapter.ConstructNewSurfaceLine(newDikeHeight); var expectedNewTopRiver = new Point2D { X = 2, Z = 2 }; Point2D actualNewTopRiver = newSurfaceLine.CharacteristicPoints.GetPoint2D(CharacteristicPointType.DikeTopAtRiver); Assert.That(expectedNewTopRiver.LocationEquals(actualNewTopRiver), Is.True); var expectedNewTopPolder = new Point2D { X = 5, Z = 2 }; Point2D actualNewTopPolder = newSurfaceLine.CharacteristicPoints.GetPoint2D(CharacteristicPointType.DikeTopAtPolder); Assert.That(expectedNewTopPolder.LocationEquals(actualNewTopPolder), Is.True); var expectedToeInside = new Point2D { X = 11, Z = -1 }; Point2D actualToeInside = newSurfaceLine.CharacteristicPoints.GetPoint2D(CharacteristicPointType.DikeToeAtPolder); Assert.That(expectedToeInside.LocationEquals(actualToeInside), Is.True); Assert.That(newSurfaceLine.Geometry.Points.Count, Is.EqualTo(5)); } [Test] public void AdaptedSurfaceLineWithNewDefinedInsideSlopeEndingOnOldShoulderTop() { var surfaceLine = new SurfaceLine2 { CharacteristicPoints = { GeometryMustContainPoint = true }, Geometry = new GeometryPointString() }; var location = new Location(); const double newDikeHeight = 2.0; surfaceLine.EnsurePointOfType(0, 0, CharacteristicPointType.DikeToeAtRiver); surfaceLine.EnsurePointOfType(1, 1, CharacteristicPointType.DikeTopAtRiver); surfaceLine.EnsurePointOfType(4, 1, CharacteristicPointType.DikeTopAtPolder); surfaceLine.EnsurePointOfType(5, 0, CharacteristicPointType.ShoulderBaseInside); surfaceLine.EnsurePointOfType(6, 0, CharacteristicPointType.ShoulderTopInside); surfaceLine.EnsurePointOfType(7, -1, CharacteristicPointType.DikeToeAtPolder); surfaceLine.EnsurePointOfType(100, -1, CharacteristicPointType.SurfaceLevelInside); location.UseNewDikeSlopeInside = true; location.NewDikeSlopeInside = 2; var surfaceLineAdapter = new SurfaceLineHeightAdapter(surfaceLine, location, 0); SurfaceLine2 newSurfaceLine = surfaceLineAdapter.ConstructNewSurfaceLine(newDikeHeight); var expectedNewTopRiver = new Point2D { X = 2, Z = 2 }; Point2D actualNewTopRiver = newSurfaceLine.CharacteristicPoints.GetPoint2D(CharacteristicPointType.DikeTopAtRiver); Assert.That(expectedNewTopRiver.LocationEquals(actualNewTopRiver), Is.True); var expectedNewTopPolder = new Point2D { X = 5, Z = 2 }; Point2D actualNewTopPolder = newSurfaceLine.CharacteristicPoints.GetPoint2D(CharacteristicPointType.DikeTopAtPolder); Assert.That(expectedNewTopPolder.LocationEquals(actualNewTopPolder), Is.True); var expectedPoint = new Point2D { X = 6, Z = 0 }; Point2D actualPoint = newSurfaceLine.Geometry.Points[3]; Assert.That(expectedPoint.LocationEquals(actualPoint), Is.True); var expectedToeInside = new Point2D { X = 7, Z = -1 }; Point2D actualToeInside = newSurfaceLine.CharacteristicPoints.GetPoint2D(CharacteristicPointType.DikeToeAtPolder); Assert.That(expectedToeInside.LocationEquals(actualToeInside), Is.True); Assert.That(newSurfaceLine.Geometry.Points.Count, Is.EqualTo(6)); } [Test] public void AdaptedSurfaceLineWithNewDefinedOutsideSlope2() { var surfaceLine = new SurfaceLine2 { CharacteristicPoints = { GeometryMustContainPoint = true }, Geometry = new GeometryPointString() }; var location = new Location(); const double newDikeHeight = 2.0; surfaceLine.EnsurePointOfType(0, 0, CharacteristicPointType.DikeToeAtRiver); surfaceLine.EnsurePointOfType(1, 1, CharacteristicPointType.DikeTopAtRiver); surfaceLine.EnsurePointOfType(4, 1, CharacteristicPointType.DikeTopAtPolder); surfaceLine.EnsurePointOfType(5, 0, CharacteristicPointType.ShoulderBaseInside); surfaceLine.EnsurePointOfType(6, 0, CharacteristicPointType.ShoulderTopInside); surfaceLine.EnsurePointOfType(7, -1, CharacteristicPointType.DikeToeAtPolder); surfaceLine.EnsurePointOfType(100, -1, CharacteristicPointType.SurfaceLevelInside); location.UseNewDikeSlopeOutside = true; location.NewDikeSlopeOutside = 2; var surfaceLineAdapter = new SurfaceLineHeightAdapter(surfaceLine, location, 0); SurfaceLine2 newSurfaceLine = surfaceLineAdapter.ConstructNewSurfaceLine(newDikeHeight); var expectedNewTopRiver = new Point2D { X = 1.5, Z = 2 }; Point2D actualNewTopRiver = newSurfaceLine.CharacteristicPoints.GetPoint2D(CharacteristicPointType.DikeTopAtRiver); Assert.That(expectedNewTopRiver.LocationEquals(actualNewTopRiver), Is.True); var expectedNewTopPolder = new Point2D { X = 4.5, Z = 2 }; Point2D actualNewTopPolder = newSurfaceLine.CharacteristicPoints.GetPoint2D(CharacteristicPointType.DikeTopAtPolder); Assert.That(expectedNewTopPolder.LocationEquals(actualNewTopPolder), Is.True); var expectedToeInside = new Point2D { X = 7.5, Z = -1 }; Point2D actualToeInside = newSurfaceLine.CharacteristicPoints.GetPoint2D(CharacteristicPointType.DikeToeAtPolder); Assert.That(expectedToeInside.LocationEquals(actualToeInside), Is.True); Assert.That(newSurfaceLine.Geometry.Points.Count, Is.EqualTo(6)); } [Test] public void AdaptedSurfaceLineWithNewDefinedOutsideSlope05() { var surfaceLine = new SurfaceLine2 { CharacteristicPoints = { GeometryMustContainPoint = true }, Geometry = new GeometryPointString() }; var location = new Location(); const double newDikeHeight = 2.0; surfaceLine.EnsurePointOfType(0, 0, CharacteristicPointType.DikeToeAtRiver); surfaceLine.EnsurePointOfType(1, 1, CharacteristicPointType.DikeTopAtRiver); surfaceLine.EnsurePointOfType(4, 1, CharacteristicPointType.DikeTopAtPolder); surfaceLine.EnsurePointOfType(5, 0, CharacteristicPointType.ShoulderBaseInside); surfaceLine.EnsurePointOfType(6, 0, CharacteristicPointType.ShoulderTopInside); surfaceLine.EnsurePointOfType(7, -1, CharacteristicPointType.DikeToeAtPolder); surfaceLine.EnsurePointOfType(100, -1, CharacteristicPointType.SurfaceLevelInside); location.UseNewDikeSlopeOutside = true; location.NewDikeSlopeOutside = 0.5; var surfaceLineAdapter = new SurfaceLineHeightAdapter(surfaceLine, location, 0); SurfaceLine2 newSurfaceLine = surfaceLineAdapter.ConstructNewSurfaceLine(newDikeHeight); var expectedNewTopRiver = new Point2D { X = 3, Z = 2 }; Point2D actualNewTopRiver = newSurfaceLine.CharacteristicPoints.GetPoint2D(CharacteristicPointType.DikeTopAtRiver); Assert.That(expectedNewTopRiver.LocationEquals(actualNewTopRiver), Is.True); var expectedNewTopPolder = new Point2D { X = 6, Z = 2 }; Point2D actualNewTopPolder = newSurfaceLine.CharacteristicPoints.GetPoint2D(CharacteristicPointType.DikeTopAtPolder); Assert.That(expectedNewTopPolder.LocationEquals(actualNewTopPolder), Is.True); var expectedToeInside = new Point2D { X = 9, Z = -1 }; Point2D actualToeInside = newSurfaceLine.CharacteristicPoints.GetPoint2D(CharacteristicPointType.DikeToeAtPolder); Assert.That(expectedToeInside.LocationEquals(actualToeInside), Is.True); Assert.That(newSurfaceLine.Geometry.Points.Count, Is.EqualTo(6)); } [Test] public void AdaptedSurfaceLineWithNewDefinedTopWidthAndOutsideSlopeAndInsideSlope2() { var surfaceLine = new SurfaceLine2 { CharacteristicPoints = { GeometryMustContainPoint = true }, Geometry = new GeometryPointString() }; var location = new Location(); const double newDikeHeight = 2.0; surfaceLine.EnsurePointOfType(0, 0, CharacteristicPointType.DikeToeAtRiver); surfaceLine.EnsurePointOfType(1, 1, CharacteristicPointType.DikeTopAtRiver); surfaceLine.EnsurePointOfType(4, 1, CharacteristicPointType.DikeTopAtPolder); surfaceLine.EnsurePointOfType(5, 0, CharacteristicPointType.ShoulderBaseInside); surfaceLine.EnsurePointOfType(6, 0, CharacteristicPointType.ShoulderTopInside); surfaceLine.EnsurePointOfType(7, -1, CharacteristicPointType.DikeToeAtPolder); surfaceLine.EnsurePointOfType(100, -1, CharacteristicPointType.SurfaceLevelInside); location.UseNewDikeSlopeOutside = true; location.NewDikeSlopeOutside = 2; location.UseNewDikeSlopeInside = true; location.NewDikeSlopeInside = 2; location.UseNewDikeTopWidth = true; location.NewDikeTopWidth = 1.5; var surfaceLineAdapter = new SurfaceLineHeightAdapter(surfaceLine, location, 0); SurfaceLine2 newSurfaceLine = surfaceLineAdapter.ConstructNewSurfaceLine(newDikeHeight); var expectedNewTopRiver = new Point2D { X = 1.5, Z = 2 }; Point2D actualNewTopRiver = newSurfaceLine.CharacteristicPoints.GetPoint2D(CharacteristicPointType.DikeTopAtRiver); Assert.That(expectedNewTopRiver.LocationEquals(actualNewTopRiver), Is.True); var expectedNewTopPolder = new Point2D { X = 3, Z = 2 }; Point2D actualNewTopPolder = newSurfaceLine.CharacteristicPoints.GetPoint2D(CharacteristicPointType.DikeTopAtPolder); Assert.That(expectedNewTopPolder.LocationEquals(actualNewTopPolder), Is.True); var expectedPoint = new Point2D { X = 3.5, Z = 1 }; Point2D actualPoint = newSurfaceLine.Geometry.Points[4]; Assert.That(expectedPoint.LocationEquals(actualPoint), Is.True); var expectedPoint2 = new Point2D { X = 4, Z = 1 }; Point2D actualPoint2 = newSurfaceLine.Geometry.Points[5]; Assert.That(expectedPoint2.LocationEquals(actualPoint2), Is.True); var expectedShoulderBaseInside = new Point2D { X = 5, Z = 0 }; Point2D actualShoulderBaseInside = newSurfaceLine.CharacteristicPoints.GetPoint2D(CharacteristicPointType.ShoulderBaseInside); Assert.That(expectedShoulderBaseInside.LocationEquals(actualShoulderBaseInside), Is.True); var expectedToeInside = new Point2D { X = 7, Z = -1 }; Point2D actualToeInside = newSurfaceLine.CharacteristicPoints.GetPoint2D(CharacteristicPointType.DikeToeAtPolder); Assert.That(expectedToeInside.LocationEquals(actualToeInside), Is.True); Assert.That(newSurfaceLine.Geometry.Points.Count, Is.EqualTo(10)); } [Test] public void AdaptedSurfaceLineWithNewDefinedTopWidthAndOutsideSlopeAndInsideSlope05() { var surfaceLine = new SurfaceLine2 { CharacteristicPoints = { GeometryMustContainPoint = true }, Geometry = new GeometryPointString() }; var location = new Location(); const double newDikeHeight = 2.0; surfaceLine.EnsurePointOfType(0, 0, CharacteristicPointType.DikeToeAtRiver); surfaceLine.EnsurePointOfType(1, 1, CharacteristicPointType.DikeTopAtRiver); surfaceLine.EnsurePointOfType(4, 1, CharacteristicPointType.DikeTopAtPolder); surfaceLine.EnsurePointOfType(5, 0, CharacteristicPointType.ShoulderBaseInside); surfaceLine.EnsurePointOfType(6, 0, CharacteristicPointType.ShoulderTopInside); surfaceLine.EnsurePointOfType(7, -1, CharacteristicPointType.DikeToeAtPolder); surfaceLine.EnsurePointOfType(100, -1, CharacteristicPointType.SurfaceLevelInside); location.UseNewDikeSlopeOutside = true; location.NewDikeSlopeOutside = 2; location.UseNewDikeSlopeInside = true; location.NewDikeSlopeInside = 0.5; location.UseNewDikeTopWidth = true; location.NewDikeTopWidth = 1.5; var surfaceLineAdapter = new SurfaceLineHeightAdapter(surfaceLine, location, 0); SurfaceLine2 newSurfaceLine = surfaceLineAdapter.ConstructNewSurfaceLine(newDikeHeight); var expectedNewTopRiver = new Point2D { X = 1.5, Z = 2 }; Point2D actualNewTopRiver = newSurfaceLine.CharacteristicPoints.GetPoint2D(CharacteristicPointType.DikeTopAtRiver); Assert.That(expectedNewTopRiver.LocationEquals(actualNewTopRiver), Is.True); var expectedNewTopPolder = new Point2D { X = 3, Z = 2 }; Point2D actualNewTopPolder = newSurfaceLine.CharacteristicPoints.GetPoint2D(CharacteristicPointType.DikeTopAtPolder); Assert.That(expectedNewTopPolder.LocationEquals(actualNewTopPolder), Is.True); var expectedToeInside = new Point2D { X = 9, Z = -1 }; Point2D actualToeInside = newSurfaceLine.CharacteristicPoints.GetPoint2D(CharacteristicPointType.DikeToeAtPolder); Assert.That(expectedToeInside.LocationEquals(actualToeInside), Is.True); Assert.That(newSurfaceLine.Geometry.Points.Count, Is.EqualTo(6)); } [Test] public void HeightAdaptionThrowsExceptionIfSurfaceLineIsNotLongEnough() { SurfaceLine2 surfaceLine = FactoryForSurfaceLines.CreateRealisticSurfaceLineForHeightAdapter(); var location = new Location(); const double newDikeHeight = 19.0; var pointSurfaceLevelInside = new Point2D { X = 40, Z = 12 }; // Set surfacelevelinside just beside ditch to force exception surfaceLine.EnsurePointOfType(pointSurfaceLevelInside.X, pointSurfaceLevelInside.Z, CharacteristicPointType.SurfaceLevelInside); var surfaceLineAdapter = new SurfaceLineHeightAdapter(surfaceLine, location, 0); Assert.That(() => surfaceLineAdapter.ConstructNewSurfaceLine(newDikeHeight), Throws.InstanceOf()); } /// /// Create dike with skewed dike table and points between characteristic points /// /// private SurfaceLine2 CreateSurfaceLineWithSkwewedDikeTableAndInBetweenPoints() { var surfaceLine = new SurfaceLine2 { CharacteristicPoints = { GeometryMustContainPoint = true }, Geometry = new GeometryPointString() }; var point1 = new Point2D { X = 0, Z = 0 }; var pointDikeToeAtRiver = new Point2D { X = 2, Z = 0 }; var point2 = new Point2D { X = 4, Z = 1 }; var pointDikeTopAtRiver = new Point2D { X = 6, Z = 3 }; var point3 = new Point2D { X = 7, Z = 3 }; var pointDikeTopAtPolder = new Point2D { X = 8, Z = 3.5 }; var point4 = new Point2D { X = 10, Z = 1.5 }; var pointDikeToeAtPolder = new Point2D { X = 12, Z = 0.5 }; var point5 = new Point2D { X = 13, Z = 0 }; var pointSurfaceLevelInside = new Point2D { X = 100, Z = 0 }; surfaceLine.EnsurePointOfType(pointDikeToeAtRiver.X, pointDikeToeAtRiver.Z, CharacteristicPointType.DikeToeAtRiver); surfaceLine.EnsurePointOfType(pointDikeTopAtRiver.X, pointDikeTopAtRiver.Z, CharacteristicPointType.DikeTopAtRiver); surfaceLine.EnsurePointOfType(pointDikeTopAtPolder.X, pointDikeTopAtPolder.Z, CharacteristicPointType.DikeTopAtPolder); surfaceLine.EnsurePointOfType(pointDikeToeAtPolder.X, pointDikeToeAtPolder.Z, CharacteristicPointType.DikeToeAtPolder); surfaceLine.EnsurePointOfType(pointSurfaceLevelInside.X, pointSurfaceLevelInside.Z, CharacteristicPointType.SurfaceLevelInside); surfaceLine.EnsurePoint(point1.X, point1.Z); surfaceLine.EnsurePoint(point2.X, point2.Z); surfaceLine.EnsurePoint(point3.X, point3.Z); surfaceLine.EnsurePoint(point4.X, point4.Z); surfaceLine.EnsurePoint(point5.X, point5.Z); surfaceLine.SortPoints(); return surfaceLine; } /// /// Determines the tan slope inside. /// /// tan slope inside private static double TanSlopeInside(SurfaceLine2 line) { Point2D dikeToeInward = line.GetDikeToeInward(); Point2D dikeTopAtPolder = line.CharacteristicPoints.GetPoint2D(CharacteristicPointType.DikeTopAtPolder); return (dikeTopAtPolder.Z - dikeToeInward.Z) / (dikeToeInward.X - dikeTopAtPolder.X); } }