// Copyright (C) Stichting Deltares 2024. All rights reserved.
//
// This file is part of the Dam Engine.
//
// The Dam Engine is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero 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 Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero 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.DamEngine.Data.Geometry;
using Deltares.DamEngine.Data.Geotechnics;
using Deltares.DamEngine.TestHelpers.Factories;
using NUnit.Framework;
namespace Deltares.DamEngine.Data.Tests.Geotechnics;
[TestFixture]
public class GeometryHelperTests
{
const double cTolerance = 1e-6;
[Test]
public void GivenTwoLayerGeometryWhenExtendingLeftThenLeftBoundaryIsChanged()
{
// Given
SoilProfile2D soilProfile2D = FactoryForSoilProfiles.CreateSoilProfile2DWithThreeLayers();
// When
GeometryHelper.ExtendGeometryLeft(soilProfile2D.Geometry, -2);
// Then
GeometryBounds geometryBounds = soilProfile2D.Geometry.GetGeometryBounds();
Assert.Multiple(() =>
{
Assert.That(geometryBounds.Left, Is.EqualTo(-2).Within(cTolerance));
Assert.That(soilProfile2D.Geometry.Left, Is.EqualTo(-2).Within(cTolerance));
// At first there are 3 surfaces, but after extending the right boundary, there are 6 surfaces
Assert.That(soilProfile2D.Geometry.Surfaces, Has.Count.EqualTo(6));
// the number of points should now be 12 + 4 = 16
Assert.That(soilProfile2D.Geometry.Points, Has.Count.EqualTo(16));
// the number of curves should now be 14 + 7 = 21
Assert.That(soilProfile2D.Geometry.Curves, Has.Count.EqualTo(21));
});
}
[Test]
public void GivenTwoLayerGeometryWhenExtendingLeftToTheRightThenExceptionIsThrown()
{
// Given
SoilProfile2D soilProfile2D = FactoryForSoilProfiles.CreateSoilProfile2DWithThreeLayers();
// When & Then
Assert.Throws(() => { GeometryHelper.ExtendGeometryLeft(soilProfile2D.Geometry, 2); });
}
[Test]
public void GivenTwoLayerGeometryWhenExtendingRightThenRightBoundaryIsChanged()
{
// Given
SoilProfile2D soilProfile2D = FactoryForSoilProfiles.CreateSoilProfile2DWithThreeLayers();
// When
GeometryHelper.ExtendGeometryRight(soilProfile2D.Geometry, 12);
// Then
Assert.Multiple(() =>
{
Assert.That(soilProfile2D.Geometry.Right, Is.EqualTo(12).Within(cTolerance));
// At first there are 3 surfaces, but after extending the right boundary, there are 6 surfaces
Assert.That(soilProfile2D.Geometry.Surfaces, Has.Count.EqualTo(6));
// the number of points should now be 12 + 4 = 16
Assert.That(soilProfile2D.Geometry.Points, Has.Count.EqualTo(16));
// the number of curves should now be 14 + 7 = 21
Assert.That(soilProfile2D.Geometry.Curves, Has.Count.EqualTo(21));
});
}
[Test]
public void GivenTwoLayerGeometryWhenExtendingRightToTheLeftThenExceptionIsThrown()
{
// Given
SoilProfile2D soilProfile2D = FactoryForSoilProfiles.CreateSoilProfile2DWithThreeLayers();
// When & Then
Assert.Throws(() => { GeometryHelper.ExtendGeometryRight(soilProfile2D.Geometry, 8); });
}
[Test]
public void GivenTwoLayerGeometryWhenCuttingLeftThenLeftBoundaryIsChanged()
{
// Given
SoilProfile2D soilProfile2D = FactoryForSoilProfiles.CreateSoilProfile2DWithThreeLayers();
// When
GeometryHelper.CutGeometryLeft(soilProfile2D.Geometry, 2);
// Then
GeometryBounds geometryBounds = soilProfile2D.Geometry.GetGeometryBounds();
Assert.Multiple(() =>
{
Assert.That(geometryBounds.Left, Is.EqualTo(2).Within(cTolerance));
Assert.That(soilProfile2D.Geometry.Left, Is.EqualTo(2).Within(cTolerance));
// At first there are 3 surfaces, after cutting the boundary, there still must be 3 surfaces
Assert.That(soilProfile2D.Geometry.Surfaces, Has.Count.EqualTo(3));
// At first there are 12 points, after cutting the boundary, there still must be 12 points
Assert.That(soilProfile2D.Geometry.Points, Has.Count.EqualTo(12));
// At first there are 14 curves, after cutting the boundary, there still must be 14 curves
Assert.That(soilProfile2D.Geometry.Curves, Has.Count.EqualTo(14));
});
}
[Test]
public void GivenTwoLayerGeometryWhenCuttingRightThenRightBoundaryIsChanged()
{
// Given
SoilProfile2D soilProfile2D = FactoryForSoilProfiles.CreateSoilProfile2DWithThreeLayers();
// When
GeometryHelper.CutGeometryRight(soilProfile2D.Geometry, 8);
// Then
GeometryBounds geometryBounds = soilProfile2D.Geometry.GetGeometryBounds();
Assert.Multiple(() =>
{
Assert.That(geometryBounds.Right, Is.EqualTo(8).Within(cTolerance));
Assert.That(soilProfile2D.Geometry.Right, Is.EqualTo(8).Within(cTolerance));
// At first there are 3 surfaces, after cutting the boundary, there still must be 3 surfaces
Assert.That(soilProfile2D.Geometry.Surfaces, Has.Count.EqualTo(3));
// At first there are 12 points, after cutting the boundary, there still must be 12 points
Assert.That(soilProfile2D.Geometry.Points, Has.Count.EqualTo(12));
// At first there are 14 curves, after cutting the boundary, there still must be 14 curves
Assert.That(soilProfile2D.Geometry.Curves, Has.Count.EqualTo(14));
});
}
}