// 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.Linq; using Deltares.DamEngine.Data.Geometry; using Deltares.DamEngine.Data.Geotechnics; using Deltares.DamEngine.TestHelpers.Factories; using Deltares.DamEngine.TestHelpers.Geometry; using NUnit.Framework; namespace Deltares.DamEngine.Data.Tests.Geotechnics; [TestFixture] public class SoilProfile2DSurfaceLineHelperTests { // For debugging purposes private const string visualizationFolder = @"D:\src\dam\DamTools\GeometryVisualizer\"; [Test] [TestCase(PositionToSoilProfile2D.LeftOfSoilProfile, false)] [TestCase(PositionToSoilProfile2D.RightOfSoilProfile, false)] [TestCase(PositionToSoilProfile2D.OnSoilProfile, true)] [TestCase(PositionToSoilProfile2D.InsideOfSoilProfile, true)] public void GivenSurfaceLineAndSoilProfile2D_WhenCheckIsSurfaceLineInsideSoilProfile2D_ThenReturnCorrectResult(PositionToSoilProfile2D positionToSoilProfile2D, bool result) { // Given SoilProfile2D soilProfile2D = FactoryForSoilProfiles.CreateSoilProfile2DWithTwoLayers(); // For debugging purposes // GeometryExporter.ExportToFile(soilProfile2D.Geometry, visualizationFolder + "Geometry.txt"); // GeometryExporter.ExportToJsonFile(soilProfile2D.Geometry, visualizationFolder + "Geometry.json"); SurfaceLine2 surfaceLine = CreateSurfaceLineForSoilProfile2D(soilProfile2D, positionToSoilProfile2D); // When-Then Assert.That(SoilProfile2DSurfaceLineHelper.IsSurfaceLineInsideSoilProfile2D(surfaceLine, soilProfile2D), Is.EqualTo(result)); } public enum PositionToSoilProfile2D { LeftOfSoilProfile, RightOfSoilProfile, OnSoilProfile, InsideOfSoilProfile } private static SurfaceLine2 CreateSurfaceLineForSoilProfile2D(SoilProfile2D soilProfile2D, PositionToSoilProfile2D positionToSoilProfile2D) { GeometryPoint geometryPoint = soilProfile2D.Geometry.SurfaceLine.Points.First(); var leftPoint = new GeometryPoint(geometryPoint.X, geometryPoint.Z); geometryPoint = soilProfile2D.Geometry.SurfaceLine.Points.Last(); var rightPoint = new GeometryPoint(geometryPoint.X, geometryPoint.Z); var middlePoint = new GeometryPoint((leftPoint.X + rightPoint.X) / 2, (leftPoint.Z + rightPoint.Z) / 2); switch (positionToSoilProfile2D) { case PositionToSoilProfile2D.LeftOfSoilProfile: leftPoint.X -= 1; break; case PositionToSoilProfile2D.RightOfSoilProfile: rightPoint.X += 1; break; case PositionToSoilProfile2D.OnSoilProfile: break; case PositionToSoilProfile2D.InsideOfSoilProfile: leftPoint.X += 1; rightPoint.X -= 1; break; } SurfaceLine2 surfaceLine = FactoryForSoilProfiles.CreateSurfaceLine(new[] { leftPoint, middlePoint, rightPoint }); surfaceLine.CharacteristicPoints.Add(new CharacteristicPoint(surfaceLine.CharacteristicPoints, leftPoint)); surfaceLine.CharacteristicPoints.Annotate(0, CharacteristicPointType.SurfaceLevelOutside); surfaceLine.CharacteristicPoints.Add(new CharacteristicPoint(surfaceLine.CharacteristicPoints, rightPoint)); surfaceLine.CharacteristicPoints.Annotate(1, CharacteristicPointType.SurfaceLevelInside); return surfaceLine; } }