Index: DamEngine/trunk/src/Deltares.DamEngine.TestHelpers/Factories/FactoryForSoilProfiles.cs =================================================================== diff -u -r5119 -r5121 --- DamEngine/trunk/src/Deltares.DamEngine.TestHelpers/Factories/FactoryForSoilProfiles.cs (.../FactoryForSoilProfiles.cs) (revision 5119) +++ DamEngine/trunk/src/Deltares.DamEngine.TestHelpers/Factories/FactoryForSoilProfiles.cs (.../FactoryForSoilProfiles.cs) (revision 5121) @@ -1146,7 +1146,7 @@ double rightCoord, Soil soil = null, SoilProfile2D soilProfile2D = null, bool isAquifer = false) { var topLeftPoint = new Point2D(leftCoord, topCoord); - var topRightPoint = new Point2D(rightCoord, topCoord); + var topRightPoint = new Point2D(rightCoord, topCoord); var bottomRightPoint = new Point2D(rightCoord, bottomCoord); var bottomLeftPoint = new Point2D(leftCoord, bottomCoord); var curve1 = new GeometryCurve(topLeftPoint, topRightPoint); @@ -1160,13 +1160,13 @@ AddPointIfNotYetPresentInGeometry(soilProfile2D, topRightPoint); AddPointIfNotYetPresentInGeometry(soilProfile2D, bottomRightPoint); AddPointIfNotYetPresentInGeometry(soilProfile2D, bottomLeftPoint); - AddCurvefNotYetPresentInGeometry(soilProfile2D, curve1); - AddCurvefNotYetPresentInGeometry(soilProfile2D, curve2); - AddCurvefNotYetPresentInGeometry(soilProfile2D, curve3); - AddCurvefNotYetPresentInGeometry(soilProfile2D, curve4); + AddCurveIfNotYetPresentInGeometry(soilProfile2D, curve1); + AddCurveIfNotYetPresentInGeometry(soilProfile2D, curve2); + AddCurveIfNotYetPresentInGeometry(soilProfile2D, curve3); + AddCurveIfNotYetPresentInGeometry(soilProfile2D, curve4); } - return new SoilLayer2D + var soilLayer2D = new SoilLayer2D { GeometrySurface = new GeometrySurface { @@ -1184,51 +1184,35 @@ Soil = soil, IsAquifer = isAquifer }; + soilLayer2D.GeometrySurface.OuterLoop.SyncPoints(); + return soilLayer2D; } public static SoilLayer2D CreateTriangularSoilLayer2D(Point2D point1, Point2D point2, Point2D point3, Soil soil = null, bool isAquifer = false) { - return new SoilLayer2D - { - GeometrySurface = new GeometrySurface + return CreatePolygoneSoilLayer2D([ + ..new[] { - OuterLoop = new GeometryLoop - { - CurveList = - { - new GeometryCurve(point1, point2), - new GeometryCurve(point2, point3), - new GeometryCurve(point3, point1) - } - } - }, - Soil = soil, - IsAquifer = isAquifer - }; + point1, + point2, + point3 + } + ], soil); } public static SoilLayer2D CreateQuadrilateralSoilLayer2D(Point2D point1, Point2D point2, Point2D point3, Point2D point4, Soil soil = null, bool isAquifer = false) { - return new SoilLayer2D - { - GeometrySurface = new GeometrySurface + return CreatePolygoneSoilLayer2D([ + ..new[] { - OuterLoop = new GeometryLoop - { - CurveList = - { - new GeometryCurve(point1, point2), - new GeometryCurve(point2, point3), - new GeometryCurve(point3, point4), - new GeometryCurve(point4, point1) - } - } - }, - Soil = soil, - IsAquifer = isAquifer - }; + point1, + point2, + point3, + point4 + } + ], soil); } - + public static SoilLayer2D CreatePentagonSoilLayer2D(Point2D point1, Point2D point2, Point2D point3, Point2D point4, Point2D point5, Soil soil = null, SoilProfile2D soilProfile2D = null, bool isAquifer = false) { @@ -1246,81 +1230,75 @@ AddPointIfNotYetPresentInGeometry(soilProfile2D, point4); AddPointIfNotYetPresentInGeometry(soilProfile2D, point5); - AddCurvefNotYetPresentInGeometry(soilProfile2D, curve1); - AddCurvefNotYetPresentInGeometry(soilProfile2D, curve2); - AddCurvefNotYetPresentInGeometry(soilProfile2D, curve3); - AddCurvefNotYetPresentInGeometry(soilProfile2D, curve4); - AddCurvefNotYetPresentInGeometry(soilProfile2D, curve5); + AddCurveIfNotYetPresentInGeometry(soilProfile2D, curve1); + AddCurveIfNotYetPresentInGeometry(soilProfile2D, curve2); + AddCurveIfNotYetPresentInGeometry(soilProfile2D, curve3); + AddCurveIfNotYetPresentInGeometry(soilProfile2D, curve4); + AddCurveIfNotYetPresentInGeometry(soilProfile2D, curve5); } - return new SoilLayer2D - { - GeometrySurface = new GeometrySurface + return CreatePolygoneSoilLayer2D([ + ..new[] { - OuterLoop = new GeometryLoop - { - CurveList = - { - curve1, - curve2, - curve3, - curve4, - curve5 - } - } - }, - Soil = soil, - IsAquifer = isAquifer - }; + point1, + point2, + point3, + point4, + point5 + } + ], soil); } public static SoilLayer2D CreateHexagonSoilLayer2D(Point2D point1, Point2D point2, Point2D point3, Point2D point4, Point2D point5, Point2D point6, Soil soil, bool isAquifer = false) { - return new SoilLayer2D - { - GeometrySurface = new GeometrySurface + return CreatePolygoneSoilLayer2D([ + ..new[] { - OuterLoop = new GeometryLoop - { - CurveList = - { - new GeometryCurve(point1, point2), - new GeometryCurve(point2, point3), - new GeometryCurve(point3, point4), - new GeometryCurve(point4, point5), - new GeometryCurve(point5, point6), - new GeometryCurve(point6, point1) - } - } - }, - Soil = soil, - IsAquifer = isAquifer - }; + point1, + point2, + point3, + point4, + point5, + point6 + } + ], soil); } - public static SoilLayer2D CreateHeptagonSoilLayer2D(Point2D point1, Point2D point2, Point2D point3, Point2D point4, Point2D point5, Point2D point6, Point2D point7, Soil soil = null, bool isAquifer = false) + public static SoilLayer2D CreateHeptagonSoilLayer2D(Point2D point1, Point2D point2, Point2D point3, Point2D point4, Point2D point5, Point2D point6, Point2D point7, Soil soil) { - return new SoilLayer2D + return CreatePolygoneSoilLayer2D([ + ..new[] + { + point1, + point2, + point3, + point4, + point5, + point6, + point7 + } + ], soil); + } + + public static SoilLayer2D CreatePolygoneSoilLayer2D(List points, Soil soil) + { + var soilLayer2D = new SoilLayer2D { GeometrySurface = new GeometrySurface { - OuterLoop = new GeometryLoop - { - CurveList = - { - new GeometryCurve(point1, point2), - new GeometryCurve(point2, point3), - new GeometryCurve(point3, point4), - new GeometryCurve(point4, point5), - new GeometryCurve(point5, point6), - new GeometryCurve(point6, point7), - new GeometryCurve(point7, point1) - } - } + OuterLoop = new GeometryLoop() }, Soil = soil, - IsAquifer = isAquifer + IsAquifer = false }; + for (var i = 0; i < points.Count - 1; i++) + { + soilLayer2D.GeometrySurface.OuterLoop.CurveList.Add(new GeometryCurve(points[i], points[i + 1])); + } + soilLayer2D.GeometrySurface.OuterLoop.CurveList.Add(new GeometryCurve(points[^1], points[0])); + soilLayer2D.GeometrySurface.OuterLoop.SyncPoints(); + + return soilLayer2D; } private static void AddPointIfNotYetPresentInGeometry(SoilProfile2D soilProfile, Point2D point) @@ -1331,10 +1309,10 @@ } } - private static void AddCurvefNotYetPresentInGeometry(SoilProfile2D soilProfile, GeometryCurve curve) + private static void AddCurveIfNotYetPresentInGeometry(SoilProfile2D soilProfile, GeometryCurve curve) { if (!soilProfile.Geometry.Curves.Any(c => (c.HeadPoint.X.IsNearEqual(curve.HeadPoint.X) && c.HeadPoint.Z.IsNearEqual(curve.HeadPoint.Z) - && c.EndPoint.X.IsNearEqual(curve.EndPoint.X) && c.EndPoint.Z.IsNearEqual(curve.EndPoint.Z)) || + && c.EndPoint.X.IsNearEqual(curve.EndPoint.X) && c.EndPoint.Z.IsNearEqual(curve.EndPoint.Z)) || (c.EndPoint.X.IsNearEqual(curve.HeadPoint.X) && c.EndPoint.Z.IsNearEqual(curve.HeadPoint.Z) && c.HeadPoint.X.IsNearEqual(curve.EndPoint.X) && c.HeadPoint.Z.IsNearEqual(curve.EndPoint.Z)))) { Index: DamEngine/trunk/src/Deltares.DamEngine.Data.Tests/Geotechnics/SoilProfile2DSurfaceLineHelperTests.cs =================================================================== diff -u -r5119 -r5121 --- DamEngine/trunk/src/Deltares.DamEngine.Data.Tests/Geotechnics/SoilProfile2DSurfaceLineHelperTests.cs (.../SoilProfile2DSurfaceLineHelperTests.cs) (revision 5119) +++ DamEngine/trunk/src/Deltares.DamEngine.Data.Tests/Geotechnics/SoilProfile2DSurfaceLineHelperTests.cs (.../SoilProfile2DSurfaceLineHelperTests.cs) (revision 5121) @@ -23,6 +23,7 @@ using System.Linq; using Deltares.DamEngine.Data.Geometry; using Deltares.DamEngine.Data.Geotechnics; +using Deltares.DamEngine.Data.Standard; using Deltares.DamEngine.TestHelpers.Factories; using Deltares.DamEngine.TestHelpers.Geometry; using NUnit.Framework; @@ -39,7 +40,7 @@ // Use the following code to export the geometry to a file // GeometryExporter.ExportToFile(soilProfile2D.Geometry, visualizationFolder + "Geometry.txt"); // GeometryExporter.ExportToJsonFile(soilProfile2D.Geometry, visualizationFolder + "Geometry.json"); - + private static IEnumerable SurfaceLinesTestCases { get @@ -95,7 +96,7 @@ } } - private static IEnumerable ZigZagSurfaceLinesTestCases + private static IEnumerable ZigZagSurfaceLinesTestCases { get { @@ -105,29 +106,26 @@ var soil4 = new Soil("Soil4"); var soil5 = new Soil("Soil5"); var soil6 = new Soil("Soil6"); - var soil7 = new Soil("Soil7"); - var soil8 = new Soil("Soil8"); - var soil9 = new Soil("Soil9"); - var soil10 = new Soil("Soil10"); + var soilFilling = new Soil("Filling material"); yield return new TestCaseData( new TestCaseZigZagSurfaceLine { TestNumber = 1, GivenZigZagSurfaceLine = FactoryForSurfaceLines.CreateSurfaceLineInZigZag(-50, 10), ExpectedSurfaceCount = 10, // 4 extra surfaces created : 2 below the highest corners of the "zigzag" surface line + 2 on the left side (between Z=60 and 70) - ExpectedFilling1 = FactoryForSoilProfiles.CreateTriangularSoilLayer2D(new Point2D(-50, 10), new Point2D(-30, 12), new Point2D(-10, 10), soil10), - ExpectedFilling2 = FactoryForSoilProfiles.CreateQuadrilateralSoilLayer2D(new Point2D(350, 10), new Point2D(50, 12), new Point2D(60, 11), new Point2D(60, 10), soil10), + ExpectedFilling1 = FactoryForSoilProfiles.CreateQuadrilateralSoilLayer2D(new Point2D(-50, 10), new Point2D(-30, 12), new Point2D(-10, 10), new Point2D(-20, 10), soilFilling), + ExpectedFilling2 = FactoryForSoilProfiles.CreateQuadrilateralSoilLayer2D(new Point2D(30, 10), new Point2D(50, 12), new Point2D(70, 10), new Point2D(60, 10), soilFilling), ExpectedExtendedSurface1 = null, - ExpectedExtendedSurface3 = FactoryForSoilProfiles.CreateRectangularSoilLayer2D(10, 0, 60, 70), + ExpectedExtendedSurface3 = FactoryForSoilProfiles.CreateRectangularSoilLayer2D(10, 0, 60, 70, soil3), ExpectedExtendedSurface4 = null, ExpectedExtendedSurface6 = FactoryForSoilProfiles.CreateRectangularSoilLayer2D(0, -15, 60, 70, soil6), ExpectedSurface1 = FactoryForSoilProfiles.CreateRectangularSoilLayer2D(10, 0, -50, -20, soil1), - ExpectedSurface2 = FactoryForSoilProfiles.CreatePentagonSoilLayer2D(new Point2D(-20, 10), new Point2D(-10, 10), new Point2D(0, 9), new Point2D(0, 0), new Point2D(-20, 0), soil2), - ExpectedSurface3 = FactoryForSoilProfiles.CreateHexagonSoilLayer2D(new Point2D(0, 9), new Point2D(10, 8), new Point2D(30, 10), new Point2D(60, 10), new Point2D(60, 0), new Point2D(0, 0), soil3), - ExpectedSurface4 = FactoryForSoilProfiles.CreateRectangularSoilLayer2D(0, -15, -50, -10, soil4), - ExpectedSurface5 = FactoryForSoilProfiles.CreateRectangularSoilLayer2D(0, -15, -50, -10, soil5), - ExpectedSurface6 = FactoryForSoilProfiles.CreateRectangularSoilLayer2D(0, -15, 35, 600, soil6) + ExpectedSurface2 = FactoryForSoilProfiles.CreateHexagonSoilLayer2D(new Point2D(-20, 10), new Point2D(-10, 10), new Point2D(0, 9), new Point2D(0, 0),new Point2D(-10, 0), new Point2D(-20, 0), soil2), + ExpectedSurface3 = FactoryForSoilProfiles.CreateHeptagonSoilLayer2D(new Point2D(0, 9), new Point2D(10, 8), new Point2D(30, 10), new Point2D(60, 10), new Point2D(60, 0), new Point2D(35, 0), new Point2D(0, 0), soil3), + ExpectedSurface4 = FactoryForSoilProfiles.CreatePentagonSoilLayer2D(new Point2D(-50, 0), new Point2D(-20, 0), new Point2D(-10, 0), new Point2D(-10, -15), new Point2D(-50, -15), soil4), + ExpectedSurface5 = FactoryForSoilProfiles.CreatePentagonSoilLayer2D(new Point2D(-10, 0), new Point2D(0, 0), new Point2D(35, 0), new Point2D(35, -15), new Point2D(-10, -15), soil5), + ExpectedSurface6 = FactoryForSoilProfiles.CreateRectangularSoilLayer2D(0, -15, 35, 60, soil6) }).SetName("Test 1: Surface line intersects the original surface line of soil profile (and shift = 0)"); @@ -138,18 +136,32 @@ GivenZigZagSurfaceLine = FactoryForSurfaceLines.CreateSurfaceLineInZigZag(-50, 13), ExpectedSurfaceCount = 9, // 3 extra surfaces created: 1 below the "zigzag" surface line + 2 on the left side (between Z=60 and 70) - ExpectedFilling1 = FactoryForSoilProfiles.CreateHeptagonSoilLayer2D(new Point2D(-50, 13), new Point2D(-30, 15), new Point2D(10, 11), new Point2D(50, 15), new Point2D(70, 13), new Point2D(70, 10), new Point2D(-50, 10), soil10), + ExpectedFilling1 = FactoryForSoilProfiles.CreatePolygoneSoilLayer2D([ + ..new[] + { + new Point2D(-50, 13), + new Point2D(-30, 15), + new Point2D(10, 11), + new Point2D(50, 15), + new Point2D(70, 13), + new Point2D(70, 10), + new Point2D(60, 10), + new Point2D(0, 10), + new Point2D(-20, 10), + new Point2D(-50, 10) + } + ], soilFilling), ExpectedFilling2 = null, ExpectedExtendedSurface1 = null, ExpectedExtendedSurface3 = FactoryForSoilProfiles.CreateRectangularSoilLayer2D(10, 0, 60, 70, soil3), ExpectedExtendedSurface4 = null, ExpectedExtendedSurface6 = FactoryForSoilProfiles.CreateRectangularSoilLayer2D(0, -15, 60, 70, soil6), ExpectedSurface1 = FactoryForSoilProfiles.CreateRectangularSoilLayer2D(10, 0, -50, -20, soil1), - ExpectedSurface2 = FactoryForSoilProfiles.CreateRectangularSoilLayer2D(10, 0, -20, 0, soil2), - ExpectedSurface3 = FactoryForSoilProfiles.CreateRectangularSoilLayer2D(10, 0, 0, 60, soil3), - ExpectedSurface4 = FactoryForSoilProfiles.CreateRectangularSoilLayer2D(0, -15, -50, -10, soil4), - ExpectedSurface5 = FactoryForSoilProfiles.CreateRectangularSoilLayer2D(0, -15, -50, -10, soil5), - ExpectedSurface6 = FactoryForSoilProfiles.CreateRectangularSoilLayer2D(0, -15, 35, 600, soil6) + ExpectedSurface2 = FactoryForSoilProfiles.CreatePentagonSoilLayer2D(new Point2D(-20, 10), new Point2D(0, 10), new Point2D(0, 0), new Point2D(-10, 0), new Point2D(-20, 0), soil2), + ExpectedSurface3 = FactoryForSoilProfiles.CreatePentagonSoilLayer2D(new Point2D(0, 10), new Point2D(60, 10), new Point2D(60, 0), new Point2D(35, 0), new Point2D(0, 0), soil3), + ExpectedSurface4 = FactoryForSoilProfiles.CreatePentagonSoilLayer2D(new Point2D(-50, 0), new Point2D(-20, 0), new Point2D(-10, 0), new Point2D(-10, -15), new Point2D(-50, -15), soil4), + ExpectedSurface5 = FactoryForSoilProfiles.CreatePentagonSoilLayer2D(new Point2D(-10, 0), new Point2D(0, 0), new Point2D(35, 0), new Point2D(35, -15), new Point2D(-10, -15), soil5), + ExpectedSurface6 = FactoryForSoilProfiles.CreateRectangularSoilLayer2D(0, -15, 35, 60, soil6) }).SetName("Test 2: Surface line is completely above original surface line of soil profile (and shift = 0)"); yield return new TestCaseData( @@ -162,15 +174,15 @@ ExpectedFilling1 = null, ExpectedFilling2 = null, ExpectedExtendedSurface1 = null, - ExpectedExtendedSurface3 = FactoryForSoilProfiles.CreateRectangularSoilLayer2D(10, 0, 60, 70, soil3), + ExpectedExtendedSurface3 = FactoryForSoilProfiles.CreateQuadrilateralSoilLayer2D(new Point2D(60, 6), new Point2D(70, 5), new Point2D(70, 0), new Point2D(60, 0), soil3), ExpectedExtendedSurface4= null, ExpectedExtendedSurface6 = FactoryForSoilProfiles.CreateRectangularSoilLayer2D(0, -15, 60, 70, soil6), ExpectedSurface1 = FactoryForSoilProfiles.CreatePentagonSoilLayer2D(new Point2D(-50, 5), new Point2D(-30, 7), new Point2D(-20, 6), new Point2D(-20, 0), new Point2D(-50, 0),soil1), - ExpectedSurface2 = FactoryForSoilProfiles.CreateQuadrilateralSoilLayer2D(new Point2D(-20, 6), new Point2D(0, 4), new Point2D(0, 0), new Point2D(-20, 0), soil2), - ExpectedSurface3 = FactoryForSoilProfiles.CreateHexagonSoilLayer2D(new Point2D(0, 4), new Point2D(10, 3), new Point2D(50, 7), new Point2D(60, 6), new Point2D(60, 0), new Point2D(0, 0), soil3), - ExpectedSurface4 = FactoryForSoilProfiles.CreateRectangularSoilLayer2D(0, -15, -50, -10, soil4), - ExpectedSurface5 = FactoryForSoilProfiles.CreateRectangularSoilLayer2D(0, -15, -50, -10, soil5), - ExpectedSurface6 = FactoryForSoilProfiles.CreateRectangularSoilLayer2D(0, -15, 35, 600, soil6) + ExpectedSurface2 = FactoryForSoilProfiles.CreatePentagonSoilLayer2D(new Point2D(-20, 6), new Point2D(0, 4), new Point2D(0, 0), new Point2D(-10, 0),new Point2D(-20, 0), soil2), + ExpectedSurface3 = FactoryForSoilProfiles.CreateHeptagonSoilLayer2D(new Point2D(0, 4), new Point2D(10, 3), new Point2D(50, 7), new Point2D(60, 6), new Point2D(60, 0), new Point2D(35, 0), new Point2D(0, 0), soil3), + ExpectedSurface4 = FactoryForSoilProfiles.CreatePentagonSoilLayer2D(new Point2D(-50, 0), new Point2D(-20, 0), new Point2D(-10, 0), new Point2D(-10, -15), new Point2D(-50, -15), soil4), + ExpectedSurface5 = FactoryForSoilProfiles.CreatePentagonSoilLayer2D(new Point2D(-10, 0), new Point2D(0, 0), new Point2D(35, 0), new Point2D(35, -15), new Point2D(-10, -15), soil5), + ExpectedSurface6 = FactoryForSoilProfiles.CreateRectangularSoilLayer2D(0, -15, 35, 60, soil6) }).SetName("Test 3: Surface line is completely in the top layer of the soil profile (and shift = 0)"); yield return new TestCaseData( @@ -186,12 +198,12 @@ ExpectedExtendedSurface3 = FactoryForSoilProfiles.CreateTriangularSoilLayer2D(new Point2D(60, 1), new Point2D(70, 0), new Point2D(60, 0), soil3), ExpectedExtendedSurface4 = null, ExpectedExtendedSurface6 = FactoryForSoilProfiles.CreateRectangularSoilLayer2D(0, -15, 60, 70, soil6), - ExpectedSurface1 = FactoryForSoilProfiles.CreatePentagonSoilLayer2D(new Point2D(-50, 5), new Point2D(-30, 7), new Point2D(-20, 6), new Point2D(-20, 0), new Point2D(-50, 0),soil1), + ExpectedSurface1 = FactoryForSoilProfiles.CreateQuadrilateralSoilLayer2D(new Point2D(-50, 0), new Point2D(-30, 2), new Point2D(-20, 1), new Point2D(-20, 0), soil1), ExpectedSurface2 = FactoryForSoilProfiles.CreateTriangularSoilLayer2D(new Point2D(-20, 1), new Point2D(-10, 0), new Point2D(-20, 0), soil2), - ExpectedSurface3 = FactoryForSoilProfiles.CreateQuadrilateralSoilLayer2D(new Point2D(35, 0), new Point2D(50, 2), new Point2D(60, 1), new Point2D(60, 0), soil3), - ExpectedSurface4 = FactoryForSoilProfiles.CreateRectangularSoilLayer2D(0, -15, -50, -10, soil4), - ExpectedSurface5 = FactoryForSoilProfiles.CreatePentagonSoilLayer2D(new Point2D(-10, 0), new Point2D(10, -2), new Point2D(35, 0), new Point2D(35, -15), new Point2D(-10, -15), soil5), - ExpectedSurface6 = FactoryForSoilProfiles.CreateRectangularSoilLayer2D(0, -15, 35, 600, soil6) + ExpectedSurface3 = FactoryForSoilProfiles.CreatePentagonSoilLayer2D(new Point2D(30, 0), new Point2D(50, 2), new Point2D(60, 1), new Point2D(60, 0), new Point2D(35, 0), soil3), + ExpectedSurface4 = FactoryForSoilProfiles.CreatePentagonSoilLayer2D(new Point2D(-50, 0), new Point2D(-20, 0), new Point2D(-10, 0), new Point2D(-10, -15), new Point2D(-50, -15), soil4), + ExpectedSurface5 = FactoryForSoilProfiles.CreateHexagonSoilLayer2D(new Point2D(-10, 0), new Point2D(10, -2), new Point2D(30, 0), new Point2D(35, 0), new Point2D(35, -15), new Point2D(-10, -15), soil5), + ExpectedSurface6 = FactoryForSoilProfiles.CreateRectangularSoilLayer2D(0, -15, 35, 60, soil6) }).SetName("Test 4: Surface line intersects the original layer separation of soil profile (and shift = 0)"); yield return new TestCaseData( @@ -217,16 +229,16 @@ GivenZigZagSurfaceLine = FactoryForSurfaceLines.CreateSurfaceLineInZigZag(-40, 10), ExpectedSurfaceCount = 10, // Only few surfaces are tested - ExpectedFilling1 = FactoryForSoilProfiles.CreateTriangularSoilLayer2D(new Point2D(-60, 10), new Point2D(-40, 12), new Point2D(-20, 10), soil10), - ExpectedFilling2 = FactoryForSoilProfiles.CreateTriangularSoilLayer2D(new Point2D(40, 10), new Point2D(60, 12), new Point2D(80, 10), soil10), + ExpectedFilling1 = FactoryForSoilProfiles.CreateQuadrilateralSoilLayer2D(new Point2D(-40, 10), new Point2D(-20, 12), new Point2D(0, 10), new Point2D(-20, 10), soilFilling), + ExpectedFilling2 = FactoryForSoilProfiles.CreateQuadrilateralSoilLayer2D(new Point2D(40, 10), new Point2D(60, 12), new Point2D(80, 10), new Point2D(60, 10), soilFilling), ExpectedExtendedSurface1 = null, ExpectedExtendedSurface3 = FactoryForSoilProfiles.CreateRectangularSoilLayer2D(10, 0, 60, 80, soil3), ExpectedExtendedSurface4 = null, ExpectedExtendedSurface6 = FactoryForSoilProfiles.CreateRectangularSoilLayer2D(0, -15, 60, 80, soil6), ExpectedSurface1 = FactoryForSoilProfiles.CreateRectangularSoilLayer2D(10, 0, -40, -20, soil1), ExpectedSurface2 = null, // not null but not tested ExpectedSurface3 = null, // not null but not tested - ExpectedSurface4 = FactoryForSoilProfiles.CreateRectangularSoilLayer2D(0, -15, -40, -10, soil4), + ExpectedSurface4 = FactoryForSoilProfiles.CreatePentagonSoilLayer2D(new Point2D(-40, 0), new Point2D(-20, 0), new Point2D(-10, 0), new Point2D(-10, -15), new Point2D(-40, -15), soil4), ExpectedSurface5 = null, // not null but not tested ExpectedSurface6 = null // not null but not tested }).SetName("Test 7: Surface line intersects the original surface line of soil profile (and shift = +10)"); @@ -238,15 +250,15 @@ GivenZigZagSurfaceLine = FactoryForSurfaceLines.CreateSurfaceLineInZigZag(10, 10), ExpectedSurfaceCount = 7, // Only few surfaces are tested - ExpectedFilling1 = FactoryForSoilProfiles.CreateTriangularSoilLayer2D(new Point2D(10, 10), new Point2D(30, 12), new Point2D(50, 10), soil10), - ExpectedFilling2 = FactoryForSoilProfiles.CreateTriangularSoilLayer2D(new Point2D(90, 10), new Point2D(110, 12), new Point2D(130, 10), soil10), + ExpectedFilling1 = FactoryForSoilProfiles.CreateTriangularSoilLayer2D(new Point2D(10, 10), new Point2D(30, 12), new Point2D(50, 10), soilFilling), + ExpectedFilling2 = FactoryForSoilProfiles.CreateTriangularSoilLayer2D(new Point2D(90, 10), new Point2D(110, 12), new Point2D(130, 10), soilFilling), ExpectedExtendedSurface1 = null, - ExpectedExtendedSurface3 = FactoryForSoilProfiles.CreateRectangularSoilLayer2D(10, 0, 60, 120, soil3), + ExpectedExtendedSurface3 = FactoryForSoilProfiles.CreateHexagonSoilLayer2D(new Point2D(60, 9), new Point2D(70, 8), new Point2D(90, 10), new Point2D(130, 10), new Point2D(130, 0), new Point2D(60, 0), soil3), ExpectedExtendedSurface4 = null, - ExpectedExtendedSurface6 = FactoryForSoilProfiles.CreateRectangularSoilLayer2D(0, -15, 60, 120, soil6), + ExpectedExtendedSurface6 = FactoryForSoilProfiles.CreateRectangularSoilLayer2D(0, -15, 60, 130, soil6), ExpectedSurface1 = null, ExpectedSurface2 = null, - ExpectedSurface3 = FactoryForSoilProfiles.CreateHexagonSoilLayer2D(new Point2D(10, 9), new Point2D(20, 8), new Point2D(40, 10), new Point2D(60, 10), new Point2D(60, 0), new Point2D(10, 0), soil3), + ExpectedSurface3 = FactoryForSoilProfiles.CreateHexagonSoilLayer2D(new Point2D(10, 10), new Point2D(50, 10), new Point2D(60, 9), new Point2D(60, 0), new Point2D(35, 0), new Point2D(10, 0), soil3), ExpectedSurface4 = null, ExpectedSurface5 = FactoryForSoilProfiles.CreateRectangularSoilLayer2D(0, -15, 10, 35, soil5), ExpectedSurface6 = null // not null but not tested @@ -259,8 +271,8 @@ GivenZigZagSurfaceLine = FactoryForSurfaceLines.CreateSurfaceLineInZigZag(-60, 10), ExpectedSurfaceCount = 10, // Only few surfaces are tested - ExpectedFilling1 = FactoryForSoilProfiles.CreateTriangularSoilLayer2D(new Point2D(-60, 10), new Point2D(-40, 12), new Point2D(-20, 10), soil10), - ExpectedFilling2 = FactoryForSoilProfiles.CreateTriangularSoilLayer2D(new Point2D(20, 10), new Point2D(40, 12), new Point2D(60, 10), soil10), + ExpectedFilling1 = FactoryForSoilProfiles.CreateQuadrilateralSoilLayer2D(new Point2D(-60, 10), new Point2D(-40, 12), new Point2D(-20, 10), new Point2D(-50, 10), soilFilling), + ExpectedFilling2 = FactoryForSoilProfiles.CreateTriangularSoilLayer2D(new Point2D(20, 10), new Point2D(40, 12), new Point2D(60, 10), soilFilling), ExpectedExtendedSurface1 = FactoryForSoilProfiles.CreateRectangularSoilLayer2D(10, 0, -60, -50, soil1), ExpectedExtendedSurface3 = null, ExpectedExtendedSurface4 = FactoryForSoilProfiles.CreateRectangularSoilLayer2D(0, -15, -60, -50, soil4), @@ -277,20 +289,20 @@ new TestCaseZigZagSurfaceLine { TestNumber = 10, - GivenZigZagSurfaceLine = FactoryForSurfaceLines.CreateSurfaceLineInZigZag(-60, 10), + GivenZigZagSurfaceLine = FactoryForSurfaceLines.CreateSurfaceLineInZigZag(-110, 10), ExpectedSurfaceCount = 9, // Only few surfaces are tested - ExpectedFilling1 = FactoryForSoilProfiles.CreateTriangularSoilLayer2D(new Point2D(-110, 10), new Point2D(-90, 11), new Point2D(-70, 10), soil10), - ExpectedFilling2 = FactoryForSoilProfiles.CreateTriangularSoilLayer2D(new Point2D(-30, 10), new Point2D(-10, 12), new Point2D(10, 10), soil10), - ExpectedExtendedSurface1 = FactoryForSoilProfiles.CreateRectangularSoilLayer2D(10, 0, -110, -50, soil1), + ExpectedFilling1 = FactoryForSoilProfiles.CreateTriangularSoilLayer2D(new Point2D(-110, 10), new Point2D(-90, 12), new Point2D(-70, 10), soilFilling), + ExpectedFilling2 = FactoryForSoilProfiles.CreatePentagonSoilLayer2D(new Point2D(-30, 10), new Point2D(-10, 12), new Point2D(10, 10), new Point2D(0, 10), new Point2D(-20, 10), soilFilling), + ExpectedExtendedSurface1 = FactoryForSoilProfiles.CreatePentagonSoilLayer2D(new Point2D(-110, 10), new Point2D(-70, 10), new Point2D(-50, 8), new Point2D(-50, 0), new Point2D(-110, 0), soil1), ExpectedExtendedSurface3 = null, ExpectedExtendedSurface4 = FactoryForSoilProfiles.CreateRectangularSoilLayer2D(0, -15, -110, -50, soil4), ExpectedExtendedSurface6 = null, ExpectedSurface1 = null, // not null but not tested ExpectedSurface2 = null, // not null but not tested ExpectedSurface3 = null, // not null but not tested ExpectedSurface4 = null, //not null but not tested - ExpectedSurface5 = FactoryForSoilProfiles.CreateRectangularSoilLayer2D(0, -15, -10, 10, soil5), + ExpectedSurface5 = FactoryForSoilProfiles.CreatePentagonSoilLayer2D(new Point2D(-10, 0), new Point2D(0, 0), new Point2D(10, 0), new Point2D(10, -15), new Point2D(-10, -15), soil5), ExpectedSurface6 = null }).SetName("Test 10: Surface line intersects the original surface line of soil profile (and shift = -60)"); @@ -305,7 +317,7 @@ ExpectedExtendedSurface1 = null, ExpectedExtendedSurface3 = null, ExpectedExtendedSurface4 = null, - ExpectedExtendedSurface6 = FactoryForSoilProfiles.CreateHeptagonSoilLayer2D(new Point2D(60, -4), new Point2D(70, -3), new Point2D(110, -5), new Point2D(150, -3), new Point2D(190, -5), new Point2D(190, -15), new Point2D(60, -15),soil6), + ExpectedExtendedSurface6 = FactoryForSoilProfiles.CreateHeptagonSoilLayer2D(new Point2D(60, -4), new Point2D(70, -3), new Point2D(110, -7), new Point2D(150, -3), new Point2D(170, -5), new Point2D(170, -15), new Point2D(60, -15),soil6), ExpectedSurface1 = null, ExpectedSurface2 = null, ExpectedSurface3 = null, @@ -356,14 +368,14 @@ } [Test, TestCaseSource(nameof(ZigZagSurfaceLinesTestCases))] - [Ignore("Work in progress")] + //[Ignore("Work in progress")] public void GivenComplexSoilProfile2D_WhenCombiningWithZigZagSurfaceLine_ThenCorrectNewSoilProfile2DIsCreated(TestCaseZigZagSurfaceLine testCaseSurfaceLine) { // Given SoilProfile2D soilProfile2D = FactoryForSoilProfiles.CreateSoilProfile2DWithSixSurfacesFormingTwoLayers(); // For debugging purposes - // GeometryExporter.ExportToJsonFile(soilProfile2D.Geometry, visualizationFolder + "Geometry.json"); - // GeometryExporter.ExportToFile(soilProfile2D.Geometry, visualizationFolder + "Geometry.txt"); + // GeometryExporter.ExportToJsonFile(soilProfile2D.Geometry, visualizationFolder + "Geometry.json"); + // GeometryExporter.ExportToFile(soilProfile2D.Geometry, visualizationFolder + "Geometry.txt"); var defaultSoil = new Soil { Name = "Filling material" @@ -372,8 +384,8 @@ SoilProfile2D newSoilProfile2D = SoilProfile2DSurfaceLineHelper.CombineSurfaceLineWithSoilProfile2D( testCaseSurfaceLine.GivenZigZagSurfaceLine.Geometry, soilProfile2D, defaultSoil, 0); // For debugging purposes - GeometryExporter.ExportToFile(newSoilProfile2D.Geometry, visualizationFolder + "Geometry" + testCaseSurfaceLine.TestNumber + ".txt"); - GeometryExporter.ExportToJsonFile(newSoilProfile2D.Geometry, visualizationFolder + "Geometry" + testCaseSurfaceLine.TestNumber + ".json"); + //GeometryExporter.ExportToFile(newSoilProfile2D.Geometry, visualizationFolder + "Geometry" + testCaseSurfaceLine.TestNumber + ".txt"); + //GeometryExporter.ExportToJsonFile(newSoilProfile2D.Geometry, visualizationFolder + "Geometry" + testCaseSurfaceLine.TestNumber + ".json"); // Then if (testCaseSurfaceLine.ExpectedSurfaceCount == 0) { @@ -440,8 +452,7 @@ public SoilLayer2D ExpectedExtendedSurface6 { get; init; } public SoilLayer2D ExpectedFilling1 { get; init; } public SoilLayer2D ExpectedFilling2 { get; init; } - - public int TestNumber { get; set; } + public int TestNumber { get; init; } } /// @@ -493,9 +504,61 @@ private static void CheckSoilProfileContainsSoilLayer(SoilProfile2D soilProfile2D, SoilLayer2D expectedSoilLayer) { - if (expectedSoilLayer != null) + if (expectedSoilLayer == null) { - Assert.That(soilProfile2D.Surfaces.Contains(expectedSoilLayer)); + return; } + + int indexLayer = -1; + // Find a point within the expected soil layer + double[] xMin = expectedSoilLayer.GeometrySurface.OuterLoop.CalcPoints.Select(p => p.X).OrderBy(x => x).Distinct().ToArray(); + double[] zMin = expectedSoilLayer.GeometrySurface.OuterLoop.CalcPoints.Select(p => p.Z).OrderBy(z => z).Distinct().ToArray(); + var gravityPoint = new Point2D + { + X = xMin[0] + 2, + Z = zMin[0] + 0.2 + }; + + for (var i = 0; i < soilProfile2D.Surfaces.Count; i++) + { + bool find = soilProfile2D.Surfaces[i].GeometrySurface.OuterLoop.IsPointInLoopArea(gravityPoint); + if (find) + { + indexLayer = i; + break; + } + } + Assert.That(indexLayer, Is.GreaterThan(-1), "The soil layer was not found "); + + Assert.Multiple(() => + { + Assert.That(soilProfile2D.Surfaces[indexLayer].SoilName, Is.EqualTo(expectedSoilLayer.SoilName)); + Assert.That(soilProfile2D.Geometry.Surfaces[indexLayer].OuterLoop.CalcPoints, Has.Count.EqualTo(expectedSoilLayer.GeometrySurface.OuterLoop.CalcPoints.Count)); + Assert.That(soilProfile2D.Geometry.Surfaces[indexLayer].OuterLoop.CurveList, Has.Count.EqualTo(expectedSoilLayer.GeometrySurface.OuterLoop.CurveList.Count)); + Assert.That(soilProfile2D.Surfaces[indexLayer].GeometrySurface.OuterLoop.CalcPoints, Has.Count.EqualTo(expectedSoilLayer.GeometrySurface.OuterLoop.CalcPoints.Count)); + Assert.That(soilProfile2D.Surfaces[indexLayer].GeometrySurface.OuterLoop.CurveList, Has.Count.EqualTo(expectedSoilLayer.GeometrySurface.OuterLoop.CurveList.Count)); + }); + foreach (GeometryCurve curve in expectedSoilLayer.GeometrySurface.OuterLoop.CurveList) + { + Assert.That(IsCurvePresentInSoilLayer(soilProfile2D.Surfaces[indexLayer], curve), Is.True); + } + foreach (Point2D point in expectedSoilLayer.GeometrySurface.OuterLoop.CalcPoints) + { + Assert.That(IsPointPresentInSoilLayer(soilProfile2D.Surfaces[indexLayer], point), Is.True); + } } + + private static bool IsPointPresentInSoilLayer(SoilLayer2D soilLayer, Point2D point) + { + return soilLayer.GeometrySurface.OuterLoop.Points.Any(p => p.X.IsNearEqual(point.X) && p.Z.IsNearEqual(point.Z)); + } + + private static bool IsCurvePresentInSoilLayer(SoilLayer2D soilLayer, GeometryCurve curve) + { + return soilLayer.GeometrySurface.OuterLoop.CurveList.Any(c => (c.HeadPoint.X.IsNearEqual(curve.HeadPoint.X) && c.HeadPoint.Z.IsNearEqual(curve.HeadPoint.Z) + && c.EndPoint.X.IsNearEqual(curve.EndPoint.X) && c.EndPoint.Z.IsNearEqual(curve.EndPoint.Z)) || + (c.EndPoint.X.IsNearEqual(curve.HeadPoint.X) && c.EndPoint.Z.IsNearEqual(curve.HeadPoint.Z) && + c.HeadPoint.X.IsNearEqual(curve.EndPoint.X) && c.HeadPoint.Z.IsNearEqual(curve.EndPoint.Z))); + + } } \ No newline at end of file