// Copyright (C) Stichting Deltares 2025. All rights reserved.
//
// This file is part of the application DAM - UI.
//
// DAM - UI is free software: you can redistribute it and/or modify
// it under the terms of the GNU 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
//
// All names, logos, and references to "Deltares" are registered trademarks of
// Stichting Deltares and remain full property of Stichting Deltares at all times.
// All rights reserved.
using System;
using Deltares.Dam.Data;
using Deltares.Geometry;
using Deltares.Geotechnics.GeotechnicalGeometry;
using Deltares.Geotechnics.SurfaceLines;
using NUnit.Framework;
namespace Deltares.Dam.Tests
{
[TestFixture]
public class DikeCoordinateSystemConverterTest
{
///
/// Test
///
[Test]
public void ThrowsExceptionIfDikeNotComplete()
{
var dikeCoordinateSystemConverter = new DikeCoordinateSystemConverter();
using (var dike = new Dike())
{
Assert.That(() => dikeCoordinateSystemConverter.CreateLocalXZObjects(dike), Throws.InstanceOf());
}
}
///
/// 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);
}
}
}
///
/// 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;
}
///
/// Checks converted local surfaceline with reference surfaceline
///
///
private void CheckResultingLocalSurfaceLine(SurfaceLine2 localSurfaceLine)
{
using (SurfaceLine2 expectedLocalSurfaceLine = CreateResultingLocalSurfaceLine())
{
Assert.That(localSurfaceLine.Geometry.Points.Count, Is.EqualTo(expectedLocalSurfaceLine.Geometry.Count), String.Format("Surfaceline line {0}", localSurfaceLine.Name));
for (var pointIndex = 0; pointIndex < localSurfaceLine.Geometry.Points.Count; pointIndex++)
{
Assert.That(localSurfaceLine.Geometry.Points[pointIndex].LocationEquals(expectedLocalSurfaceLine.Geometry.Points[pointIndex]),
Is.True, 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.That(localPL1Line.Points.Count, Is.EqualTo(expectedLocalPL1Line.Points.Count), String.Format("PL1 line {0}", localPL1Line.Name));
for (var pointIndex = 0; pointIndex < localPL1Line.Points.Count; pointIndex++)
{
Assert.That(localPL1Line.Points[pointIndex].LocationEquals(expectedLocalPL1Line.Points[pointIndex]),
Is.True, 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
var location = new Location();
location.Name = "Loc1";
location.SurfaceLine2 = surfaceLine;
dike.Locations.Add(location);
// Location 2 surface line
surfaceLine = CreateGlobalSurfaceLineSteepWithAlphaBetween0and90Degrees();
surfaceLine.Name = "SL2";
dike.SurfaceLines2.Add(surfaceLine);
// Location 2 (with sheetpiling)
location = new Location();
location.Name = "Loc2";
location.SurfaceLine2 = surfaceLine;
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;
dike.Locations.Add(location);
return dike;
}
}
}