Index: Ringtoets/Integration/src/Ringtoets.Integration.IO/Factories/ExportableAssessmentSectionFactory.cs =================================================================== diff -u -rf95e168752ab9e77c5521fa68c25cf86e653dbf0 -r66b39e30bcc260749e86dd91aeddc1bcb57cb01e --- Ringtoets/Integration/src/Ringtoets.Integration.IO/Factories/ExportableAssessmentSectionFactory.cs (.../ExportableAssessmentSectionFactory.cs) (revision f95e168752ab9e77c5521fa68c25cf86e653dbf0) +++ Ringtoets/Integration/src/Ringtoets.Integration.IO/Factories/ExportableAssessmentSectionFactory.cs (.../ExportableAssessmentSectionFactory.cs) (revision 66b39e30bcc260749e86dd91aeddc1bcb57cb01e) @@ -58,7 +58,7 @@ throw new ArgumentException("reference line of assessment section cannot be null."); } - return new ExportableAssessmentSection(assessmentSection.Name, + return new ExportableAssessmentSection(assessmentSection.Name, assessmentSection.Id, assessmentSection.ReferenceLine.Points, CreateExportableAssessmentSectionAssemblyResult(assessmentSection), Index: Ringtoets/Integration/src/Ringtoets.Integration.IO/Factories/ExportableCombinedSectionAssemblyCollectionFactory.cs =================================================================== diff -u -r82832b737256f4fb806ccbb1e601b63cc8dfa86c -r66b39e30bcc260749e86dd91aeddc1bcb57cb01e --- Ringtoets/Integration/src/Ringtoets.Integration.IO/Factories/ExportableCombinedSectionAssemblyCollectionFactory.cs (.../ExportableCombinedSectionAssemblyCollectionFactory.cs) (revision 82832b737256f4fb806ccbb1e601b63cc8dfa86c) +++ Ringtoets/Integration/src/Ringtoets.Integration.IO/Factories/ExportableCombinedSectionAssemblyCollectionFactory.cs (.../ExportableCombinedSectionAssemblyCollectionFactory.cs) (revision 66b39e30bcc260749e86dd91aeddc1bcb57cb01e) @@ -21,8 +21,6 @@ using System; using System.Collections.Generic; -using System.Linq; -using Core.Common.Base.Geometry; using Ringtoets.AssemblyTool.Data; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Integration.Data.Assembly; Index: Ringtoets/Integration/src/Ringtoets.Integration.IO/Helpers/ExportableFailureMechanismSectionHelper.cs =================================================================== diff -u -r548b7cecd2ac4a239dd218c1e675a2c6f2bf4a6d -r66b39e30bcc260749e86dd91aeddc1bcb57cb01e --- Ringtoets/Integration/src/Ringtoets.Integration.IO/Helpers/ExportableFailureMechanismSectionHelper.cs (.../ExportableFailureMechanismSectionHelper.cs) (revision 548b7cecd2ac4a239dd218c1e675a2c6f2bf4a6d) +++ Ringtoets/Integration/src/Ringtoets.Integration.IO/Helpers/ExportableFailureMechanismSectionHelper.cs (.../ExportableFailureMechanismSectionHelper.cs) (revision 66b39e30bcc260749e86dd91aeddc1bcb57cb01e) @@ -73,9 +73,9 @@ /// of the , and . /// /// The reference line to get the geometry from. - /// The start of the section from the beginning of the reference line in meters. - /// The end of the section from the beginning of the reference line in meters. - /// A geometry based on the reference line and the section start and end. + /// The start of the section relative to the start of the reference line in meters. + /// The end of the section relative to the start of the reference line in meters. + /// The failure mechanism section geometry. /// Thrown when is null. public static IEnumerable GetFailureMechanismSectionGeometry(ReferenceLine referenceLine, double sectionStart, double sectionEnd) { @@ -84,55 +84,34 @@ throw new ArgumentNullException(nameof(referenceLine)); } - int index; + int startIndex; + int endIndex; + Point2D[] referenceLinePoints = referenceLine.Points.ToArray(); - Point2D startPoint = GetStartPoint(referenceLinePoints, sectionStart, out index); + Point2D startPoint = GetPointByOffset(referenceLinePoints, sectionStart, out startIndex); + Point2D endPoint = GetPointByOffset(referenceLinePoints, sectionEnd, out endIndex); + var sectionPoints = new List { startPoint }; - double sectionLength = sectionEnd - sectionStart; - double sectionLengthOnReferenceLine = 0; - Point2D lastPoint = startPoint; + sectionPoints.AddRange(referenceLinePoints.Skip(startIndex + 1).Take(endIndex - startIndex)); - foreach (Point2D point in referenceLinePoints.Skip(index + 1)) + if (!sectionPoints.Contains(endPoint)) { - double pointsLength = Math2D.Length(new[] - { - lastPoint, - point - }); - - sectionLengthOnReferenceLine += pointsLength; - - if (sectionLength > sectionLengthOnReferenceLine) - { - sectionPoints.Add(point); - lastPoint = point; - } - else if (Math.Abs(sectionLength - sectionLengthOnReferenceLine) < 1e-6) - { - sectionPoints.Add(point); - break; - } - else if (sectionLength < sectionLengthOnReferenceLine) - { - double distance = pointsLength - (sectionLengthOnReferenceLine - sectionLength); - sectionPoints.Add(InterpolatePoint(lastPoint, point, distance)); - break; - } + sectionPoints.Add(endPoint); } return sectionPoints; } - private static Point2D GetStartPoint(Point2D[] referenceLinePoints, double sectionStart, out int index) + private static Point2D GetPointByOffset(Point2D[] referenceLinePoints, double offset, out int index) { index = 0; - Point2D startPoint = null; + Point2D point = null; - if (Math.Abs(sectionStart) < 1e-6) + if (Math.Abs(offset) < 1e-6) { return referenceLinePoints[0]; } @@ -150,29 +129,36 @@ totalLength += pointsLength; - if (Math.Abs(totalLength - sectionStart) < 1e-6) + if (Math.Abs(totalLength - offset) < 1e-6) { - startPoint = referenceLinePoints[i]; + point = referenceLinePoints[i]; break; } - if (totalLength > sectionStart) + if (totalLength > offset) { - double distance = sectionStart - (totalLength - pointsLength); - startPoint = InterpolatePoint(referenceLinePoints[i - 1], referenceLinePoints[i], distance); + double distance = offset - (totalLength - pointsLength); + point = InterpolatePoint(referenceLinePoints[i - 1], referenceLinePoints[i], distance); index = i - 1; break; } } - return startPoint; + return point; } private static Point2D InterpolatePoint(Point2D startPoint, Point2D endPoint, double distance) { - double magnitude = Math.Sqrt(Math.Pow(endPoint.Y - startPoint.Y, 2) + Math.Pow(endPoint.X - startPoint.X, 2)); - return new Point2D(startPoint.X + (distance * ((endPoint.X - startPoint.X) / magnitude)), - startPoint.Y + (distance * ((endPoint.Y - startPoint.Y) / magnitude))); + double magnitude = Math2D.Length(new[] + { + startPoint, + endPoint + }); + + double factor = distance / magnitude; + + return new Point2D(startPoint.X + (factor * (endPoint.X - startPoint.X)), + startPoint.Y + (factor * (endPoint.Y - startPoint.Y))); } } } \ No newline at end of file