Index: DamEngine/trunk/src/Deltares.DamEngine.Data/Geotechnics/SurfaceLine2Extensions.cs =================================================================== diff -u -r877 -r951 --- DamEngine/trunk/src/Deltares.DamEngine.Data/Geotechnics/SurfaceLine2Extensions.cs (.../SurfaceLine2Extensions.cs) (revision 877) +++ DamEngine/trunk/src/Deltares.DamEngine.Data/Geotechnics/SurfaceLine2Extensions.cs (.../SurfaceLine2Extensions.cs) (revision 951) @@ -163,20 +163,18 @@ bool movedPointToMatch = false; bool addPoint = false; - Point2D point = null; - var newPoint = new Point2D() + GeometryPoint point = null; + var newPoint = new GeometryPoint() { X = x, Z = z }; - GeometryPoint gp = null; if (type.HasValue) { // Get point of this type.. - gp = line.CharacteristicPoints.GetGeometryPoint(type.Value); - if (gp != null) + point = line.CharacteristicPoints.GetGeometryPoint(type.Value); + if (point != null) { - point = new Point2D(gp.X, gp.Z); // Characteristic point annotation set, check location... if (point.LocationEquals(newPoint)) { @@ -186,11 +184,11 @@ else { bool isAssignedToOtherCharacteristicPoints = - line.GetCharacteristicPoints(gp).Count(cpt => cpt != CharacteristicPointType.None) > 1; + line.GetCharacteristicPoints(point).Count(cpt => cpt != CharacteristicPointType.None) > 1; if (isAssignedToOtherCharacteristicPoints) { // Other characteristic points exist with the same coordinates so add as new point - point = line.Geometry.GetPointAt(newPoint.X, newPoint.Z); // Get point at specified coords + point = line.Geometry.GetGeometryPointAt(newPoint.X, newPoint.Z); // Get point at specified coords if (point == null) { point = newPoint; @@ -204,18 +202,16 @@ point.Z = z; movedPointToMatch = true; } - gp.X = point.X; - gp.Z = point.Z; } } } if (point == null) { - point = line.Geometry.GetPointAt(x, z); // Get point at specified coords + point = line.Geometry.GetGeometryPointAt(x, z); // Get point at specified coords } if (point == null) { - point = new Point2D() + point = new GeometryPoint() { X = x, Z = z @@ -224,23 +220,22 @@ } if (addPoint) { - var newgp = new GeometryPoint(point.X, point.Z); - line.Geometry.Points.Add(newgp); - line.AddCharacteristicPoint(newgp, type ?? CharacteristicPointType.None); + line.Geometry.Points.Add(point); + line.AddCharacteristicPoint(point, type ?? CharacteristicPointType.None); } else if (type.HasValue && !movedPointToMatch) { - if (line.CharacteristicPoints.Any(cp => ReferenceEquals(cp.GeometryPoint, gp) && + if (line.CharacteristicPoints.Any(cp => ReferenceEquals(cp.GeometryPoint, point) && cp.CharacteristicPointType != CharacteristicPointType.None)) { - line.AddCharacteristicPoint(gp, type.Value); + line.AddCharacteristicPoint(point, type.Value); } else { int index = -1; for (int i = 0; i < line.CharacteristicPoints.Count; i++) { - if (ReferenceEquals(line.CharacteristicPoints[i].GeometryPoint, gp)) + if (ReferenceEquals(line.CharacteristicPoints[i].GeometryPoint, point)) { index = i; break; Index: DamEngine/trunk/src/Deltares.DamEngine.Calculators.Tests/DikesDesign/SurfaceLineAdapterTest.cs =================================================================== diff -u --- DamEngine/trunk/src/Deltares.DamEngine.Calculators.Tests/DikesDesign/SurfaceLineAdapterTest.cs (revision 0) +++ DamEngine/trunk/src/Deltares.DamEngine.Calculators.Tests/DikesDesign/SurfaceLineAdapterTest.cs (revision 951) @@ -0,0 +1,142 @@ +// Copyright (C) Stichting Deltares 2018. 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.Calculators.Dikes_Design; +using Deltares.DamEngine.Data.General; +using Deltares.DamEngine.Data.Geometry; +using Deltares.DamEngine.Data.Geotechnics; +using NUnit.Framework; + +namespace Deltares.DamEngine.Calculators.Tests.DikesDesign +{ + [TestFixture] + public class SurfaceLineAdapterTest + { + private readonly Location location = new Location(); + + [TestFixtureTearDown] + public void TestFixtureTearDown() + { + } + + [Test] + [ExpectedException(typeof(ArgumentNullException))] + public void ThrowsAnExceptionWhenSurfaceLineIsNull() + { + new StubSurfaceLineAdapter(null, location); + } + + [Test] + [ExpectedException(typeof(SurfaceLineAdapterException))] + public void ThrowsAnExceptionWhenSurfaceLineHasNoDike() + { + var surfaceLine = new SurfaceLine2 + { + CharacteristicPoints = + { + GeometryMustContainPoint = true + }, + Geometry = new GeometryPointString() + }; + surfaceLine.EnsurePoint(0, 0); + surfaceLine.EnsurePoint(1, 0); + surfaceLine.EnsurePoint(2, 0); + surfaceLine.EnsurePoint(3, 0); + new StubSurfaceLineAdapter(surfaceLine, location); + } + + [Test] + [ExpectedException(typeof(SurfaceLineAdapterException))] + public void ThrowsAnExceptionWhenSurfaceLineDoesNotComplyToSpecificationUsingZeroCoordValues() + { + var surfaceLine1 = new SurfaceLine2 + { + CharacteristicPoints = + { + GeometryMustContainPoint = true + }, + Geometry = new GeometryPointString() + }; + surfaceLine1.EnsurePointOfType(0, 0, CharacteristicPointType.DikeToeAtRiver); + surfaceLine1.EnsurePointOfType(0, 0, CharacteristicPointType.DikeTopAtRiver); + surfaceLine1.EnsurePointOfType(0, 0, CharacteristicPointType.DikeTopAtPolder); + surfaceLine1.EnsurePointOfType(0, 0, CharacteristicPointType.DikeToeAtPolder); + new StubSurfaceLineAdapter(surfaceLine1, location); + } + + [Test] + [ExpectedException(typeof(SurfaceLineAdapterException))] + public void ThrowsAnExceptionWhenSurfaceLineDoesNotComplyToSpecificationUsingAskewDikeTop() + { + var surfaceLine1 = new SurfaceLine2 + { + CharacteristicPoints = + { + GeometryMustContainPoint = true + }, + Geometry = new GeometryPointString() + }; + var p1 = new GeometryPoint(); + var p2 = new GeometryPoint() { X = 10, Z = 10 }; + var p3 = new GeometryPoint() { X = 15, Z = 15 }; + surfaceLine1.EnsurePointOfType(p1.X, p1.Z, CharacteristicPointType.DikeToeAtRiver); + surfaceLine1.EnsurePointOfType(p2.X, p2.Z, CharacteristicPointType.DikeTopAtRiver); + surfaceLine1.EnsurePointOfType(p3.X, p3.Z, CharacteristicPointType.DikeTopAtPolder); + surfaceLine1.EnsurePointOfType(p1.X, p1.Z, CharacteristicPointType.DikeToeAtPolder); + new StubSurfaceLineAdapter(surfaceLine1, location); + } + + [Test] + [ExpectedException(typeof(SurfaceLineAdapterException))] + public void ThrowsAnExceptionWhenSurfaceLineDoesNotComplyToSpecificationUsingAskewTopShoulderInside() + { + var surfaceLine1 = new SurfaceLine2 + { + CharacteristicPoints = + { + GeometryMustContainPoint = true + }, + Geometry = new GeometryPointString() + }; + var p1 = new GeometryPoint(); + var p2 = new GeometryPoint() { X = 10, Z = 10 }; + var p3 = new GeometryPoint() { X = 15, Z = 10 }; + var p4 = new GeometryPoint() { X = 17, Z = 8 }; + var p5 = new GeometryPoint() { X = 18, Z = 9 }; + surfaceLine1.EnsurePointOfType(p1.X, p1.Z, CharacteristicPointType.DikeToeAtRiver); + surfaceLine1.EnsurePointOfType(p2.X, p2.Z, CharacteristicPointType.DikeTopAtRiver); + surfaceLine1.EnsurePointOfType(p3.X, p3.Z, CharacteristicPointType.DikeTopAtPolder); + surfaceLine1.EnsurePointOfType(p4.X, p4.Z, CharacteristicPointType.ShoulderBaseInside); + surfaceLine1.EnsurePointOfType(p5.X, p5.Z, CharacteristicPointType.ShoulderTopInside); + surfaceLine1.EnsurePointOfType(p1.X, p1.Z, CharacteristicPointType.DikeToeAtPolder); + new StubSurfaceLineAdapter(surfaceLine1, location); + } + + class StubSurfaceLineAdapter : SurfaceLineAdapter + { + public StubSurfaceLineAdapter(SurfaceLine2 surfaceLine, Location location) + : base(surfaceLine, location) + { + } + } + } +} Index: DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryPointString.cs =================================================================== diff -u -r877 -r951 --- DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryPointString.cs (.../GeometryPointString.cs) (revision 877) +++ DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryPointString.cs (.../GeometryPointString.cs) (revision 951) @@ -436,7 +436,7 @@ } /// - /// Gets the point at. + /// Gets the Point2D at the specified coordinates. /// /// The x. /// The z. @@ -448,6 +448,19 @@ point.Z.AlmostEquals(z, GeometryPoint.Precision)); } + /// + /// Gets the GeometryPoint at the specified coordinates. + /// + /// The x. + /// The z. + /// + public GeometryPoint GetGeometryPointAt(double x, double z) + { + return Points.FirstOrDefault( + point => point.X.AlmostEquals(x, GeometryPoint.Precision) && + point.Z.AlmostEquals(z, GeometryPoint.Precision)); + } + //#Bka: this should never be 1 method! Split it into 2 methods // It is used for sliplanes only and therefor uses Points instead of calcPoints /// Index: DamEngine/trunk/src/Deltares.DamEngine.Calculators.Tests/Deltares.DamEngine.Calculators.Tests.csproj =================================================================== diff -u -r946 -r951 --- DamEngine/trunk/src/Deltares.DamEngine.Calculators.Tests/Deltares.DamEngine.Calculators.Tests.csproj (.../Deltares.DamEngine.Calculators.Tests.csproj) (revision 946) +++ DamEngine/trunk/src/Deltares.DamEngine.Calculators.Tests/Deltares.DamEngine.Calculators.Tests.csproj (.../Deltares.DamEngine.Calculators.Tests.csproj) (revision 951) @@ -45,6 +45,7 @@ + @@ -101,9 +102,7 @@ PreserveNewest - - - +