Index: Core/Common/src/Core.Common.Base/Core.Common.Base.csproj
===================================================================
diff -u -rb8fa5d6867c945f3f1744fd1455b89cadb357959 -rb8976a5e3cf525e419227e409e44ac69a430711a
--- Core/Common/src/Core.Common.Base/Core.Common.Base.csproj (.../Core.Common.Base.csproj) (revision b8fa5d6867c945f3f1744fd1455b89cadb357959)
+++ Core/Common/src/Core.Common.Base/Core.Common.Base.csproj (.../Core.Common.Base.csproj) (revision b8976a5e3cf525e419227e409e44ac69a430711a)
@@ -96,6 +96,7 @@
+
Index: Core/Common/src/Core.Common.Base/Geometry/Point2DCollectionExtensions.cs
===================================================================
diff -u
--- Core/Common/src/Core.Common.Base/Geometry/Point2DCollectionExtensions.cs (revision 0)
+++ Core/Common/src/Core.Common.Base/Geometry/Point2DCollectionExtensions.cs (revision b8976a5e3cf525e419227e409e44ac69a430711a)
@@ -0,0 +1,58 @@
+// Copyright (C) Stichting Deltares 2017. All rights reserved.
+//
+// This file is part of Ringtoets.
+//
+// Ringtoets is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser 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.Collections.Generic;
+using System.Linq;
+
+namespace Core.Common.Base.Geometry
+{
+ public static class Point2DCollectionExtensions
+ {
+ ///
+ /// Checks whether the form a reclining geometry.
+ /// That is, given a point from the geometry with an X-coordinate,
+ /// has a point further in the geometry that has an X-coordinate smaller
+ /// than the X-coordinate of the given point.
+ ///
+ /// The points forming a line to check.
+ /// true if the line is reclining; false
+ /// otherwise.
+ /// Thrown when
+ /// is null.
+ public static bool IsReclining(this IEnumerable points)
+ {
+ if (points == null)
+ {
+ throw new ArgumentNullException(nameof(points));
+ }
+ double[] lCoordinates = points.Select(p => p.X).ToArray();
+ for (var i = 1; i < lCoordinates.Length; i++)
+ {
+ if (lCoordinates[i - 1] > lCoordinates[i])
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+ }
+}
\ No newline at end of file
Index: Core/Common/src/Core.Common.Base/Geometry/Point3DCollectionExtensions.cs
===================================================================
diff -u -rb8fa5d6867c945f3f1744fd1455b89cadb357959 -rb8976a5e3cf525e419227e409e44ac69a430711a
--- Core/Common/src/Core.Common.Base/Geometry/Point3DCollectionExtensions.cs (.../Point3DCollectionExtensions.cs) (revision b8fa5d6867c945f3f1744fd1455b89cadb357959)
+++ Core/Common/src/Core.Common.Base/Geometry/Point3DCollectionExtensions.cs (.../Point3DCollectionExtensions.cs) (revision b8976a5e3cf525e419227e409e44ac69a430711a)
@@ -19,43 +19,47 @@
// Stichting Deltares and remain full property of Stichting Deltares at all times.
// All rights reserved.
+using System;
using System.Collections.Generic;
using System.Linq;
-using Core.Common.Base.Data;
namespace Core.Common.Base.Geometry
{
public static class Point3DCollectionExtensions
{
- private const int numberOfDecimalPlaces = 2;
-
///
/// Projects the points in to localized coordinate (LZ-plane) system.
/// Z-values are retained, and the first point is put a L=0.
///
/// Points to project.
/// Collection of 2D points in the LZ-plane.
- private static RoundedPoint2DCollection ProjectGeometryToLZ(this IEnumerable points)
+ /// Thrown when
+ /// is null.
+ public static IEnumerable ProjectToLZ(this IEnumerable points)
{
+ if (points == null)
+ {
+ throw new ArgumentNullException(nameof(points));
+ }
int count = points.Count();
if (count == 0)
{
- return new RoundedPoint2DCollection(numberOfDecimalPlaces, Enumerable.Empty());
+ return Enumerable.Empty();
}
Point3D first = points.First();
if (count == 1)
{
- return new RoundedPoint2DCollection(numberOfDecimalPlaces, new[]
+ return new[]
{
new Point2D(0.0, first.Z)
- });
+ };
}
Point3D last = points.Last();
var firstPoint = new Point2D(first.X, first.Y);
var lastPoint = new Point2D(last.X, last.Y);
- return new RoundedPoint2DCollection(numberOfDecimalPlaces, points.Select(p => p.ProjectIntoLocalCoordinates(firstPoint, lastPoint)));
+ return points.Select(p => p.ProjectIntoLocalCoordinates(firstPoint, lastPoint));
}
///
@@ -65,8 +69,14 @@
/// The points forming a line to check.
/// true if the line has a length of zero; false
/// otherwise.
+ /// Thrown when
+ /// is null.
public static bool IsZeroLength(this IEnumerable points)
{
+ if (points == null)
+ {
+ throw new ArgumentNullException(nameof(points));
+ }
Point3D lastPoint = null;
foreach (Point3D point in points)
{
@@ -89,19 +99,13 @@
/// L-coordinate smaller than the L-coordinate of the given point.
///
/// The points forming a line to check.
- /// true if the surface line is reclining; false
- /// otherwise.
+ /// true if the localized (in 2D) line is reclining;
+ /// false otherwise.
+ /// Thrown when
+ /// is null.
public static bool IsReclining(this IEnumerable points)
{
- double[] lCoordinates = points.ProjectGeometryToLZ().Select(p => p.X).ToArray();
- for (var i = 1; i < lCoordinates.Length; i++)
- {
- if (lCoordinates[i - 1] > lCoordinates[i])
- {
- return true;
- }
- }
- return false;
+ return points.ProjectToLZ().IsReclining();
}
}
}
\ No newline at end of file
Index: Core/Common/test/Core.Common.Base.Test/Core.Common.Base.Test.csproj
===================================================================
diff -u -r320aceee6e754aa37aa80a80b371a0150cbf2496 -rb8976a5e3cf525e419227e409e44ac69a430711a
--- Core/Common/test/Core.Common.Base.Test/Core.Common.Base.Test.csproj (.../Core.Common.Base.Test.csproj) (revision 320aceee6e754aa37aa80a80b371a0150cbf2496)
+++ Core/Common/test/Core.Common.Base.Test/Core.Common.Base.Test.csproj (.../Core.Common.Base.Test.csproj) (revision b8976a5e3cf525e419227e409e44ac69a430711a)
@@ -89,6 +89,8 @@
+
+
Index: Core/Common/test/Core.Common.Base.Test/Geometry/Point2DCollectionExtensionsTest.cs
===================================================================
diff -u
--- Core/Common/test/Core.Common.Base.Test/Geometry/Point2DCollectionExtensionsTest.cs (revision 0)
+++ Core/Common/test/Core.Common.Base.Test/Geometry/Point2DCollectionExtensionsTest.cs (revision b8976a5e3cf525e419227e409e44ac69a430711a)
@@ -0,0 +1,72 @@
+// Copyright (C) Stichting Deltares 2017. All rights reserved.
+//
+// This file is part of Ringtoets.
+//
+// Ringtoets is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser 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.Collections.Generic;
+using Core.Common.Base.Geometry;
+using NUnit.Framework;
+
+namespace Core.Common.Base.Test.Geometry
+{
+ [TestFixture]
+ public class Point2DCollectionExtensionsTest
+ {
+ [Test]
+ public void IsReclining_PointsNull_ThrowsArgumentNullException()
+ {
+ // Call
+ TestDelegate test = () => ((IEnumerable)null).IsReclining();
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.AreEqual("points", exception.ParamName);
+ }
+
+ [Test]
+ [TestCase(3.01, true)]
+ [TestCase(3 + 1e-6, true)]
+ [TestCase(3, false)]
+ [TestCase(2, false)]
+ [TestCase(1, false)]
+ [TestCase(1 - 1e-6, true)]
+ [TestCase(0.99, true)]
+ [TestCase(0, true)]
+ [TestCase(-5, true)]
+ public void IsReclining_ThirdPointDifferingInPosition_ReturnsTrueIfThirdPointBeforeSecondOrAfterFourth(double thirdPointL, bool expectedResult)
+ {
+ // Setup
+ var random = new Random(21);
+ var points = new[]
+ {
+ new Point2D(0, random.NextDouble()),
+ new Point2D(1, random.NextDouble()),
+ new Point2D(thirdPointL, random.NextDouble()),
+ new Point2D(3, random.NextDouble())
+ };
+
+ // Call
+ bool result = points.IsReclining();
+
+ // Assert
+ Assert.AreEqual(expectedResult, result);
+ }
+ }
+}
\ No newline at end of file
Index: Core/Common/test/Core.Common.Base.Test/Geometry/Point3DCollectionExtensionsTest.cs
===================================================================
diff -u
--- Core/Common/test/Core.Common.Base.Test/Geometry/Point3DCollectionExtensionsTest.cs (revision 0)
+++ Core/Common/test/Core.Common.Base.Test/Geometry/Point3DCollectionExtensionsTest.cs (revision b8976a5e3cf525e419227e409e44ac69a430711a)
@@ -0,0 +1,245 @@
+// Copyright (C) Stichting Deltares 2017. All rights reserved.
+//
+// This file is part of Ringtoets.
+//
+// Ringtoets is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser 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.Collections.Generic;
+using System.Linq;
+using Core.Common.Base.Data;
+using Core.Common.Base.Geometry;
+using Core.Common.TestUtil;
+using NUnit.Framework;
+
+namespace Core.Common.Base.Test.Geometry
+{
+ [TestFixture]
+ public class Point3DCollectionExtensionsTest
+ {
+ [Test]
+ public void IsReclining_PointsNull_ThrowsArgumentNullException()
+ {
+ // Call
+ TestDelegate test = () => ((IEnumerable)null).IsReclining();
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.AreEqual("points", exception.ParamName);
+ }
+
+ [Test]
+ [TestCase(3.01, true)]
+ [TestCase(3 + 1e-6, true)]
+ [TestCase(3, false)]
+ [TestCase(2, false)]
+ [TestCase(1, false)]
+ [TestCase(1 - 1e-6, true)]
+ [TestCase(0.99, true)]
+ [TestCase(0, true)]
+ [TestCase(-5, true)]
+ public void IsReclining_ThirdPointDifferingInPosition_ReturnsTrueIfThirdPointBeforeSecondOrAfterFourth(double thirdPointL, bool expectedResult)
+ {
+ // Setup
+ var random = new Random(21);
+ double randomY = random.NextDouble();
+ var points = new[]
+ {
+ new Point3D(0, randomY, random.NextDouble()),
+ new Point3D(1, randomY, random.NextDouble()),
+ new Point3D(thirdPointL, randomY, random.NextDouble()),
+ new Point3D(3, randomY, random.NextDouble())
+ };
+
+ // Call
+ bool result = points.IsReclining();
+
+ // Assert
+ Assert.AreEqual(expectedResult, result);
+ }
+
+ [Test]
+ public void IsZeroLength_PointsNull_ThrowsArgumentNullException()
+ {
+ // Call
+ TestDelegate test = () => ((IEnumerable)null).IsZeroLength();
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.AreEqual("points", exception.ParamName);
+ }
+ [Test]
+ [TestCase(3)]
+ [TestCase(2.01)]
+ [TestCase(1.99)]
+ [TestCase(1)]
+ public void IsZeroLength_DifferenceInX_ReturnsFalse(double otherPointX)
+ {
+ // Setup
+ var random = new Random(21);
+ double randomY = random.NextDouble();
+ double randomZ = random.NextDouble();
+ var points = new[]
+ {
+ new Point3D(2, randomY, randomZ),
+ new Point3D(otherPointX, randomY, randomZ)
+ };
+
+ // Call
+ bool result = points.IsZeroLength();
+
+ // Assert
+ Assert.IsFalse(result);
+ }
+
+ [Test]
+ [TestCase(3)]
+ [TestCase(2.01)]
+ [TestCase(1.99)]
+ [TestCase(1)]
+ public void IsZeroLength_DifferenceInZ_ReturnsFalse(double otherPointZ)
+ {
+ // Setup
+ var random = new Random(21);
+ double randomX = random.NextDouble();
+ double randomY = random.NextDouble();
+ var points = new[]
+ {
+ new Point3D(randomX, randomY, 2),
+ new Point3D(randomX, randomY, otherPointZ)
+ };
+
+ // Call
+ bool result = points.IsZeroLength();
+
+ // Assert
+ Assert.IsFalse(result);
+ }
+
+ [Test]
+ [TestCase(3)]
+ [TestCase(2.01)]
+ [TestCase(1.99)]
+ [TestCase(1)]
+ public void IsZeroLength_DifferenceInY_ReturnsFalse(double otherPointY)
+ {
+ // Setup
+ var random = new Random(21);
+ double randomX = random.NextDouble();
+ double randomZ = random.NextDouble();
+ var points = new[]
+ {
+ new Point3D(randomX, 2, randomZ),
+ new Point3D(randomX, otherPointY, randomZ)
+ };
+
+ // Call
+ bool result = points.IsZeroLength();
+
+ // Assert
+ Assert.IsFalse(result);
+ }
+
+ [Test]
+ [TestCase(1)]
+ [TestCase(2)]
+ [TestCase(12)]
+ public void IsZeroLength_PointsEqualToEachother_ReturnsTrue(int pointCount)
+ {
+ // Setup
+ IEnumerable points = Enumerable.Repeat(new Point3D(3, 4, 7), pointCount);
+
+ // Call
+ bool result = points.IsZeroLength();
+
+ // Assert
+ Assert.IsTrue(result);
+ }
+
+ [Test]
+ public void ProjectToLZ_PointsNull_ThrowsArgumentNullException()
+ {
+ // Call
+ TestDelegate test = () => ((IEnumerable)null).ProjectToLZ();
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.AreEqual("points", exception.ParamName);
+ }
+
+ [Test]
+ public void ProjectToLZ_EmptyCollection_ReturnEmptyCollection()
+ {
+ // Setup
+ var points = new Point3D[0];
+
+ // Call
+ IEnumerable lzCoordinates = points.ProjectToLZ();
+
+ // Assert
+ CollectionAssert.IsEmpty(lzCoordinates);
+ }
+
+ [Test]
+ public void ProjectToLZ_GeometryWithOnePoint_ReturnSinglePointAtZeroXAndOriginalZ()
+ {
+ // Setup
+ const double originalZ = 3.3;
+ var points = new[]
+ {
+ new Point3D(1.1, 2.2, originalZ)
+ };
+
+ // Call
+ IEnumerable lzCoordinates = points.ProjectToLZ();
+
+ // Assert
+ CollectionAssert.AreEqual(new[]
+ {
+ new Point2D(0.0, originalZ)
+ }, lzCoordinates);
+ }
+
+ [Test]
+ public void ProjectToLZ_GeometryWithMultiplePoints_ProjectPointsOntoLzPlaneKeepingOriginalZ()
+ {
+ // Setup
+ var points = new[]
+ {
+ new Point3D(1.0, 1.0, 2.2),
+ new Point3D(2.0, 3.0, 4.4), // Outlier from line specified by extrema
+ new Point3D(3.0, 4.0, 7.7)
+ };
+
+ // Call
+ IEnumerable actual = points.ProjectToLZ();
+
+ // Assert
+ double length = Math.Sqrt(2 * 2 + 3 * 3);
+ const double secondCoordinateFactor = (2.0 * 1.0 + 3.0 * 2.0) / (2.0 * 2.0 + 3.0 * 3.0);
+ var expectedCoordinatesX = new[]
+ {
+ 0.0,
+ secondCoordinateFactor * length,
+ length
+ };
+ CollectionAssert.AreEqual(expectedCoordinatesX, actual.Select(p => p.X).ToArray(), new DoubleWithToleranceComparer(0.5e-2));
+ CollectionAssert.AreEqual(points.Select(p => p.Z).ToArray(), actual.Select(p => p.Y).ToArray());
+ }
+ }
+}
\ No newline at end of file
Index: Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.Designer.cs
===================================================================
diff -u -ra940166534b3dd6e778de2e7c8e7e5241f3d3381 -rb8976a5e3cf525e419227e409e44ac69a430711a
--- Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision a940166534b3dd6e778de2e7c8e7e5241f3d3381)
+++ Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision b8976a5e3cf525e419227e409e44ac69a430711a)
@@ -1986,22 +1986,40 @@
///
/// Looks up a localized string similar to Een punt in de geometrie voor de profielschematisatie heeft geen waarde..
///
- public static string SurfaceLine_A_point_in_the_collection_was_null {
+ public static string SurfaceLine_SetGeometry_A_point_in_the_collection_was_null {
get {
- return ResourceManager.GetString("SurfaceLine_A_point_in_the_collection_was_null", resourceCulture);
+ return ResourceManager.GetString("SurfaceLine_SetGeometry_A_point_in_the_collection_was_null", resourceCulture);
}
}
///
/// Looks up a localized string similar to De geometrie die opgegeven werd voor de profielschematisatie heeft geen waarde..
///
- public static string SurfaceLine_Collection_of_points_for_geometry_is_null {
+ public static string SurfaceLine_SetGeometry_Collection_of_points_for_geometry_is_null {
get {
- return ResourceManager.GetString("SurfaceLine_Collection_of_points_for_geometry_is_null", resourceCulture);
+ return ResourceManager.GetString("SurfaceLine_SetGeometry_Collection_of_points_for_geometry_is_null", resourceCulture);
}
}
///
+ /// Looks up a localized string similar to Profielschematisatie heeft een teruglopende geometrie (punten behoren een oplopende set L-coördinaten te hebben in het lokale coördinatenstelsel)..
+ ///
+ public static string SurfaceLine_SetGeometry_SurfaceLine_has_reclining_geometry {
+ get {
+ return ResourceManager.GetString("SurfaceLine_SetGeometry_SurfaceLine_has_reclining_geometry", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to Profielschematisatie heeft een geometrie die een lijn met lengte 0 beschrijft..
+ ///
+ public static string SurfaceLine_SetGeometry_SurfaceLine_has_zero_length {
+ get {
+ return ResourceManager.GetString("SurfaceLine_SetGeometry_SurfaceLine_has_zero_length", resourceCulture);
+ }
+ }
+
+ ///
/// Looks up a localized string similar to Karakteristieke punten gevonden zonder bijbehorende profielschematisatie voor locatie '{0}'..
///
public static string SurfaceLinesCsvImporter_AddImportedDataToModel_Characteristic_points_found_for_unknown_SurfaceLine_0_ {
@@ -2245,24 +2263,6 @@
}
///
- /// Looks up a localized string similar to Profielschematisatie heeft een teruglopende geometrie (punten behoren een oplopende set L-coördinaten te hebben in het lokale coördinatenstelsel)..
- ///
- public static string SurfaceLinesCsvReader_ReadLine_SurfaceLine_has_reclining_geometry {
- get {
- return ResourceManager.GetString("SurfaceLinesCsvReader_ReadLine_SurfaceLine_has_reclining_geometry", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to Profielschematisatie heeft een geometrie die een lijn met lengte 0 beschrijft..
- ///
- public static string SurfaceLinesCsvReader_ReadLine_SurfaceLine_has_zero_length {
- get {
- return ResourceManager.GetString("SurfaceLinesCsvReader_ReadLine_SurfaceLine_has_zero_length", resourceCulture);
- }
- }
-
- ///
/// Looks up a localized string similar to Voor de profielschematisatie ontbreken er waardes om een 3D (X,Y,Z) punt aan te maken..
///
public static string SurfaceLinesCsvReader_ReadLine_SurfaceLine_lacks_values_for_coordinate_triplet {
Index: Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.resx
===================================================================
diff -u -ra940166534b3dd6e778de2e7c8e7e5241f3d3381 -rb8976a5e3cf525e419227e409e44ac69a430711a
--- Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.resx (.../Resources.resx) (revision a940166534b3dd6e778de2e7c8e7e5241f3d3381)
+++ Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.resx (.../Resources.resx) (revision b8976a5e3cf525e419227e409e44ac69a430711a)
@@ -665,10 +665,10 @@
Er is voor scenario geen contributie of relevantie opgegeven.
-
+
Een punt in de geometrie voor de profielschematisatie heeft geen waarde.
-
+
De geometrie die opgegeven werd voor de profielschematisatie heeft geen waarde.
@@ -698,7 +698,7 @@
Het bestand is niet geschikt om profielschematisaties uit te lezen (Verwachte koptekst: locationid;X1;Y1;Z1).
-
+
Profielschematisatie heeft een teruglopende geometrie (punten behoren een oplopende set L-coördinaten te hebben in het lokale coördinatenstelsel).
@@ -713,7 +713,7 @@
profielschematisatie '{0}'
-
+
Profielschematisatie heeft een geometrie die een lijn met lengte 0 beschrijft.
Index: Ringtoets/Common/src/Ringtoets.Common.IO/SurfaceLines/SurfaceLine.cs
===================================================================
diff -u -rb8fa5d6867c945f3f1744fd1455b89cadb357959 -rb8976a5e3cf525e419227e409e44ac69a430711a
--- Ringtoets/Common/src/Ringtoets.Common.IO/SurfaceLines/SurfaceLine.cs (.../SurfaceLine.cs) (revision b8fa5d6867c945f3f1744fd1455b89cadb357959)
+++ Ringtoets/Common/src/Ringtoets.Common.IO/SurfaceLines/SurfaceLine.cs (.../SurfaceLine.cs) (revision b8976a5e3cf525e419227e409e44ac69a430711a)
@@ -69,19 +69,19 @@
{
if (points == null)
{
- throw new ArgumentNullException(nameof(points), Resources.SurfaceLine_Collection_of_points_for_geometry_is_null);
+ throw new ArgumentNullException(nameof(points), Resources.SurfaceLine_SetGeometry_Collection_of_points_for_geometry_is_null);
}
if (points.Any(p => p == null))
{
- throw new ArgumentException(Resources.SurfaceLine_A_point_in_the_collection_was_null);
+ throw new ArgumentException(Resources.SurfaceLine_SetGeometry_A_point_in_the_collection_was_null);
}
if (points.IsZeroLength())
{
- throw new ArgumentException(Resources.SurfaceLinesCsvReader_ReadLine_SurfaceLine_has_zero_length);
+ throw new ArgumentException(Resources.SurfaceLine_SetGeometry_SurfaceLine_has_zero_length);
}
- if (points.IsReclining())
+ if (new RoundedPoint2DCollection(2, points.ProjectToLZ()).IsReclining())
{
- throw new ArgumentException(Resources.SurfaceLinesCsvReader_ReadLine_SurfaceLine_has_reclining_geometry);
+ throw new ArgumentException(Resources.SurfaceLine_SetGeometry_SurfaceLine_has_reclining_geometry);
}
Points = points.Select(p => new Point3D(p)).ToArray();
}
Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/SurfaceLines/SurfaceLineTest.cs
===================================================================
diff -u -rb8fa5d6867c945f3f1744fd1455b89cadb357959 -rb8976a5e3cf525e419227e409e44ac69a430711a
--- Ringtoets/Common/test/Ringtoets.Common.IO.Test/SurfaceLines/SurfaceLineTest.cs (.../SurfaceLineTest.cs) (revision b8fa5d6867c945f3f1744fd1455b89cadb357959)
+++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/SurfaceLines/SurfaceLineTest.cs (.../SurfaceLineTest.cs) (revision b8976a5e3cf525e419227e409e44ac69a430711a)
@@ -24,7 +24,6 @@
using System.Linq;
using Core.Common.Base;
using Core.Common.Base.Geometry;
-using Core.Common.Base.Properties;
using Core.Common.TestUtil;
using NUnit.Framework;
using Ringtoets.Common.IO.SurfaceLines;
@@ -155,123 +154,5 @@
Assert.DoesNotThrow(test);
}
}
-
- [Test]
- [TestCase(3.01, true)]
- [TestCase(3 + 1e-6, false)]
- [TestCase(3, false)]
- [TestCase(2, false)]
- [TestCase(1, false)]
- [TestCase(1 - 1e-6, false)]
- [TestCase(0.99, true)]
- [TestCase(0, true)]
- [TestCase(-5, true)]
- public void IsReclining_ThirdPointDifferingInPosition_ReturnsTrueIfThirdPointBeforeSecondOrAfterFourth(double thirdPointL, bool expectedResult)
- {
- // Setup
- var random = new Random(21);
- double randomY = random.NextDouble();
- var points = new[]
- {
- new Point3D(0, randomY, random.NextDouble()),
- new Point3D(1, randomY, random.NextDouble()),
- new Point3D(thirdPointL, randomY, random.NextDouble()),
- new Point3D(3, randomY, random.NextDouble())
- };
-
- // Call
- bool result = points.IsReclining();
-
- // Assert
- Assert.AreEqual(expectedResult, result);
- }
-
- [Test]
- [TestCase(3)]
- [TestCase(2.01)]
- [TestCase(1.99)]
- [TestCase(1)]
- public void IsZeroLength_DifferenceInX_ReturnsFalse(double otherPointX)
- {
- // Setup
- var random = new Random(21);
- double randomY = random.NextDouble();
- double randomZ = random.NextDouble();
- var points = new[]
- {
- new Point3D(2, randomY, randomZ),
- new Point3D(otherPointX, randomY, randomZ)
- };
-
- // Call
- bool result = points.IsZeroLength();
-
- // Assert
- Assert.IsFalse(result);
- }
-
- [Test]
- [TestCase(3)]
- [TestCase(2.01)]
- [TestCase(1.99)]
- [TestCase(1)]
- public void IsZeroLength_DifferenceInZ_ReturnsFalse(double otherPointZ)
- {
- // Setup
- var random = new Random(21);
- double randomX = random.NextDouble();
- double randomY = random.NextDouble();
- var points = new[]
- {
- new Point3D(randomX, randomY, 2),
- new Point3D(randomX, randomY, otherPointZ)
- };
-
- // Call
- bool result = points.IsZeroLength();
-
- // Assert
- Assert.IsFalse(result);
- }
-
- [Test]
- [TestCase(3)]
- [TestCase(2.01)]
- [TestCase(1.99)]
- [TestCase(1)]
- public void IsZeroLength_DifferenceInY_ReturnsFalse(double otherPointY)
- {
- // Setup
- var random = new Random(21);
- double randomX = random.NextDouble();
- double randomZ = random.NextDouble();
- var points = new[]
- {
- new Point3D(randomX, 2, randomZ),
- new Point3D(randomX, otherPointY, randomZ)
- };
-
- // Call
- bool result = points.IsZeroLength();
-
- // Assert
- Assert.IsFalse(result);
- }
-
- [Test]
- [TestCase(1)]
- [TestCase(2)]
- [TestCase(12)]
- public void IsZeroLength_PointsEqualToEachother_ReturnsTrue(int pointCount)
- {
- // Setup
- IEnumerable points = Enumerable.Repeat(new Point3D(3, 4, 7), pointCount);
-
- // Call
- bool result = points.IsZeroLength();
-
- // Assert
- Assert.IsTrue(result);
- }
}
}
\ No newline at end of file
Index: Ringtoets/Piping/src/Ringtoets.Piping.Data/PipingInput.cs
===================================================================
diff -u -r5906f61fff270a7526253bea07dfecdf680898ed -rb8976a5e3cf525e419227e409e44ac69a430711a
--- Ringtoets/Piping/src/Ringtoets.Piping.Data/PipingInput.cs (.../PipingInput.cs) (revision 5906f61fff270a7526253bea07dfecdf680898ed)
+++ Ringtoets/Piping/src/Ringtoets.Piping.Data/PipingInput.cs (.../PipingInput.cs) (revision b8976a5e3cf525e419227e409e44ac69a430711a)
@@ -270,7 +270,7 @@
int entryPointIndex = Array.IndexOf(SurfaceLine.Points, SurfaceLine.DikeToeAtRiver);
int exitPointIndex = Array.IndexOf(SurfaceLine.Points, SurfaceLine.DikeToeAtPolder);
- Point2D[] localGeometry = SurfaceLine.ProjectGeometryToLZ().ToArray();
+ Point2D[] localGeometry = SurfaceLine.LocalGeometry.ToArray();
tempEntryPointL = localGeometry[0].X;
tempExitPointL = localGeometry[localGeometry.Length - 1].X;
Index: Ringtoets/Piping/src/Ringtoets.Piping.Forms/Factories/PipingChartDataPointsFactory.cs
===================================================================
diff -u -r93036b575ee81b4517b29db51f1eadf81454fb93 -rb8976a5e3cf525e419227e409e44ac69a430711a
--- Ringtoets/Piping/src/Ringtoets.Piping.Forms/Factories/PipingChartDataPointsFactory.cs (.../PipingChartDataPointsFactory.cs) (revision 93036b575ee81b4517b29db51f1eadf81454fb93)
+++ Ringtoets/Piping/src/Ringtoets.Piping.Forms/Factories/PipingChartDataPointsFactory.cs (.../PipingChartDataPointsFactory.cs) (revision b8976a5e3cf525e419227e409e44ac69a430711a)
@@ -22,6 +22,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using Core.Common.Base.Data;
using Core.Common.Base.Geometry;
using Core.Common.Geometry;
using Core.Components.Chart.Data;
@@ -43,7 +44,7 @@
/// An array of points in 2D space or an empty array when is null.
public static Point2D[] CreateSurfaceLinePoints(RingtoetsPipingSurfaceLine surfaceLine)
{
- return surfaceLine?.ProjectGeometryToLZ().ToArray() ?? new Point2D[0];
+ return surfaceLine?.LocalGeometry.ToArray() ?? new Point2D[0];
}
///
@@ -231,7 +232,7 @@
return Enumerable.Empty();
}
- Point2D[] surfaceLineLocalGeometry = surfaceLine.ProjectGeometryToLZ().ToArray();
+ Point2D[] surfaceLineLocalGeometry = surfaceLine.LocalGeometry.ToArray();
if (IsSurfaceLineAboveSoilLayer(surfaceLineLocalGeometry, soilLayer))
{
Index: Ringtoets/Piping/src/Ringtoets.Piping.KernelWrapper/PipingSurfaceLineCreator.cs
===================================================================
diff -u -r81fa8a9bf3bd503cbd280e88b8f6037a840cff12 -rb8976a5e3cf525e419227e409e44ac69a430711a
--- Ringtoets/Piping/src/Ringtoets.Piping.KernelWrapper/PipingSurfaceLineCreator.cs (.../PipingSurfaceLineCreator.cs) (revision 81fa8a9bf3bd503cbd280e88b8f6037a840cff12)
+++ Ringtoets/Piping/src/Ringtoets.Piping.KernelWrapper/PipingSurfaceLineCreator.cs (.../PipingSurfaceLineCreator.cs) (revision b8976a5e3cf525e419227e409e44ac69a430711a)
@@ -21,6 +21,7 @@
using System.Collections.Generic;
using System.Linq;
+using Core.Common.Base.Data;
using Core.Common.Base.Geometry;
using Deltares.WTIPiping;
using Ringtoets.Piping.Primitives;
@@ -54,7 +55,7 @@
private static IEnumerable CreatePoints(RingtoetsPipingSurfaceLine line)
{
- Point2D[] projectedPoints = line.ProjectGeometryToLZ().ToArray();
+ Point2D[] projectedPoints = line.LocalGeometry.ToArray();
var pipingPoints = new List();
for (var i = 0; i < line.Points.Length; i++)
Index: Ringtoets/Piping/src/Ringtoets.Piping.Primitives/RingtoetsPipingSurfaceLine.cs
===================================================================
diff -u -ra940166534b3dd6e778de2e7c8e7e5241f3d3381 -rb8976a5e3cf525e419227e409e44ac69a430711a
--- Ringtoets/Piping/src/Ringtoets.Piping.Primitives/RingtoetsPipingSurfaceLine.cs (.../RingtoetsPipingSurfaceLine.cs) (revision a940166534b3dd6e778de2e7c8e7e5241f3d3381)
+++ Ringtoets/Piping/src/Ringtoets.Piping.Primitives/RingtoetsPipingSurfaceLine.cs (.../RingtoetsPipingSurfaceLine.cs) (revision b8976a5e3cf525e419227e409e44ac69a430711a)
@@ -39,7 +39,7 @@
public class RingtoetsPipingSurfaceLine : Observable, IMechanismSurfaceLine
{
private const int numberOfDecimalPlaces = 2;
- private Point2D[] localGeometry;
+ private RoundedPoint2DCollection localGeometry;
///
/// Initializes a new instance of the class.
@@ -48,7 +48,7 @@
{
Name = string.Empty;
Points = new Point3D[0];
- localGeometry = new Point2D[0];
+ localGeometry = new RoundedPoint2DCollection(2, new Point2D[0]);
}
///
@@ -109,7 +109,7 @@
///
/// Gets the 2D points describing the local geometry of the surface line.
///
- public IEnumerable LocalGeometry
+ public RoundedPoint2DCollection LocalGeometry
{
get
{
@@ -141,7 +141,7 @@
EndingWorldPoint = Points[Points.Length - 1];
}
- localGeometry = ProjectGeometryToLZ().ToArray();
+ localGeometry = new RoundedPoint2DCollection(numberOfDecimalPlaces, Points.ProjectToLZ().ToArray());
}
///
@@ -269,9 +269,9 @@
}
var segments = new Collection();
- for (var i = 1; i < localGeometry.Length; i++)
+ for (var i = 1; i < localGeometry.Count(); i++)
{
- segments.Add(new Segment2D(localGeometry[i - 1], localGeometry[i]));
+ segments.Add(new Segment2D(localGeometry.ElementAt(i - 1), localGeometry.ElementAt(i)));
}
IEnumerable intersectionPoints = Math2D.SegmentsIntersectionWithVerticalLine(segments, l).OrderBy(p => p.Y).ToArray();
@@ -289,34 +289,6 @@
}
///
- /// Projects the points in to localized coordinate (LZ-plane) system.
- /// Z-values are retained, and the first point is put a L=0.
- ///
- /// Collection of 2D points in the LZ-plane.
- public RoundedPoint2DCollection ProjectGeometryToLZ()
- {
- int count = Points.Length;
- if (count == 0)
- {
- return new RoundedPoint2DCollection(numberOfDecimalPlaces, Enumerable.Empty());
- }
-
- Point3D first = Points.First();
- if (count == 1)
- {
- return new RoundedPoint2DCollection(numberOfDecimalPlaces, new[]
- {
- new Point2D(0.0, first.Z)
- });
- }
-
- Point3D last = Points.Last();
- var firstPoint = new Point2D(first.X, first.Y);
- var lastPoint = new Point2D(last.X, last.Y);
- return new RoundedPoint2DCollection(numberOfDecimalPlaces, Points.Select(p => p.ProjectIntoLocalCoordinates(firstPoint, lastPoint)));
- }
-
- ///
/// Checks whether is in range of the geometry projected in local coordinate system
/// where the points are ordered on the L-coordinate being monotonically non-decreasing.
///
Index: Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/PipingInputTest.cs
===================================================================
diff -u -r8bb6e849266ec28412ebfe23beccd7235c4db9bf -rb8976a5e3cf525e419227e409e44ac69a430711a
--- Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/PipingInputTest.cs (.../PipingInputTest.cs) (revision 8bb6e849266ec28412ebfe23beccd7235c4db9bf)
+++ Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/PipingInputTest.cs (.../PipingInputTest.cs) (revision b8976a5e3cf525e419227e409e44ac69a430711a)
@@ -193,7 +193,7 @@
};
// Call
- RoundedPoint2DCollection localGeometry = pipingInput.SurfaceLine.ProjectGeometryToLZ();
+ RoundedPoint2DCollection localGeometry = pipingInput.SurfaceLine.LocalGeometry;
// Assert
Assert.AreEqual(localGeometry.NumberOfDecimalPlaces, pipingInput.ExitPointL.NumberOfDecimalPlaces);
@@ -308,7 +308,7 @@
var pipingInput = new PipingInput(new GeneralPipingInput());
// Call
- RoundedPoint2DCollection localGeometry = surfaceLine.ProjectGeometryToLZ();
+ RoundedPoint2DCollection localGeometry = surfaceLine.LocalGeometry;
// Assert
Assert.AreEqual(localGeometry.NumberOfDecimalPlaces, pipingInput.EntryPointL.NumberOfDecimalPlaces);
Index: Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/RingtoetsPipingSurfaceLineTest.cs
===================================================================
diff -u -r081badaad87a6e2a6d5c861de9ee95fa1ca6dea3 -rb8976a5e3cf525e419227e409e44ac69a430711a
--- Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/RingtoetsPipingSurfaceLineTest.cs (.../RingtoetsPipingSurfaceLineTest.cs) (revision 081badaad87a6e2a6d5c861de9ee95fa1ca6dea3)
+++ Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/RingtoetsPipingSurfaceLineTest.cs (.../RingtoetsPipingSurfaceLineTest.cs) (revision b8976a5e3cf525e419227e409e44ac69a430711a)
@@ -129,71 +129,6 @@
}
[Test]
- public void ProjectGeometryToLZ_EmptyCollection_ReturnEmptyCollection()
- {
- // Setup
- var surfaceLine = new RingtoetsPipingSurfaceLine();
-
- // Call
- RoundedPoint2DCollection lzCoordinates = surfaceLine.ProjectGeometryToLZ();
-
- // Assert
- CollectionAssert.IsEmpty(lzCoordinates);
- Assert.AreEqual(2, lzCoordinates.NumberOfDecimalPlaces);
- }
-
- [Test]
- public void ProjectGeometryToLZ_GeometryWithOnePoint_ReturnSinglePointAtZeroXAndOriginalZ()
- {
- // Setup
- var surfaceLine = new RingtoetsPipingSurfaceLine();
- const double originalZ = 3.3;
- surfaceLine.SetGeometry(new[]
- {
- new Point3D(1.1, 2.2, originalZ)
- });
-
- // Call
- RoundedPoint2DCollection lzCoordinates = surfaceLine.ProjectGeometryToLZ();
-
- // Assert
- CollectionAssert.AreEqual(new[]
- {
- new Point2D(0.0, originalZ)
- }, lzCoordinates);
- Assert.AreEqual(2, lzCoordinates.NumberOfDecimalPlaces);
- }
-
- [Test]
- public void ProjectGeometryToLZ_GeometryWithMultiplePoints_ProjectPointsOntoLzPlaneKeepingOriginalZ()
- {
- // Setup
- var surfaceLine = new RingtoetsPipingSurfaceLine();
- surfaceLine.SetGeometry(new[]
- {
- new Point3D(1.0, 1.0, 2.2),
- new Point3D(2.0, 3.0, 4.4), // Outlier from line specified by extrema
- new Point3D(3.0, 4.0, 7.7)
- });
-
- // Call
- RoundedPoint2DCollection actual = surfaceLine.ProjectGeometryToLZ();
-
- // Assert
- double length = Math.Sqrt(2 * 2 + 3 * 3);
- const double secondCoordinateFactor = (2.0 * 1.0 + 3.0 * 2.0) / (2.0 * 2.0 + 3.0 * 3.0);
- var expectedCoordinatesX = new[]
- {
- 0.0,
- secondCoordinateFactor * length,
- length
- };
- CollectionAssert.AreEqual(expectedCoordinatesX, actual.Select(p => p.X).ToArray(), new DoubleWithToleranceComparer(actual.GetAccuracy()));
- CollectionAssert.AreEqual(surfaceLine.Points.Select(p => p.Z).ToArray(), actual.Select(p => p.Y).ToArray());
- Assert.AreEqual(2, actual.NumberOfDecimalPlaces);
- }
-
- [Test]
public void SetGeometry_GeometryIsNull_ThrowsArgumentNullException()
{
// Setup
Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Factories/PipingChartDataPointsFactoryTest.cs
===================================================================
diff -u -rf1f94637a6b45b394493bf16a078b317c02d329b -rb8976a5e3cf525e419227e409e44ac69a430711a
--- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Factories/PipingChartDataPointsFactoryTest.cs (.../PipingChartDataPointsFactoryTest.cs) (revision f1f94637a6b45b394493bf16a078b317c02d329b)
+++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Factories/PipingChartDataPointsFactoryTest.cs (.../PipingChartDataPointsFactoryTest.cs) (revision b8976a5e3cf525e419227e409e44ac69a430711a)
@@ -53,7 +53,7 @@
Point2D[] points = PipingChartDataPointsFactory.CreateSurfaceLinePoints(surfaceLine);
// Assert
- AssertEqualPointCollections(surfaceLine.ProjectGeometryToLZ(), points);
+ AssertEqualPointCollections(surfaceLine.LocalGeometry, points);
}
[Test]
Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Views/PipingInputViewTest.cs
===================================================================
diff -u -r93036b575ee81b4517b29db51f1eadf81454fb93 -rb8976a5e3cf525e419227e409e44ac69a430711a
--- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Views/PipingInputViewTest.cs (.../PipingInputViewTest.cs) (revision 93036b575ee81b4517b29db51f1eadf81454fb93)
+++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Views/PipingInputViewTest.cs (.../PipingInputViewTest.cs) (revision b8976a5e3cf525e419227e409e44ac69a430711a)
@@ -23,6 +23,7 @@
using System.Linq;
using System.Windows.Forms;
using Core.Common.Base;
+using Core.Common.Base.Data;
using Core.Common.Base.Geometry;
using Core.Components.Chart.Data;
using Core.Components.Chart.Forms;
@@ -836,7 +837,7 @@
var surfaceLineChartData = (ChartLineData) chartData;
Assert.AreEqual(surfaceLine.Points.Length, surfaceLineChartData.Points.Length);
- CollectionAssert.AreEqual(surfaceLine.ProjectGeometryToLZ(), surfaceLineChartData.Points);
+ CollectionAssert.AreEqual(surfaceLine.LocalGeometry, surfaceLineChartData.Points);
Assert.AreEqual(surfaceLine.Name, chartData.Name);
}