//----------------------------------------------------------------------- // // Copyright (c) 2010 Deltares. All rights reserved. // // Tom The // tom.the@deltares.nl // 07-06-2010 // // Tests for DikeCoordinateSystemConverter object // //----------------------------------------------------------------------- using Deltares.Geometry; using Deltares.Geotechnics; using Deltares.Geotechnics.GeotechnicalGeometry; using System; using Deltares.Dam.Data; using Deltares.Geotechnics.SurfaceLines; using NUnit.Framework; namespace Deltares.Dam.Tests { [TestFixture] public class DikeCoordinateSystemConverterTest { const int cSheetPilingPointIndex = 1; /// /// Create result surfaceline /// /// private SurfaceLine2 CreateResultingLocalSurfaceLine() { var surfaceline = new SurfaceLine2 { Name = "SL1", Geometry = new LocalizedGeometryPointString(), CharacteristicPoints = { GeometryMustContainPoint = true } }; surfaceline.AddCharacteristicPoint(new GeometryPoint(0.0000, 0.0000, 0.0000)); surfaceline.AddCharacteristicPoint(new GeometryPoint(27.9508, 0.0000, 2.50000)); surfaceline.AddCharacteristicPoint(new GeometryPoint(55.9017, 0.0000, 5.00000)); surfaceline.AddCharacteristicPoint(new GeometryPoint(83.8525, 0.0000, 7.50000)); surfaceline.AddCharacteristicPoint(new GeometryPoint(111.8034, 0.0000, 10.0000)); return surfaceline; } /// /// Create test surfaceline /// /// a surfaceline with angle in XY plane between 0 and 90 degrees private SurfaceLine2 CreateGlobalSurfaceLineWithAlphaBetween0and90Degrees() { var surfaceline = new SurfaceLine2 { Geometry = new LocalizedGeometryPointString(), CharacteristicPoints = { GeometryMustContainPoint = true } }; surfaceline.AddCharacteristicPoint(new GeometryPoint(10000.0, 20000.0, 0.0)); surfaceline.AddCharacteristicPoint(new GeometryPoint(10012.5, 20025.0, 2.5)); surfaceline.AddCharacteristicPoint(new GeometryPoint(10025.0, 20050.0, 5.0)); surfaceline.AddCharacteristicPoint(new GeometryPoint(10037.5, 20075.0, 7.5)); surfaceline.AddCharacteristicPoint(new GeometryPoint(10050.0, 20100.0, 10.0)); return surfaceline; } /// /// Create test surfaceline /// /// a surfaceline with angle in XY plane between 0 and 90 degrees private SurfaceLine2 CreateGlobalSurfaceLineSteepWithAlphaBetween0and90Degrees() { var surfaceline = new SurfaceLine2 { Geometry = new LocalizedGeometryPointString(), CharacteristicPoints = { GeometryMustContainPoint = true } }; surfaceline.AddCharacteristicPoint(new GeometryPoint(10000.00, 20000.00, 0.0)); surfaceline.AddCharacteristicPoint(new GeometryPoint(10025.00, 20012.50, 2.5)); surfaceline.AddCharacteristicPoint(new GeometryPoint(10050.00, 20025.00, 5.0)); surfaceline.AddCharacteristicPoint(new GeometryPoint(10075.00, 20037.50, 7.5)); surfaceline.AddCharacteristicPoint(new GeometryPoint(10100.00, 20050.00, 10.0)); return surfaceline; } /// /// Create result PL1-line /// /// private PL1Line CreateResultingLocalPL1Line() { var pl1line = new PL1Line(); pl1line.Points.Add(new GeometryPoint(0.0000, 0.0000, -1.0000)); pl1line.Points.Add(new GeometryPoint(27.9508, 0.0000, 1.50000)); pl1line.Points.Add(new GeometryPoint(55.9017, 0.0000, 4.00000)); pl1line.Points.Add(new GeometryPoint(83.8525, 0.0000, 6.50000)); pl1line.Points.Add(new GeometryPoint(111.8034, 0.0000, 9.0000)); return pl1line; } /// /// Create test PL1-line /// /// a Pl1-line with angle in XY plane between 0 and 90 degrees private PL1Line CreateGlobalPL1LineWithAlphaBetween0and90Degrees() { var pl1line = new PL1Line(); pl1line.Points.Add(new GeometryPoint(10000.0, 20000.0, -1.0)); pl1line.Points.Add(new GeometryPoint(10012.5, 20025.0, 1.5)); pl1line.Points.Add(new GeometryPoint(10025.0, 20050.0, 4.0)); pl1line.Points.Add(new GeometryPoint(10037.5, 20075.0, 6.5)); pl1line.Points.Add(new GeometryPoint(10050.0, 20100.0, 9.0)); return pl1line; } /// /// Create test PL1-line /// /// a surfaceline with angle in XY plane between 0 and 90 degrees private PL1Line CreateGlobalPL1LineSteepWithAlphaBetween0and90Degrees() { var pl1line = new PL1Line(); pl1line.Points.Add(new GeometryPoint(10000.00, 20000.00, -1.0)); pl1line.Points.Add(new GeometryPoint(10025.00, 20012.50, 1.5)); pl1line.Points.Add(new GeometryPoint(10050.00, 20025.00, 4.0)); pl1line.Points.Add(new GeometryPoint(10075.00, 20037.50, 6.5)); pl1line.Points.Add(new GeometryPoint(10100.00, 20050.00, 9.0)); return pl1line; } /// /// Test /// [Test] [ExpectedException(typeof(DikeCoordinateSystemConverterException))] public void ThrowsExceptionIfDikeNotComplete() { var dikeCoordinateSystemConverter = new DikeCoordinateSystemConverter(); using (Dike dike = new Dike()) { dikeCoordinateSystemConverter.CreateLocalXZObjects(dike); } } /// /// Checks converted local surfaceline with reference surfaceline /// /// private void CheckResultingLocalSurfaceLine(SurfaceLine2 localSurfaceLine) { using (SurfaceLine2 expectedLocalSurfaceLine = CreateResultingLocalSurfaceLine()) { Assert.AreEqual(expectedLocalSurfaceLine.Geometry.Count, localSurfaceLine.Geometry.Points.Count, String.Format("Surfaceline line {0}", localSurfaceLine.Name)); for (int pointIndex = 0; pointIndex < localSurfaceLine.Geometry.Points.Count; pointIndex++) { Assert.IsTrue(localSurfaceLine.Geometry.Points[pointIndex].LocationEquals(expectedLocalSurfaceLine.Geometry.Points[pointIndex]), String.Format("Surfaceline {0} GeometryPoint {1} converted incorrectly", localSurfaceLine.Name, pointIndex)); } } } /// /// Checks converted local PL1-line with reference PL1-line /// /// private void CheckResultingLocalPL1Line(PL1Line localPL1Line) { PL1Line expectedLocalPL1Line = CreateResultingLocalPL1Line(); Assert.AreEqual(expectedLocalPL1Line.Points.Count, localPL1Line.Points.Count, String.Format("PL1 line {0}", localPL1Line.Name)); for (int pointIndex = 0; pointIndex < localPL1Line.Points.Count; pointIndex++) { Assert.IsTrue(localPL1Line.Points[pointIndex].LocationEquals(expectedLocalPL1Line.Points[pointIndex]), String.Format("PL1 line {0} GeometryPoint {1} converted incorrectly", localPL1Line.Name, pointIndex)); } } /// /// Create test dike /// /// private Dike CreateDike() { var dike = new Dike(); // Location 1 surface line SurfaceLine2 surfaceLine; surfaceLine = CreateGlobalSurfaceLineWithAlphaBetween0and90Degrees(); surfaceLine.Name = "SL1"; dike.SurfaceLines2.Add(surfaceLine); // Location 1 pl1 line PL1Line pl1Line; pl1Line = CreateGlobalPL1LineWithAlphaBetween0and90Degrees(); pl1Line.Name = "PL1_1"; dike.PL1Lines.Add(pl1Line); // Location 1 Location location = new Location(); location.Name = "Loc1"; location.SurfaceLine2 = surfaceLine; location.PL1Line = pl1Line; dike.Locations.Add(location); // Location 2 surface line surfaceLine = CreateGlobalSurfaceLineSteepWithAlphaBetween0and90Degrees(); surfaceLine.Name = "SL2"; dike.SurfaceLines2.Add(surfaceLine); // Location 2 pl1 line pl1Line = CreateGlobalPL1LineSteepWithAlphaBetween0and90Degrees(); pl1Line.Name = "PL1_2"; dike.PL1Lines.Add(pl1Line); // Location 2 (with sheetpiling) location = new Location(); location.Name = "Loc2"; location.SurfaceLine2 = surfaceLine; location.PL1Line = pl1Line; location.SheetPilePoint.Assign(surfaceLine.Geometry.Points[cSheetPilingPointIndex]); location.SheetPileLength = 12.0; dike.Locations.Add(location); // Location 3: a location which has the same surfaceline and pl1-line as Location 2 location = new Location(); location.Name = "Loc3"; location.SurfaceLine2 = surfaceLine; location.PL1Line = pl1Line; dike.Locations.Add(location); return dike; } /// /// Test creation of objects with local coordinates /// [Test] public void CanCreateLocalXZObjects() { var dikeCoordinateSystemConverter = new DikeCoordinateSystemConverter(); using (Dike dike = CreateDike()) { dikeCoordinateSystemConverter.CreateLocalXZObjects(dike); foreach (Location location in dike.Locations) { // Check surfacelines CheckResultingLocalSurfaceLine(location.LocalXZSurfaceLine2); // Check PL1-Lines CheckResultingLocalPL1Line(location.LocalXZPL1Line); // Check sheetpiling if (location.SheetPileLength > 0) { Assert.IsTrue(location.LocalXZSurfaceLine2.Geometry.Points[cSheetPilingPointIndex].LocationEquals(location.LocalXZSheetPilePoint)); } } } } } }