Index: DamEngine/trunk/src/Deltares.DamEngine.Data.Tests/Geotechnics/SoilSurfaceProfileTests.cs =================================================================== diff -u -r3079 -r3228 --- DamEngine/trunk/src/Deltares.DamEngine.Data.Tests/Geotechnics/SoilSurfaceProfileTests.cs (.../SoilSurfaceProfileTests.cs) (revision 3079) +++ DamEngine/trunk/src/Deltares.DamEngine.Data.Tests/Geotechnics/SoilSurfaceProfileTests.cs (.../SoilSurfaceProfileTests.cs) (revision 3228) @@ -19,12 +19,14 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved.using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Deltares.DamEngine.Data.Geometry; using Deltares.DamEngine.Data.Geotechnics; +using Deltares.DamEngine.Data.Standard; using Deltares.DamEngine.TestHelpers.Factories; using NUnit.Framework; @@ -58,6 +60,107 @@ Assert.AreEqual(3, profile2D.Surfaces.Count); } + [Test] + public void ConvertToSoilProfile2D_WithSurfaceLineAboveSoilLayers_SetsCorrectSurfacesAndGeometry() + { + // Setup + const string bottomLayerName = "BottomLayer"; + const string middleLayerName = "MiddleLayer"; + const string topLayerName = "TopLayer"; + + var profile = new SoilProfile1D + { + BottomLevel = -10 + }; + profile.Layers.Add(CreateSoilLayer(-5, bottomLayerName)); + profile.Layers.Add(CreateSoilLayer(-2, middleLayerName)); + + SurfaceLine2 surfaceLine = CreateSurfaceLine(new[] + { + new GeometryPoint(0, 0), + new GeometryPoint(5, 10), + new GeometryPoint(10, 10) + }); + + var soilSurfaceProfile = new SoilSurfaceProfile + { + SoilProfile = profile, + SurfaceLine2 = surfaceLine, + DikeEmbankmentMaterial = new Soil + { + Name = topLayerName + } + }; + + // Call + soilSurfaceProfile.ConvertToSoilProfile2D(); + + // Assert + var soilLayer2Ds = soilSurfaceProfile.Surfaces; + Assert.That(soilLayer2Ds, Has.Count.EqualTo(3)); + + GeometryLoop topSurface = soilLayer2Ds.Single(l => string.Equals(l.Name, topLayerName)).GeometrySurface.OuterLoop; + AssertGeometry(new [] + { + new GeometryCurve(new Point2D(10, -2), new Point2D(0, -2)), + new GeometryCurve(new Point2D(0, -2), new Point2D(0, 0)), + new GeometryCurve(new Point2D(0, 0), new Point2D(5, 10)), + new GeometryCurve(new Point2D(5, 10), new Point2D(10, 10)), + new GeometryCurve(new Point2D(10, 10), new Point2D(10, -2)), + }, topSurface.CurveList); + + GeometryLoop middleSurface = soilLayer2Ds.Single(l => string.Equals(l.Name, middleLayerName)).GeometrySurface.OuterLoop; + AssertGeometry(new[] + { + new GeometryCurve(new Point2D(0, -2), new Point2D(10, -2)), + new GeometryCurve(new Point2D(10, -2), new Point2D(10, -5)), + new GeometryCurve(new Point2D(10, -5), new Point2D(0, -5)), + new GeometryCurve(new Point2D(0, -5), new Point2D(0, -2)) + }, middleSurface.CurveList); + + GeometryLoop bottomSurface = soilLayer2Ds.Single(l => string.Equals(l.Name, bottomLayerName)).GeometrySurface.OuterLoop; + AssertGeometry(new[] + { + new GeometryCurve(new Point2D(0, -5), new Point2D(10, -5)), + new GeometryCurve(new Point2D(10, -5), new Point2D(10, -10)), + new GeometryCurve(new Point2D(10, -10), new Point2D(0, -10)), + new GeometryCurve(new Point2D(0, -10), new Point2D(0, -5)) + }, bottomSurface.CurveList); + } + + private static void AssertGeometry(IEnumerable expectedCurves, IEnumerable actualCurves) + { + int nrOfExpectedCurves = expectedCurves.Count(); + Assert.That(actualCurves.Count(), Is.EqualTo(nrOfExpectedCurves)); + + for (int i = 0; i < nrOfExpectedCurves; i++) + { + GeometryCurve expectedCurve = expectedCurves.ElementAt(i); + GeometryCurve actualCurve = actualCurves.ElementAt(i); + + Assert.That(actualCurve.LocationEquals(expectedCurve), Is.True); + } + } + + private static SoilLayer1D CreateSoilLayer(double topLevel, string soilName) + { + return new SoilLayer1D + { + TopLevel = topLevel, + Soil = new Soil(soilName) + }; + } + + private static SurfaceLine2 CreateSurfaceLine(IEnumerable coordinates) + { + var surfaceLine = new SurfaceLine2(); + surfaceLine.Geometry.Points.AddRange(coordinates); + + surfaceLine.Geometry.SyncCalcPoints(); + + return surfaceLine; + } + private static SoilProfile1D CreateTwoLayerProfile(double offset = 0) { var soilProfile = new SoilProfile1D();