Index: Core/Common/src/Core.Common.Base/Geometry/Math2D.cs =================================================================== diff -u -rb79e419a1fcdf3d80760ea4bc35ac354525911d2 -r01f52f7e7b49e5353c0fe2583ad9d906a047c5b5 --- Core/Common/src/Core.Common.Base/Geometry/Math2D.cs (.../Math2D.cs) (revision b79e419a1fcdf3d80760ea4bc35ac354525911d2) +++ Core/Common/src/Core.Common.Base/Geometry/Math2D.cs (.../Math2D.cs) (revision 01f52f7e7b49e5353c0fe2583ad9d906a047c5b5) @@ -117,20 +117,20 @@ var aLine = line1Point2.Y - line1Point1.Y; var bLine = line1Point1.X - line1Point2.X; - var cLine = aLine * line1Point1.X + bLine * line1Point1.Y; + var cLine = aLine*line1Point1.X + bLine*line1Point1.Y; var aOtherLine = line2Point2.Y - line2Point1.Y; var bOtherLine = line2Point1.X - line2Point2.X; - var cOtherLine = aOtherLine * line2Point1.X + bOtherLine * line2Point1.Y; + var cOtherLine = aOtherLine*line2Point1.X + bOtherLine*line2Point1.Y; - var determinant = aLine * bOtherLine - aOtherLine * bLine; + var determinant = aLine*bOtherLine - aOtherLine*bLine; if (Math.Abs(determinant) < epsilonForComparisons) { return null; } - var x = (bOtherLine * cLine - bLine * cOtherLine) / determinant; - var y = (aLine * cOtherLine - aOtherLine * cLine) / determinant; + var x = (bOtherLine*cLine - bLine*cOtherLine)/determinant; + var y = (aLine*cOtherLine - aOtherLine*cLine)/determinant; return new Point2D(x, y); } @@ -233,6 +233,28 @@ return ConvertLinePointsToLineSegments(points); } + /// + /// Calculates the length of a line defined as a collection of . + /// + /// The points that make up a 2D line. + /// The sum of the distances between consecutive points. + public static double Length(IEnumerable points) + { + double length = 0; + Point2D previousPoint = null; + + foreach (Point2D point in points) + { + if (previousPoint != null) + { + length += previousPoint.GetEuclideanDistanceTo(point); + } + previousPoint = point; + } + + return length; + } + private static Point2D Convert3DPointTo2DPoint(Point3D point) { return new Point2D(point.X, point.Y); @@ -315,10 +337,10 @@ private static Point2D GetInterpolatedPoint(Segment2D lineSegment, double splitDistance) { - var interpolationFactor = splitDistance / lineSegment.Length; + var interpolationFactor = splitDistance/lineSegment.Length; Vector segmentVector = lineSegment.SecondPoint - lineSegment.FirstPoint; - double interpolatedX = lineSegment.FirstPoint.X + interpolationFactor * segmentVector[0]; - double interpolatedY = lineSegment.FirstPoint.Y + interpolationFactor * segmentVector[1]; + double interpolatedX = lineSegment.FirstPoint.X + interpolationFactor*segmentVector[0]; + double interpolatedY = lineSegment.FirstPoint.Y + interpolationFactor*segmentVector[1]; return new Point2D(interpolatedX, interpolatedY); } Index: Core/Common/test/Core.Common.Base.Test/Geometry/Math2DTest.cs =================================================================== diff -u -re65a7b987f40cd17a68b43e6a7f267e91588fc4b -r01f52f7e7b49e5353c0fe2583ad9d906a047c5b5 --- Core/Common/test/Core.Common.Base.Test/Geometry/Math2DTest.cs (.../Math2DTest.cs) (revision e65a7b987f40cd17a68b43e6a7f267e91588fc4b) +++ Core/Common/test/Core.Common.Base.Test/Geometry/Math2DTest.cs (.../Math2DTest.cs) (revision 01f52f7e7b49e5353c0fe2583ad9d906a047c5b5) @@ -615,5 +615,87 @@ // Assert Assert.IsFalse(result); } + + [Test] + public void Length_EmptyCollection_ReturnsZero() + { + // Setup + var points = new Point2D[0]; + + // Call + var length = Math2D.Length(points); + + // Assert + Assert.AreEqual(0, length); + } + + [Test] + public void Length_CollectionWithSinglePoint_ReturnsZero() + { + // Setup + var random = new Random(21); + var points = new [] + { + new Point2D(random.NextDouble(), random.NextDouble()), + }; + + // Call + var length = Math2D.Length(points); + + // Assert + Assert.AreEqual(0, length); + } + + [Test] + public void Length_CollectionWithTwoPoints_ReturnsDistanceBetweenPoints() + { + // Setup + var random = new Random(21); + + var point1 = new Point2D(random.NextDouble(), random.NextDouble()); + var point2 = new Point2D(random.NextDouble(), random.NextDouble()); + + var points = new[] + { + point1, + point2 + }; + + // Call + var length = Math2D.Length(points); + + // Assert + Assert.AreEqual(point2.GetEuclideanDistanceTo(point1), length); + } + + [Test] + [TestCase(3)] + [TestCase(5)] + public void Length_CollectionWithMoreThanTwoPoints_ReturnsSumOfDistanceBetweenPoints(int count) + { + // Setup + var random = new Random(21); + + var points = new List(count); + double expectedLength = 0; + Point2D previousPoint = null; + + for (int i = 0; i < count; i++) + { + var point = new Point2D(random.NextDouble(), random.NextDouble()); + if (previousPoint != null) + { + expectedLength += previousPoint.GetEuclideanDistanceTo(point); + } + points.Add(point); + previousPoint = point; + } + + // Call + var length = Math2D.Length(points); + + // Assert + Assert.AreEqual(expectedLength, length); + } } } \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Data/AssessmentSectionBase.cs =================================================================== diff -u -r0e801c8485332bd9cdd1a907619f1f93e495ba4c -r01f52f7e7b49e5353c0fe2583ad9d906a047c5b5 --- Ringtoets/Common/src/Ringtoets.Common.Data/AssessmentSectionBase.cs (.../AssessmentSectionBase.cs) (revision 0e801c8485332bd9cdd1a907619f1f93e495ba4c) +++ Ringtoets/Common/src/Ringtoets.Common.Data/AssessmentSectionBase.cs (.../AssessmentSectionBase.cs) (revision 01f52f7e7b49e5353c0fe2583ad9d906a047c5b5) @@ -50,7 +50,7 @@ /// /// Gets or sets the reference line defining the geometry of the dike assessment section. /// - public ReferenceLine ReferenceLine { get; set; } + public virtual ReferenceLine ReferenceLine { get; set; } /// /// Gets or sets the contribution of each failure mechanism available in this assessment section. Index: Ringtoets/Integration/src/Ringtoets.Integration.Data/DikeAssessmentSection.cs =================================================================== diff -u -rd1565906db90df7be4365d277d5ff22dc2d77a82 -r01f52f7e7b49e5353c0fe2583ad9d906a047c5b5 --- Ringtoets/Integration/src/Ringtoets.Integration.Data/DikeAssessmentSection.cs (.../DikeAssessmentSection.cs) (revision d1565906db90df7be4365d277d5ff22dc2d77a82) +++ Ringtoets/Integration/src/Ringtoets.Integration.Data/DikeAssessmentSection.cs (.../DikeAssessmentSection.cs) (revision 01f52f7e7b49e5353c0fe2583ad9d906a047c5b5) @@ -19,7 +19,9 @@ // 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 Ringtoets.Common.Data; using Ringtoets.Common.Data.Contribution; using Ringtoets.Integration.Data.Placeholders; @@ -80,6 +82,19 @@ FailureMechanismContribution = new FailureMechanismContribution(GetFailureMechanisms(), 30, 30000); } + public override ReferenceLine ReferenceLine + { + get + { + return base.ReferenceLine; + } + set + { + PipingFailureMechanism.GeneralInput.SectionLength = Math2D.Length(value.Points); + base.ReferenceLine = value; + } + } + /// /// Gets the "Piping" failure mechanism. /// Index: Ringtoets/Integration/test/Ringtoets.Integration.Data.Test/DikeAssessmentSectionTest.cs =================================================================== diff -u -r0e801c8485332bd9cdd1a907619f1f93e495ba4c -r01f52f7e7b49e5353c0fe2583ad9d906a047c5b5 --- Ringtoets/Integration/test/Ringtoets.Integration.Data.Test/DikeAssessmentSectionTest.cs (.../DikeAssessmentSectionTest.cs) (revision 0e801c8485332bd9cdd1a907619f1f93e495ba4c) +++ Ringtoets/Integration/test/Ringtoets.Integration.Data.Test/DikeAssessmentSectionTest.cs (.../DikeAssessmentSectionTest.cs) (revision 01f52f7e7b49e5353c0fe2583ad9d906a047c5b5) @@ -1,5 +1,8 @@ -using System.Linq; +using System; +using System.Collections.Generic; +using System.Linq; using Core.Common.Base; +using Core.Common.Base.Geometry; using NUnit.Framework; using Ringtoets.Common.Data; @@ -145,5 +148,29 @@ Assert.AreEqual(norm, contribution[9].Norm); Assert.AreEqual((norm / contribution[9].Contribution) * 100, 100000); } + + [Test] + public void ReferenceLine_SomeReferenceLine_GeneralPipingInputSectionLengthSet() + { + // Setup + var random = new Random(21); + var assessmentSection = new DikeAssessmentSection(); + ReferenceLine referenceLine = new ReferenceLine(); + + Point2D[] somePointsCollection = + { + new Point2D(random.NextDouble(), random.NextDouble()), + new Point2D(random.NextDouble(), random.NextDouble()), + new Point2D(random.NextDouble(), random.NextDouble()), + new Point2D(random.NextDouble(), random.NextDouble()) + }; + referenceLine.SetGeometry(somePointsCollection); + + // Call + assessmentSection.ReferenceLine = referenceLine; + + // Assert + Assert.AreEqual(Math2D.Length(referenceLine.Points), assessmentSection.PipingFailureMechanism.GeneralInput.SectionLength); + } } } \ No newline at end of file Index: Ringtoets/Piping/src/Ringtoets.Piping.Data/GeneralPipingInput.cs =================================================================== diff -u -r9d0bb6ba6d087fa3d615908f6d40252243ac635e -r01f52f7e7b49e5353c0fe2583ad9d906a047c5b5 --- Ringtoets/Piping/src/Ringtoets.Piping.Data/GeneralPipingInput.cs (.../GeneralPipingInput.cs) (revision 9d0bb6ba6d087fa3d615908f6d40252243ac635e) +++ Ringtoets/Piping/src/Ringtoets.Piping.Data/GeneralPipingInput.cs (.../GeneralPipingInput.cs) (revision 01f52f7e7b49e5353c0fe2583ad9d906a047c5b5) @@ -45,6 +45,7 @@ SellmeijerReductionFactor = 0.3; A = 1.0; B = 350.0; + SectionLength = double.NaN; } #region General parameters (used by multiple calculations) @@ -141,6 +142,11 @@ /// public double B { get; private set; } + /// + /// Gets or sets the length of the assessment section. + /// + public double SectionLength { get; set; } + #endregion } } \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/GeneralPipingInputTest.cs =================================================================== diff -u -r1c01ea681887e96b5b80fb7d23680a4eeac9bd50 -r01f52f7e7b49e5353c0fe2583ad9d906a047c5b5 --- Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/GeneralPipingInputTest.cs (.../GeneralPipingInputTest.cs) (revision 1c01ea681887e96b5b80fb7d23680a4eeac9bd50) +++ Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/GeneralPipingInputTest.cs (.../GeneralPipingInputTest.cs) (revision 01f52f7e7b49e5353c0fe2583ad9d906a047c5b5) @@ -29,6 +29,7 @@ Assert.AreEqual(1.0, inputParameters.A); Assert.AreEqual(350.0, inputParameters.B); + Assert.IsNaN(inputParameters.SectionLength); } } } \ No newline at end of file