Index: Core/Common/src/Core.Common.Base/Geometry/Math2D.cs
===================================================================
diff -u -r1b4f4720632f9a691837fa97e777a4637b6739c8 -re09cea5c0eb01dd5dcfe438bd191fb5166924ff0
--- Core/Common/src/Core.Common.Base/Geometry/Math2D.cs (.../Math2D.cs) (revision 1b4f4720632f9a691837fa97e777a4637b6739c8)
+++ Core/Common/src/Core.Common.Base/Geometry/Math2D.cs (.../Math2D.cs) (revision e09cea5c0eb01dd5dcfe438bd191fb5166924ff0)
@@ -23,6 +23,7 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
+
using Core.Common.Base.Properties;
using MathNet.Numerics.LinearAlgebra;
@@ -119,55 +120,24 @@
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);
}
///
- /// Determines the intersection points between multiple segments.
- ///
- /// A of .
- /// Another of which may or may not intersect with the from .
- /// A of intersection points.
- public static IEnumerable SegmentsIntersectionsWithSegments(IEnumerable segments, IEnumerable segmentsToCompare)
- {
- return segments.SelectMany(segment => segmentsToCompare, SegmentIntersectionWithSegment).Where(intersection => intersection != null).Distinct().ToList();
- }
-
- ///
- /// Determines the intersection points between two segments.
- ///
- /// A segment.
- /// Another segment which may or may not intersect with the from .
- /// A intersection point, or null when there is no intersection.
- public static Point2D SegmentIntersectionWithSegment(Segment2D segment1, Segment2D segment2)
- {
- if (AreEqualPoints(segment1.FirstPoint, segment1.SecondPoint))
- {
- return segment1.FirstPoint;
- }
- if (AreEqualPoints(segment1.SecondPoint, segment2.FirstPoint))
- {
- return segment1.SecondPoint;
- }
-
- return GetIntersectionPoint(segment1, segment2);
- }
-
- ///
/// Determines if two points are equal.
///
/// The first point.
@@ -367,7 +337,6 @@
Segment2DIntersectSegment2DResult.CreateIntersectionResult(segment1.FirstPoint) :
Segment2DIntersectSegment2DResult.CreateNoIntersectResult();
}
-
}
return IsPointInCollinearSegment(segment2.FirstPoint, segment1) ?
@@ -401,25 +370,25 @@
/// based on method intersect2D_2Segments.
private static Point2D GetIntersectionPoint(Segment2D segment1, Segment2D segment2)
{
- var aLine = (segment1.FirstPoint.Y - segment2.FirstPoint.Y)*(segment2.SecondPoint.X - segment2.FirstPoint.X) - (segment1.FirstPoint.X - segment2.FirstPoint.X)*(segment2.SecondPoint.Y - segment2.FirstPoint.Y);
- var bLine = (segment1.SecondPoint.X - segment1.FirstPoint.X)*(segment2.SecondPoint.Y - segment2.FirstPoint.Y) - (segment1.SecondPoint.Y - segment1.FirstPoint.Y)*(segment2.SecondPoint.X - segment2.FirstPoint.X);
+ var aLine = (segment1.FirstPoint.Y - segment2.FirstPoint.Y) * (segment2.SecondPoint.X - segment2.FirstPoint.X) - (segment1.FirstPoint.X - segment2.FirstPoint.X) * (segment2.SecondPoint.Y - segment2.FirstPoint.Y);
+ var bLine = (segment1.SecondPoint.X - segment1.FirstPoint.X) * (segment2.SecondPoint.Y - segment2.FirstPoint.Y) - (segment1.SecondPoint.Y - segment1.FirstPoint.Y) * (segment2.SecondPoint.X - segment2.FirstPoint.X);
if (Math.Abs(bLine) < epsilonForComparisons)
{
return null;
}
- var intersectionPoint = aLine/bLine;
+ var intersectionPoint = aLine / bLine;
- var cLine = (segment1.FirstPoint.Y - segment2.FirstPoint.Y)*(segment1.SecondPoint.X - segment1.FirstPoint.X) - (segment1.FirstPoint.X - segment2.FirstPoint.X)*(segment1.SecondPoint.Y - segment1.FirstPoint.Y);
- var dLine = cLine/bLine;
+ var cLine = (segment1.FirstPoint.Y - segment2.FirstPoint.Y) * (segment1.SecondPoint.X - segment1.FirstPoint.X) - (segment1.FirstPoint.X - segment2.FirstPoint.X) * (segment1.SecondPoint.Y - segment1.FirstPoint.Y);
+ var dLine = cLine / bLine;
if (intersectionPoint >= 0 && intersectionPoint <= 1 && dLine >= 0 && dLine <= 1)
{
return new Point2D
(
- segment1.FirstPoint.X + intersectionPoint*(segment1.SecondPoint.X - segment1.FirstPoint.X),
- segment1.FirstPoint.Y + intersectionPoint*(segment1.SecondPoint.Y - segment1.FirstPoint.Y)
+ segment1.FirstPoint.X + intersectionPoint * (segment1.SecondPoint.X - segment1.FirstPoint.X),
+ segment1.FirstPoint.Y + intersectionPoint * (segment1.SecondPoint.Y - segment1.FirstPoint.Y)
);
}
return null;
@@ -510,7 +479,7 @@
private static Point2D GetInterpolatedPoint(Segment2D lineSegment, double splitDistance)
{
- var interpolationFactor = splitDistance/lineSegment.Length;
+ var interpolationFactor = splitDistance / lineSegment.Length;
Vector segmentVector = lineSegment.SecondPoint - lineSegment.FirstPoint;
return lineSegment.FirstPoint + segmentVector.Multiply(interpolationFactor);
}
Index: Core/Common/test/Core.Common.Base.Test/Geometry/Math2DTest.cs
===================================================================
diff -u -r433502e631a189c9cd4358cb8984d7d3473fb694 -re09cea5c0eb01dd5dcfe438bd191fb5166924ff0
--- Core/Common/test/Core.Common.Base.Test/Geometry/Math2DTest.cs (.../Math2DTest.cs) (revision 433502e631a189c9cd4358cb8984d7d3473fb694)
+++ Core/Common/test/Core.Common.Base.Test/Geometry/Math2DTest.cs (.../Math2DTest.cs) (revision e09cea5c0eb01dd5dcfe438bd191fb5166924ff0)
@@ -61,34 +61,6 @@
}
///
- /// Test cases for intersecting segments. The contains pairs of ,
- /// which represent the coordinate of a point. Each pair of coordinates form a segment.
- /// The last 2 point2D values are the expected intersection points.
- ///
- private static IEnumerable MultipleIntersectingSegments()
- {
- // _|_
- // / | \
- // \_|_/
- var testCaseDatadata1 = new TestCaseData(new[]
- {
- new Point2D(1.0, 0.0),
- new Point2D(0.0, 1.0),
- new Point2D(1.0, 2.0),
- new Point2D(3.0, 2.0),
- new Point2D(4.0, 1.0),
- new Point2D(3.0, 0.0),
- new Point2D(1.0, 0.0),
- new Point2D(2.0, 0.0),
- new Point2D(2.0, 2.0),
- new Point2D(2.0, 0.0),
- new Point2D(2.0, 2.0)
- }, "MultipleIntersectingSegments 1");
- yield return testCaseDatadata1;
-
- }
-
- ///
/// Test cases for parallel segments. The contains pairs of ,
/// which represent the coordinate of a point. Each pair of coordinates form a segment.
///
@@ -415,161 +387,6 @@
}
[Test]
- [TestCaseSource("IntersectingSegments")]
- public void SingleSegmentIntersectionWithSingleSegment_DifferentLineSegmentsWithIntersections_ReturnsPoint(Point2D[] points, string testname = "")
- {
- // Call
- var result = Math2D.SegmentIntersectionWithSegment(new Segment2D(points[0], points[1]), new Segment2D(points[2], points[3]));
-
- // Assert
- Assert.AreEqual(points[4], result);
- }
-
- [Test]
- [TestCaseSource("ParallelSegments")]
- // String testname was added because the Teamcity report only counts the unique signatures that were tested
- public void SingleSegmentIntersectionWithSingleSegment_DifferentParallelLineSegments_ReturnsPointWhenConnectedOtherwiseNull(Point2D[] points, string testname = "")
- {
- // Call
- var result = Math2D.SegmentIntersectionWithSegment(new Segment2D(points[0], points[1]), new Segment2D(points[2], points[3]));
-
- // Assert
- if (Math2D.AreEqualPoints(points[1], points[2]))
- {
- Assert.AreEqual(points[1], result);
- }
- else
- {
- Assert.IsNull(result);
- }
- }
-
- [Test]
- [TestCaseSource("NonIntersectingSegments")]
- public void SegmentIntersectionWithSegment_DifferentLineSegmentsWithNoIntersection_ReturnsNull(Point2D[] points)
- {
- // Call
- var result = Math2D.SegmentIntersectionWithSegment(new Segment2D(points[0], points[1]), new Segment2D(points[2], points[3]));
-
- // Assert
- Assert.IsNull(result);
- }
-
- [Test]
- public void SingleSegmentIntersectionWithSingleSegment_InterSectionsHigherUpX_ReturnsNull()
- {
- // Setup
- var y1 = 5.925;
- var y2 = 5.890;
- var start = 133;
-
- // Call
- var result = Math2D.SegmentIntersectionWithSegment(new Segment2D(new Point2D(start, y1), new Point2D(start + 1, y2)), new Segment2D(new Point2D(start + 0.5, 0), new Point2D(start + 0.5, 1)));
-
- // Assert
- Assert.IsNull(result);
- }
-
- [Test]
- [TestCaseSource("MultipleIntersectingSegments")]
- public void SegmentsIntersectionsWithSegments_DifferentLinesWithMultipleIntersections_ReturnsMultiplePoints(Point2D[] points, string testname = "")
- {
- // Setup
- var segments = Math2D.ConvertLinePointsToLineSegments(new List
- {
- points[0], points[1], points[2], points[3], points[4], points[5], points[6]
- });
-
- var lineSegments = Math2D.ConvertLinePointsToLineSegments(new List
- {
- points[7], points[8]
- });
-
- // Call
- var result = Math2D.SegmentsIntersectionsWithSegments(segments, lineSegments).ToArray();
-
- // Assert
- Assert.AreEqual(2, result.Length);
- Assert.AreEqual(points[9], result[1]);
- Assert.AreEqual(points[10], result[0]);
- }
-
- [Test]
- [TestCaseSource("IntersectingSegments")]
- public void SegmentsIntersectionsWithSegments_DifferentLineSegmentsWithIntersections_ReturnsPoint(Point2D[] points, string testname = "")
- {
- // Call
- var result = Math2D.SegmentsIntersectionsWithSegments(new List {new Segment2D(points[0], points[1])}, new List {new Segment2D(points[2], points[3])});
-
- // Assert
- CollectionAssert.AreEquivalent(new [] {points[4]}, result);
- }
-
- [Test]
- [TestCaseSource("ParallelSegments")]
- // String testname was added because the Teamcity report only counts the unique signatures that were tested
- public void SegmentsIntersectionsWithSegments_DifferentParallelLineSegments_ReturnsPointWhenConnectedOtherwiseEmptyList(Point2D[] points, string testname = "")
- {
- // Call
- var result = Math2D.SegmentsIntersectionsWithSegments(new List { new Segment2D(points[0], points[1]) }, new List { new Segment2D(points[2], points[3]) });
-
- // Assert
- if (Math2D.AreEqualPoints(points[1], points[2]))
- {
- CollectionAssert.AreEquivalent(new [] {points[1]}, result);
- }
- else
- {
- CollectionAssert.IsEmpty(result);
- }
- }
-
- [Test]
- [TestCaseSource("NonIntersectingSegments")]
- public void SegmentsIntersectionsWithSegments_DifferentLineSegmentsWithNoIntersection_ReturnsEmtpyList(Point2D[] points)
- {
- // Call
- var result = Math2D.SegmentsIntersectionsWithSegments(new List { new Segment2D(points[0], points[1]) }, new List { new Segment2D(points[2], points[3]) });
-
- // Assert
- CollectionAssert.IsEmpty(result);
- }
-
- [Test]
- public void SegmentsIntersectionsWithSegments_WithEqualPoints_ReturnsMultiplePoints()
- {
- // Setup
- var segments1 = new List
- {
- new Segment2D(new Point2D(0, 0), new Point2D(0, 0)), new Segment2D(new Point2D(1, 0), new Point2D(0, 1))
- };
- var segments2 = new List
- {
- new Segment2D(new Point2D(0, 1), new Point2D(0, 0)), new Segment2D(new Point2D(1, 1), new Point2D(1, 1))
- };
- // Call
- var result = Math2D.SegmentsIntersectionsWithSegments(segments1, segments2);
-
- // Assert
- CollectionAssert.AreEquivalent(new[] { new Point2D(0, 0), new Point2D(0, 1) }, result);
- }
-
- [Test]
- public void SegmentsIntersectionsWithSegments_InterSectionsHigherUpX_ReturnsEmptyList()
- {
- // Setup
- var y1 = 5.925;
- var y2 = 5.890;
- var start = 133;
-
- // Call
- var result = Math2D.SegmentsIntersectionsWithSegments(new List {new Segment2D(new Point2D(start, y1), new Point2D(start + 1, y2))}, new List {new Segment2D(new Point2D(start + 0.5, 0), new Point2D(start + 0.5, 1))});
-
- // Assert
- CollectionAssert.IsEmpty(result);
- }
-
- [Test]
[TestCase(1234.56789)]
[TestCase(1e-6)]
[TestCase(-1e-6)]
@@ -1003,6 +820,145 @@
}
[Test]
+ public void GetIntersectionBetweenSegments_SegmentsArePointsOnTopOfEachOther_ReturnIntersection(
+ [Random(-9876.54321, 1234.56789, 1)]double x,
+ [Random(-123456.789, 98765.4321, 1)]double y)
+ {
+ // Setup
+ var segment1 = new Segment2D(new Point2D(x, y), new Point2D(x, y));
+ var segment2 = new Segment2D(new Point2D(x, y), new Point2D(x, y));
+
+ // Call
+ Segment2DIntersectSegment2DResult result = Math2D.GetIntersectionBetweenSegments(segment1, segment2);
+
+ // Assert
+ Assert.AreEqual(Intersection2DType.Intersects, result.IntersectionType);
+ CollectionAssert.AreEqual(new[]{ new Point2D(x, y) }, result.IntersectionPoints);
+ }
+
+ [Test]
+ public void GetIntersectionBetweenSegments_SegmentsArePointsNotOnTopOfEachOther_ReturnNoIntersection()
+ {
+ // Setup
+ const double x1 = 1.1;
+ const double y1 = 2.2;
+ const double x2 = 3.3;
+ const double y2 = 4.4;
+ var segment1 = new Segment2D(new Point2D(x1, y1), new Point2D(x1, y1));
+ var segment2 = new Segment2D(new Point2D(x2, y2), new Point2D(x2, y2));
+
+ // Call
+ Segment2DIntersectSegment2DResult result = Math2D.GetIntersectionBetweenSegments(segment1, segment2);
+
+ // Assert
+ Assert.AreEqual(Intersection2DType.NoIntersections, result.IntersectionType);
+ CollectionAssert.IsEmpty(result.IntersectionPoints);
+ }
+
+ [Test]
+ [TestCase(true)]
+ [TestCase(false)]
+ public void GetIntersectionBetweenSegments_SegmentWithPointSegmentOnIt_ReturnIntersection(
+ bool firstSegmentIsPointDegenerate)
+ {
+ // Setup
+ Func getY = x => 1.2 * x + 3.4;
+
+ const double x1 = 1.1;
+ const double x2 = 5.5;
+ var lineSegment = new Segment2D(new Point2D(x1, getY(x1)), new Point2D(x2, getY(x2)));
+ const double x3 = 3.3;
+ var point = new Point2D(x3, getY(x3));
+ var pointSegment = new Segment2D(point, point);
+
+ Segment2D segment1, segment2;
+ if (firstSegmentIsPointDegenerate)
+ {
+ segment1 = pointSegment;
+ segment2 = lineSegment;
+ }
+ else
+ {
+ segment1 = lineSegment;
+ segment2 = pointSegment;
+ }
+
+ // Call
+ Segment2DIntersectSegment2DResult result = Math2D.GetIntersectionBetweenSegments(segment1, segment2);
+
+ // Assert
+ Assert.AreEqual(Intersection2DType.Intersects, result.IntersectionType);
+ CollectionAssert.AreEqual(new[]{ point }, result.IntersectionPoints);
+ }
+
+ [Test]
+ [TestCase(true)]
+ [TestCase(false)]
+ public void GetIntersectionBetweenSegments_VerticalSegmentWithPointSegmentOnIt_ReturnIntersection(
+ bool firstSegmentIsPointDegenerate)
+ {
+ // Setup
+ const double x = 1.1;
+ var lineSegment = new Segment2D(new Point2D(x, 1.0), new Point2D(x, 3.0));
+ var point = new Point2D(x, 2.0);
+ var pointSegment = new Segment2D(point, point);
+
+ Segment2D segment1, segment2;
+ if (firstSegmentIsPointDegenerate)
+ {
+ segment1 = pointSegment;
+ segment2 = lineSegment;
+ }
+ else
+ {
+ segment1 = lineSegment;
+ segment2 = pointSegment;
+ }
+
+ // Call
+ Segment2DIntersectSegment2DResult result = Math2D.GetIntersectionBetweenSegments(segment1, segment2);
+
+ // Assert
+ Assert.AreEqual(Intersection2DType.Intersects, result.IntersectionType);
+ CollectionAssert.AreEqual(new[] { point }, result.IntersectionPoints);
+ }
+
+ [Test]
+ [TestCase(true)]
+ [TestCase(false)]
+ public void GetIntersectionBetweenSegments_SegmentAndSeparatePointSegment_ReturnNoIntersection(
+ bool firstSegmentIsPointDegenerate)
+ {
+ // Setup
+ Func getY = x => -5.6 * x + 7.8;
+
+ const double x1 = 1.1;
+ const double x2 = 5.5;
+ var lineSegment = new Segment2D(new Point2D(x1, getY(x1)), new Point2D(x2, getY(x2)));
+ var point = new Point2D(0.0, 0.0);
+ var pointSegment = new Segment2D(point, point);
+
+ Segment2D segment1, segment2;
+ if (firstSegmentIsPointDegenerate)
+ {
+ segment1 = pointSegment;
+ segment2 = lineSegment;
+ }
+ else
+ {
+ segment1 = lineSegment;
+ segment2 = pointSegment;
+ }
+
+ // Call
+ Segment2DIntersectSegment2DResult result = Math2D.GetIntersectionBetweenSegments(segment1, segment2);
+
+ // Assert
+ Assert.AreEqual(Intersection2DType.NoIntersections, result.IntersectionType);
+ CollectionAssert.IsEmpty(result.IntersectionPoints);
+ }
+
+ [Test]
public void AreEqualPoints_PointsEqual_ReturnsTrue()
{
// Call
Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/PipingSurfaceLinesCsvImporter.cs
===================================================================
diff -u -rd82fa09fe9ae053ce7702ba89ef23ae029640d1b -re09cea5c0eb01dd5dcfe438bd191fb5166924ff0
--- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/PipingSurfaceLinesCsvImporter.cs (.../PipingSurfaceLinesCsvImporter.cs) (revision d82fa09fe9ae053ce7702ba89ef23ae029640d1b)
+++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/PipingSurfaceLinesCsvImporter.cs (.../PipingSurfaceLinesCsvImporter.cs) (revision e09cea5c0eb01dd5dcfe438bd191fb5166924ff0)
@@ -24,15 +24,19 @@
using System.Drawing;
using System.IO;
using System.Linq;
+
using Core.Common.Base.Geometry;
using Core.Common.Base.IO;
using Core.Common.IO.Exceptions;
using Core.Common.IO.Readers;
+
using log4net;
+
using Ringtoets.Common.Data;
using Ringtoets.Piping.Forms.PresentationObjects;
using Ringtoets.Piping.IO.SurfaceLines;
using Ringtoets.Piping.Primitives;
+
using PipingFormsResources = Ringtoets.Piping.Forms.Properties.Resources;
using PipingDataResources = Ringtoets.Piping.Data.Properties.Resources;
using RingtoetsFormsResources = Ringtoets.Common.Forms.Properties.Resources;
@@ -47,6 +51,13 @@
///
public class PipingSurfaceLinesCsvImporter : FileImporterBase
{
+ private enum ReferenceLineIntersectionsResult
+ {
+ NoIntersections,
+ OneIntersection,
+ MultipleIntersectionsOrOverlap
+ }
+
private const string characteristicPointsFileSubExtension = ".krp";
private const string csvFileExtension = ".csv";
private readonly ILog log = LogManager.GetLogger(typeof(PipingSurfaceLinesCsvImporter));
@@ -99,7 +110,7 @@
return false;
}
- var surfaceLinesContext = (RingtoetsPipingSurfaceLinesContext) targetItem;
+ var surfaceLinesContext = (RingtoetsPipingSurfaceLinesContext)targetItem;
var importSurfaceLinesResult = ReadPipingSurfaceLines(filePath);
if (importSurfaceLinesResult.CriticalErrorOccurred)
@@ -132,7 +143,7 @@
private static bool IsReferenceLineAvailable(object targetItem)
{
- return ((RingtoetsPipingSurfaceLinesContext) targetItem).AssessmentSection.ReferenceLine != null;
+ return ((RingtoetsPipingSurfaceLinesContext)targetItem).AssessmentSection.ReferenceLine != null;
}
private ReadResult HandleCriticalReadError(Exception e)
@@ -184,30 +195,57 @@
private bool CheckReferenceLineInterSections(RingtoetsPipingSurfaceLine readSurfaceLine, ReferenceLine referenceLine)
{
- var surfaceLineSegments = Math2D.ConvertLinePointsToLineSegments(readSurfaceLine.Points.Select(p => new Point2D(p.X, p.Y)));
- var referenceLineSegments = Math2D.ConvertLinePointsToLineSegments(referenceLine.Points);
+ ReferenceLineIntersectionsResult result = GetReferenceLineIntersections(referenceLine, readSurfaceLine);
- var intersections = Math2D.SegmentsIntersectionsWithSegments(referenceLineSegments, surfaceLineSegments).ToList();
-
- if (intersections.Count == 1)
+ if (result == ReferenceLineIntersectionsResult.NoIntersections)
{
- return true;
- }
-
- if (intersections.Count == 0)
- {
log.ErrorFormat(RingtoetsPluginResources.PipingSurfaceLinesCsvImporter_CheckReferenceLineInterSections_Surfaceline_0_does_not_correspond_to_current_referenceline_1_,
readSurfaceLine.Name,
RingtoetsPluginResources.PipingSurfaceLinesCsvImporter_CheckReferenceLineInterSections_This_could_be_caused_coordinates_being_local_coordinate_system);
}
- else if (intersections.Count > 1)
+ else if (result == ReferenceLineIntersectionsResult.MultipleIntersectionsOrOverlap)
{
log.ErrorFormat(RingtoetsPluginResources.PipingSurfaceLinesCsvImporter_CheckReferenceLineInterSections_Surfaceline_0_does_not_correspond_to_current_referenceline, readSurfaceLine.Name);
}
- return false;
+ return result == ReferenceLineIntersectionsResult.OneIntersection;
}
+ private static ReferenceLineIntersectionsResult GetReferenceLineIntersections(ReferenceLine referenceLine, RingtoetsPipingSurfaceLine surfaceLine)
+ {
+ var surfaceLineSegments = Math2D.ConvertLinePointsToLineSegments(surfaceLine.Points.Select(p => new Point2D(p.X, p.Y)));
+ Segment2D[] referenceLineSegments = Math2D.ConvertLinePointsToLineSegments(referenceLine.Points).ToArray();
+
+ return GetReferenceLineIntersectionsResult(surfaceLineSegments, referenceLineSegments);
+ }
+
+ private static ReferenceLineIntersectionsResult GetReferenceLineIntersectionsResult(IEnumerable surfaceLineSegments, Segment2D[] referenceLineSegments)
+ {
+ ReferenceLineIntersectionsResult intersectionResult = ReferenceLineIntersectionsResult.NoIntersections;
+ foreach (Segment2D surfaceLineSegment in surfaceLineSegments)
+ {
+ foreach (Segment2D referenceLineSegment in referenceLineSegments)
+ {
+ Segment2DIntersectSegment2DResult result = Math2D.GetIntersectionBetweenSegments(surfaceLineSegment, referenceLineSegment);
+ if (result.IntersectionType == Intersection2DType.Intersects)
+ {
+ if (intersectionResult == ReferenceLineIntersectionsResult.OneIntersection)
+ {
+ // Early exit as multiple intersections is a return result:
+ return ReferenceLineIntersectionsResult.MultipleIntersectionsOrOverlap;
+ }
+ intersectionResult = ReferenceLineIntersectionsResult.OneIntersection;
+ }
+ if (result.IntersectionType == Intersection2DType.Overlapping)
+ {
+ // Early exit as overlap is a return result:
+ return ReferenceLineIntersectionsResult.MultipleIntersectionsOrOverlap;
+ }
+ }
+ }
+ return intersectionResult;
+ }
+
private static void SetCharacteristicPointsOnSurfaceLine(RingtoetsPipingSurfaceLine readSurfaceLine, CharacteristicPoints characteristicPointsLocation)
{
readSurfaceLine.TrySetDitchPolderSide(characteristicPointsLocation.DitchPolderSide);