Index: Core/Common/src/Core.Common.Base/Geometry/Math2D.cs
===================================================================
diff -u -rf28fac2f7d391c4d48691c180f7ae8335b278c72 -re678af24e939bdb6b49294b16b06af9565bef9b1
--- Core/Common/src/Core.Common.Base/Geometry/Math2D.cs (.../Math2D.cs) (revision f28fac2f7d391c4d48691c180f7ae8335b278c72)
+++ Core/Common/src/Core.Common.Base/Geometry/Math2D.cs (.../Math2D.cs) (revision e678af24e939bdb6b49294b16b06af9565bef9b1)
@@ -92,6 +92,33 @@
}
///
+ /// Creates an enumerator that converts a sequence of line points to a sequence of line segments
+ /// and adds a segment between the last and the first point of the sequence.
+ ///
+ /// The line points.
+ /// A sequence of N elements, where N is the number of elements in ,
+ /// or 0 if has one or no elements.
+ public static IEnumerable ConvertLinePointsToClosingLineSegments(IEnumerable linePoints)
+ {
+ if (linePoints.Count() < 2)
+ {
+ yield break;
+ }
+
+ Point2D endPoint = linePoints.Last();
+ foreach (Point2D linePoint in linePoints)
+ {
+ Point2D startPoint = endPoint;
+ endPoint = linePoint;
+
+ if (startPoint != null)
+ {
+ yield return new Segment2D(startPoint, endPoint);
+ }
+ }
+ }
+
+ ///
/// Determines the intersection point of a line which passes through the and
/// the ; and a line which passes through the
/// and the .
Index: Core/Common/test/Core.Common.Base.Test/Geometry/Math2DTest.cs
===================================================================
diff -u -rb513e76d805898795483251f7d070489dfd20b9b -re678af24e939bdb6b49294b16b06af9565bef9b1
--- Core/Common/test/Core.Common.Base.Test/Geometry/Math2DTest.cs (.../Math2DTest.cs) (revision b513e76d805898795483251f7d070489dfd20b9b)
+++ Core/Common/test/Core.Common.Base.Test/Geometry/Math2DTest.cs (.../Math2DTest.cs) (revision e678af24e939bdb6b49294b16b06af9565bef9b1)
@@ -203,6 +203,46 @@
[Test]
[TestCase(0)]
[TestCase(1)]
+ public void ConvertLinePointsToClosingLineSegments_TooFewPoints_ReturnEmpty(int pointCount)
+ {
+ // Setup
+ IEnumerable linePoints = Enumerable.Repeat(new Point2D(0, 0), pointCount);
+
+ // Call
+ IEnumerable segments = Math2D.ConvertLinePointsToClosingLineSegments(linePoints);
+
+ // Assert
+ CollectionAssert.IsEmpty(segments);
+ }
+
+ [Test]
+ public void ConvertLinePointsToClosingLineSegments_TwoPoints_ReturnsExpectedSegments()
+ {
+ // Setup
+ var linePoints = new[]
+ {
+ new Point2D(0, 0),
+ new Point2D(1, 1)
+ };
+
+ // Call
+ Segment2D[] segments = Math2D.ConvertLinePointsToClosingLineSegments(linePoints).ToArray();
+
+ // Assert
+ Assert.AreEqual(2, segments.Length);
+
+ Segment2D firstSegment = segments[0];
+ Assert.AreEqual(linePoints[1], firstSegment.FirstPoint);
+ Assert.AreEqual(linePoints[0], firstSegment.SecondPoint);
+
+ Segment2D secondSegment = segments[1];
+ Assert.AreEqual(linePoints[0], secondSegment.FirstPoint);
+ Assert.AreEqual(linePoints[1], secondSegment.SecondPoint);
+ }
+
+ [Test]
+ [TestCase(0)]
+ [TestCase(1)]
public void SplitLineAtLengths_TooFewPoints_ThrowArgumentException(int pointCount)
{
// Setup
Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Service/MacroStabilityInwardsInputValidator.cs
===================================================================
diff -u -r73bd43678d003eca592c2ce14a2500a983d9b4c9 -re678af24e939bdb6b49294b16b06af9565bef9b1
--- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Service/MacroStabilityInwardsInputValidator.cs (.../MacroStabilityInwardsInputValidator.cs) (revision 73bd43678d003eca592c2ce14a2500a983d9b4c9)
+++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Service/MacroStabilityInwardsInputValidator.cs (.../MacroStabilityInwardsInputValidator.cs) (revision e678af24e939bdb6b49294b16b06af9565bef9b1)
@@ -147,7 +147,7 @@
{
bool isNear = soilProfile2D.Layers.Any(l => IsPointNearSoilSegments(
surfaceLinePoint,
- Math2D.ConvertLinePointsToLineSegments(l.OuterRing.Points)));
+ Math2D.ConvertLinePointsToClosingLineSegments(l.OuterRing.Points)));
if (!isNear)
{
return false;
Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Service.Test/MacroStabilityInwardsInputValidatorTest.cs
===================================================================
diff -u -r73bd43678d003eca592c2ce14a2500a983d9b4c9 -re678af24e939bdb6b49294b16b06af9565bef9b1
--- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Service.Test/MacroStabilityInwardsInputValidatorTest.cs (.../MacroStabilityInwardsInputValidatorTest.cs) (revision 73bd43678d003eca592c2ce14a2500a983d9b4c9)
+++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Service.Test/MacroStabilityInwardsInputValidatorTest.cs (.../MacroStabilityInwardsInputValidatorTest.cs) (revision e678af24e939bdb6b49294b16b06af9565bef9b1)
@@ -602,6 +602,44 @@
}))
}, new MacroStabilityInwardsPreconsolidationStress[0]))
.SetName("X further than x of surfaceLine");
+
+ yield return new TestCaseData(
+ new MacroStabilityInwardsSoilProfile2D(
+ "profile",
+ new[]
+ {
+ new MacroStabilityInwardsSoilLayer2D(new Ring(new[]
+ {
+ new Point2D(0.2, 0),
+ new Point2D(0.0, 10),
+ new Point2D(0.1, 20)
+ })),
+ new MacroStabilityInwardsSoilLayer2D(new Ring(new[]
+ {
+ new Point2D(0.0, 10.0),
+ new Point2D(0.1, 20)
+ }))
+ }, new MacroStabilityInwardsPreconsolidationStress[0]))
+ .SetName("SoilLayer X start- and endpoint on right side of surfaceline");
+
+ yield return new TestCaseData(
+ new MacroStabilityInwardsSoilProfile2D(
+ "profile",
+ new[]
+ {
+ new MacroStabilityInwardsSoilLayer2D(new Ring(new[]
+ {
+ new Point2D(0.1, 20),
+ new Point2D(0.2, 10),
+ new Point2D(0.0, 10)
+ })),
+ new MacroStabilityInwardsSoilLayer2D(new Ring(new[]
+ {
+ new Point2D(0.0, 10.0),
+ new Point2D(0.1, 20)
+ }))
+ }, new MacroStabilityInwardsPreconsolidationStress[0]))
+ .SetName("SoilLayer X start- and endpoint on left side of surfaceline");
}
}
}
\ No newline at end of file