// Copyright (C) Stichting Deltares 2020. All rights reserved. // // This file is part of the Layer On Slope Tool. // // The Layer On Slope Tool 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 Deltares.LayerOnSlopeTool.Data; using NUnit.Framework; namespace Deltares.LayerOnSlopeTool.LayerCreator.Tests { [TestFixture] public class SurfaceLineProcessorTests { private const double Tolerance = 0.001; [Test] public void TestDetermineLoweredSurfaceLineForGivenLayerThickness() { var originalSurfaceLine = CreateSimpleStraightSurfaceLine(); var surfacelineProcessor = new SurfaceLineProcessor(originalSurfaceLine); var loweredSurfaceLine = surfacelineProcessor.CreateLoweredSurfaceLine(1); Assert.AreEqual(11, loweredSurfaceLine.SurfaceLinePoints.Count); Assert.AreEqual(0, loweredSurfaceLine.SurfaceLinePoints[0].XCoordinate, Tolerance); Assert.AreEqual(0, loweredSurfaceLine.SurfaceLinePoints[0].ZCoordinate, Tolerance); Assert.AreEqual(5, loweredSurfaceLine.SurfaceLinePoints[1].XCoordinate, Tolerance); Assert.AreEqual(0, loweredSurfaceLine.SurfaceLinePoints[1].ZCoordinate, Tolerance); Assert.AreEqual(10, loweredSurfaceLine.SurfaceLinePoints[2].XCoordinate, Tolerance); Assert.AreEqual(0, loweredSurfaceLine.SurfaceLinePoints[2].ZCoordinate, Tolerance); Assert.AreEqual(12, loweredSurfaceLine.SurfaceLinePoints[3].XCoordinate, Tolerance); Assert.AreEqual(0, loweredSurfaceLine.SurfaceLinePoints[3].ZCoordinate, Tolerance); Assert.AreEqual(14, loweredSurfaceLine.SurfaceLinePoints[4].XCoordinate, Tolerance); Assert.AreEqual(0, loweredSurfaceLine.SurfaceLinePoints[4].ZCoordinate, Tolerance); Assert.AreEqual(14.01, loweredSurfaceLine.SurfaceLinePoints[5].XCoordinate, Tolerance); Assert.AreEqual(-1, loweredSurfaceLine.SurfaceLinePoints[5].ZCoordinate, Tolerance); Assert.AreEqual(15, loweredSurfaceLine.SurfaceLinePoints[6].XCoordinate, Tolerance); Assert.AreEqual(-1, loweredSurfaceLine.SurfaceLinePoints[6].ZCoordinate, Tolerance); Assert.AreEqual(15.99, loweredSurfaceLine.SurfaceLinePoints[7].XCoordinate, Tolerance); Assert.AreEqual(-1, loweredSurfaceLine.SurfaceLinePoints[7].ZCoordinate, Tolerance); Assert.AreEqual(16, loweredSurfaceLine.SurfaceLinePoints[8].XCoordinate, Tolerance); Assert.AreEqual(0, loweredSurfaceLine.SurfaceLinePoints[8].ZCoordinate, Tolerance); Assert.AreEqual(22, loweredSurfaceLine.SurfaceLinePoints[9].XCoordinate, Tolerance); Assert.AreEqual(0, loweredSurfaceLine.SurfaceLinePoints[9].ZCoordinate, Tolerance); Assert.AreEqual(30, loweredSurfaceLine.SurfaceLinePoints[10].XCoordinate, Tolerance); Assert.AreEqual(0, loweredSurfaceLine.SurfaceLinePoints[10].ZCoordinate, Tolerance); } [Test] public void TestDetermineLoweredSurfaceLineForGivenLayerThicknessWithAckwardPoints() { var originalSurfaceLine = CreateSimpleStraightSurfaceLineWithAckwardPoints(); var surfacelineProcessor = new SurfaceLineProcessor(originalSurfaceLine); var loweredSurfaceLine = surfacelineProcessor.CreateLoweredSurfaceLine(1); Assert.AreEqual(11, loweredSurfaceLine.SurfaceLinePoints.Count); Assert.AreEqual(0, loweredSurfaceLine.SurfaceLinePoints[0].XCoordinate, Tolerance); Assert.AreEqual(0, loweredSurfaceLine.SurfaceLinePoints[0].ZCoordinate, Tolerance); Assert.AreEqual(5, loweredSurfaceLine.SurfaceLinePoints[1].XCoordinate, Tolerance); Assert.AreEqual(0, loweredSurfaceLine.SurfaceLinePoints[1].ZCoordinate, Tolerance); Assert.AreEqual(10, loweredSurfaceLine.SurfaceLinePoints[2].XCoordinate, Tolerance); Assert.AreEqual(0, loweredSurfaceLine.SurfaceLinePoints[2].ZCoordinate, Tolerance); Assert.AreEqual(12, loweredSurfaceLine.SurfaceLinePoints[3].XCoordinate, Tolerance); Assert.AreEqual(0, loweredSurfaceLine.SurfaceLinePoints[3].ZCoordinate, Tolerance); Assert.AreEqual(14, loweredSurfaceLine.SurfaceLinePoints[4].XCoordinate, Tolerance); Assert.AreEqual(0, loweredSurfaceLine.SurfaceLinePoints[4].ZCoordinate, Tolerance); Assert.AreEqual(14.01, loweredSurfaceLine.SurfaceLinePoints[5].XCoordinate, Tolerance); Assert.AreEqual(-1, loweredSurfaceLine.SurfaceLinePoints[5].ZCoordinate, Tolerance); Assert.AreEqual(15.5, loweredSurfaceLine.SurfaceLinePoints[6].XCoordinate, Tolerance); Assert.AreEqual(-1, loweredSurfaceLine.SurfaceLinePoints[6].ZCoordinate, Tolerance); Assert.AreEqual(15.99, loweredSurfaceLine.SurfaceLinePoints[7].XCoordinate, Tolerance); Assert.AreEqual(-1, loweredSurfaceLine.SurfaceLinePoints[7].ZCoordinate, Tolerance); Assert.AreEqual(16, loweredSurfaceLine.SurfaceLinePoints[8].XCoordinate, Tolerance); Assert.AreEqual(0, loweredSurfaceLine.SurfaceLinePoints[8].ZCoordinate, Tolerance); Assert.AreEqual(22, loweredSurfaceLine.SurfaceLinePoints[9].XCoordinate, Tolerance); Assert.AreEqual(0, loweredSurfaceLine.SurfaceLinePoints[9].ZCoordinate, Tolerance); Assert.AreEqual(30, loweredSurfaceLine.SurfaceLinePoints[10].XCoordinate, Tolerance); Assert.AreEqual(0, loweredSurfaceLine.SurfaceLinePoints[10].ZCoordinate, Tolerance); } private SurfaceLine CreateSimpleStraightSurfaceLine() { var surfaceLine = new SurfaceLine(); surfaceLine.SurfaceLineId = "SimpleStraightSurfaceLine"; var point = new SurfaceLinePoint { XCoordinate = 0, ZCoordinate = 0, PointType = CharacteristicPointType.SurfaceLevelOutside }; surfaceLine.SurfaceLinePoints.Add(point); var pointA = new SurfaceLinePoint { XCoordinate = 5, ZCoordinate = 0, PointType = CharacteristicPointType.None }; surfaceLine.SurfaceLinePoints.Add(pointA); var point1 = new SurfaceLinePoint { XCoordinate = 10, ZCoordinate = 0, PointType = CharacteristicPointType.DikeToeAtRiver }; surfaceLine.SurfaceLinePoints.Add(point1); var point2 = new SurfaceLinePoint { XCoordinate = 12, ZCoordinate = 0, PointType = CharacteristicPointType.DikeTopAtRiver }; surfaceLine.SurfaceLinePoints.Add(point2); var point3 = new SurfaceLinePoint { XCoordinate = 14, ZCoordinate = 0, PointType = CharacteristicPointType.DikeTopAtPolder }; surfaceLine.SurfaceLinePoints.Add(point3); var point3A = new SurfaceLinePoint { XCoordinate = 15, ZCoordinate = 0, PointType = CharacteristicPointType.None }; surfaceLine.SurfaceLinePoints.Add(point3A); var point4 = new SurfaceLinePoint { XCoordinate = 16, ZCoordinate = 0, PointType = CharacteristicPointType.DikeToeAtPolder }; surfaceLine.SurfaceLinePoints.Add(point4); var point4A = new SurfaceLinePoint { XCoordinate = 22, ZCoordinate = 0, PointType = CharacteristicPointType.None }; surfaceLine.SurfaceLinePoints.Add(point4A); var point5 = new SurfaceLinePoint { XCoordinate = 30, ZCoordinate = 0, PointType = CharacteristicPointType.SurfaceLevelInside }; surfaceLine.SurfaceLinePoints.Add(point5); return surfaceLine; } private SurfaceLine CreateSimpleStraightSurfaceLineWithAckwardPoints() { var surfaceLine = new SurfaceLine(); surfaceLine.SurfaceLineId = "SimpleStraightSurfaceLine"; var point = new SurfaceLinePoint { XCoordinate = 0, ZCoordinate = 0, PointType = CharacteristicPointType.SurfaceLevelOutside }; surfaceLine.SurfaceLinePoints.Add(point); var pointA = new SurfaceLinePoint { XCoordinate = 5, ZCoordinate = 0, PointType = CharacteristicPointType.None }; surfaceLine.SurfaceLinePoints.Add(pointA); var point1 = new SurfaceLinePoint { XCoordinate = 10, ZCoordinate = 0, PointType = CharacteristicPointType.DikeToeAtRiver }; surfaceLine.SurfaceLinePoints.Add(point1); var point2 = new SurfaceLinePoint { XCoordinate = 12, ZCoordinate = 0, PointType = CharacteristicPointType.DikeTopAtRiver }; surfaceLine.SurfaceLinePoints.Add(point2); var point3 = new SurfaceLinePoint { XCoordinate = 14, ZCoordinate = 0, PointType = CharacteristicPointType.DikeTopAtPolder }; surfaceLine.SurfaceLinePoints.Add(point3); var point3A = new SurfaceLinePoint { // is less than 0.01 meter beyond the point that is to be lowered with offset of 0.01 m. So this point should NOT be found in the lowered line XCoordinate = 14.001, ZCoordinate = 0, PointType = CharacteristicPointType.None }; surfaceLine.SurfaceLinePoints.Add(point3A); var point3B = new SurfaceLinePoint { // make this 15.5 instead of 15 to be different from ordinary SimpleStraightSurfaceLine. XCoordinate = 15.5, ZCoordinate = 0, PointType = CharacteristicPointType.None }; surfaceLine.SurfaceLinePoints.Add(point3B); var point3C = new SurfaceLinePoint { // is less than 0.01 meter in front off the point that is to be lowered with offset of -0.01 m. So this point should NOT be found in the lowered line XCoordinate = 15.999, ZCoordinate = 0, PointType = CharacteristicPointType.None }; surfaceLine.SurfaceLinePoints.Add(point3C); var point4 = new SurfaceLinePoint { XCoordinate = 16, ZCoordinate = 0, PointType = CharacteristicPointType.DikeToeAtPolder }; surfaceLine.SurfaceLinePoints.Add(point4); var point4A = new SurfaceLinePoint { XCoordinate = 22, ZCoordinate = 0, PointType = CharacteristicPointType.None }; surfaceLine.SurfaceLinePoints.Add(point4A); var point5 = new SurfaceLinePoint { XCoordinate = 30, ZCoordinate = 0, PointType = CharacteristicPointType.SurfaceLevelInside }; surfaceLine.SurfaceLinePoints.Add(point5); return surfaceLine; } } }