Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/Builders/SoilLayer2D.cs =================================================================== diff -u -r069921ae1e06e13d8e5e19dd9caa5e8f7b9e1f35 -r72802865521b0ddd696ff95ab01573feb4bd0cb0 --- Ringtoets/Piping/src/Ringtoets.Piping.IO/Builders/SoilLayer2D.cs (.../SoilLayer2D.cs) (revision 069921ae1e06e13d8e5e19dd9caa5e8f7b9e1f35) +++ Ringtoets/Piping/src/Ringtoets.Piping.IO/Builders/SoilLayer2D.cs (.../SoilLayer2D.cs) (revision 72802865521b0ddd696ff95ab01573feb4bd0cb0) @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; +using System.Linq.Expressions; using Ringtoets.Piping.Data; using Ringtoets.Piping.IO.Calculation; using Ringtoets.Piping.IO.Properties; @@ -105,11 +106,11 @@ var result = new Collection(); if (OuterLoop != null) { - Collection outerLoopIntersectionHeights = GetLoopIntersectionHeights(outerLoop, atX); + IEnumerable outerLoopIntersectionHeights = GetLoopIntersectionHeights(outerLoop, atX); - if (outerLoopIntersectionHeights.Count > 0) + if (outerLoopIntersectionHeights.Any()) { - IEnumerable> innerLoopsIntersectionHeights = InnerLoops.Select(loop => GetLoopIntersectionHeights(loop, atX)); + IEnumerable> innerLoopsIntersectionHeights = InnerLoops.Select(loop => GetLoopIntersectionHeights(loop, atX)); IEnumerable> innerLoopIntersectionHeightPairs = GetOrderedStartAndEndPairsIn1D(innerLoopsIntersectionHeights).ToList(); IEnumerable> outerLoopIntersectionHeightPairs = GetOrderedStartAndEndPairsIn1D(outerLoopIntersectionHeights).ToList(); @@ -185,7 +186,7 @@ return height < tuple.Item2 && height >= tuple.Item1; } - private IEnumerable> GetOrderedStartAndEndPairsIn1D(IEnumerable> innerLoopsIntersectionPoints) + private IEnumerable> GetOrderedStartAndEndPairsIn1D(IEnumerable> innerLoopsIntersectionPoints) { Collection> result = new Collection>(); foreach (var innerLoopIntersectionPoints in innerLoopsIntersectionPoints) @@ -221,47 +222,20 @@ /// intersects the vertical line at . /// Thrown when a segment is vertical at and thus /// no deterministic intersection points can be determined. - private Collection GetLoopIntersectionHeights(IEnumerable loop, double atX) + private IEnumerable GetLoopIntersectionHeights(IEnumerable loop, double atX) { - var intersectionPointY = new Collection(); - - foreach (Segment2D segment in loop.Where(s => s.ContainsX(atX))) + var segment2Ds = loop.ToArray(); + if(segment2Ds.Any(segment => IsVerticalAtX(segment, atX))) { - if (segment.IsVertical()) - { - throw new SoilLayer2DConversionException(String.Format(Resources.Error_Can_not_determine_1D_profile_with_vertical_segments_at_x, atX)); - } - - Point2D intersectionPoint = GetSegmentIntersectionAtX(segment, atX); - - if (intersectionPoint != null) - { - intersectionPointY.Add(intersectionPoint.Y); - } + var message = string.Format(Resources.Error_Can_not_determine_1D_profile_with_vertical_segments_at_x, atX); + throw new SoilLayer2DConversionException(message); } - - return intersectionPointY; + return Math2D.SegmentsIntersectionWithVerticalLine(segment2Ds, atX).Select(p => p.Y); } - private Point2D GetSegmentIntersectionAtX(Segment2D segment, double x) + private static bool IsVerticalAtX(Segment2D segment, double atX) { - var verticalLineFirstPoint = new Point2D - { - X = x, Y = 0 - }; - var verticalLineSecondPoint = new Point2D - { - X = x, Y = 1 - }; - - try - { - return Math2D.LineIntersectionWithLine(segment.FirstPoint, segment.SecondPoint, verticalLineFirstPoint, verticalLineSecondPoint); - } - catch (ArgumentException) - { - return null; - } + return segment.FirstPoint.X.Equals(atX) && segment.IsVertical(); } } } \ No newline at end of file