// 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 surface lines
CheckResultingLocalSurfaceLine(location.LocalXZSurfaceLine2);
}
}
}
///
/// Create result surface line
///
///
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 surface line
///
/// a surface line 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 surface line
///
/// a surface line 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;
}
///
/// Checks converted local surface line with reference surface line
///
///
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));
}
}
}
///
/// 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 surface line and pl1-line as Location 2
location = new Location();
location.Name = "Loc3";
location.SurfaceLine2 = surfaceLine;
dike.Locations.Add(location);
return dike;
}
}
}