// Copyright (C) Stichting Deltares 2019. 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 System.Linq; using Deltares.DamEngine.Data.Geometry; using Deltares.DamEngine.Data.Geotechnics; using NUnit.Framework; namespace Deltares.DamEngine.Data.Tests.Geotechnics { [TestFixture] public class SurfaceLine2Tests { [Test] public void TestAddingCharacteristicPointsOnSameLocationDoesNotAddDoublePointsInGeometry() { SurfaceLine2 surfaceLine = new SurfaceLine2(); surfaceLine.CharacteristicPoints.Geometry = surfaceLine.Geometry; AddPointToSurfaceLine(surfaceLine, 0.0, 0.0, CharacteristicPointType.SurfaceLevelOutside); AddPointToSurfaceLine(surfaceLine, 2.0, 0.5, CharacteristicPointType.None); AddPointToSurfaceLine(surfaceLine, 4.0, 0.0, CharacteristicPointType.DikeToeAtRiver); AddPointToSurfaceLine(surfaceLine, 9.0, 5.0, CharacteristicPointType.DikeTopAtRiver); AddPointToSurfaceLine(surfaceLine, 10.0, 5.2, CharacteristicPointType.None); AddPointToSurfaceLine(surfaceLine, 13.0, 5.4, CharacteristicPointType.DikeTopAtPolder); AddPointToSurfaceLine(surfaceLine, 13.0, 5.4, CharacteristicPointType.TrafficLoadOutside); AddPointToSurfaceLine(surfaceLine, 14.0, 4.52, CharacteristicPointType.TrafficLoadInside); AddPointToSurfaceLine(surfaceLine, 18.0, 1.0, CharacteristicPointType.DikeToeAtPolder); AddPointToSurfaceLine(surfaceLine, 24.0, 1.0, CharacteristicPointType.SurfaceLevelInside); surfaceLine.Geometry.SyncCalcPoints(); Assert.AreEqual(10, surfaceLine.CharacteristicPoints.Count); double tolerance = 0.001; Assert.AreEqual(2, surfaceLine.CharacteristicPoints.Count(cp => Math.Abs(cp.X - 13.0) < tolerance && Math.Abs(cp.Z - 5.4) < tolerance)); // Because TrafficLoadOutside and DikeTopAtPolder are on the same location, 1 point less should be in the geometry Assert.AreEqual(9, surfaceLine.Geometry.Points.Count); Assert.AreEqual(1, surfaceLine.Geometry.Points.Count(cp => Math.Abs(cp.X - 13.0) < tolerance && Math.Abs(cp.Z - 5.4) < tolerance)); } private void AddPointToSurfaceLine(SurfaceLine2 surfaceLine, double xCoordinate, double zCoordinate, CharacteristicPointType characteristicPointType) { var geometryPoint = new GeometryPoint() { X = xCoordinate, Y = 0.0, Z = zCoordinate, }; surfaceLine.AddCharacteristicPoint(geometryPoint, characteristicPointType); } } }