Index: DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/LineHelper.cs =================================================================== diff -u -r4000 -r4052 --- DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/LineHelper.cs (.../LineHelper.cs) (revision 4000) +++ DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/LineHelper.cs (.../LineHelper.cs) (revision 4052) @@ -23,156 +23,155 @@ using System.Collections.Generic; using System.Linq; -namespace Deltares.DamEngine.Data.Geometry +namespace Deltares.DamEngine.Data.Geometry; + +/// +/// Helper class for Line objects +/// +public static class LineHelper { /// - /// Helper class for Line objects + /// Calculate intersection between two lines (strict interpolation) /// - public static class LineHelper + /// + /// + /// + /// + public static bool GetStrictIntersectionPoint(Line line1, Line line2, ref GeometryPoint intersectPoint) { - /// - /// Calculate intersection between two lines (strict interpolation) - /// - /// - /// - /// - /// - public static bool GetStrictIntersectionPoint(Line line1, Line line2, ref GeometryPoint intersectPoint) - { - var point1 = new Point2D(line1.BeginPoint.X, line1.BeginPoint.Z); - var point2 = new Point2D(line1.EndPoint.X, line1.EndPoint.Z); - var point3 = new Point2D(line2.BeginPoint.X, line2.BeginPoint.Z); - var point4 = new Point2D(line2.EndPoint.X, line2.EndPoint.Z); + var point1 = new Point2D(line1.BeginPoint.X, line1.BeginPoint.Z); + var point2 = new Point2D(line1.EndPoint.X, line1.EndPoint.Z); + var point3 = new Point2D(line2.BeginPoint.X, line2.BeginPoint.Z); + var point4 = new Point2D(line2.EndPoint.X, line2.EndPoint.Z); - Point2D ip; - LineIntersection res = Routines2D.DetermineIf2DLinesIntersectStrickly(point1, point2, point3, - point4, out ip); - if (ip != null) - { - intersectPoint.X = ip.X; - intersectPoint.Z = ip.Z; - } - - return res == LineIntersection.Intersects; + Point2D ip; + LineIntersection res = Routines2D.DetermineIf2DLinesIntersectStrickly(point1, point2, point3, + point4, out ip); + if (ip != null) + { + intersectPoint.X = ip.X; + intersectPoint.Z = ip.Z; } - /// - /// This method uses constant extrapolation from the start point to the negative X direction and - /// from the end point to the positive X direction. Then the method tries to find intersection - /// points with the circle on that line. - /// - /// Circle's middle point X value - /// Circle's middle point Z value - /// Circle's radius - /// Point collection which defines a line. Extrapolation is performed at the start and end points. - /// Intersections of this line extrapolated to the negative and positive X with the circle. - public static List ExtendedSurfaceIntersectionPointsWithCircle(double xMid, double zMid, double radius, IList pointss) + return res == LineIntersection.Intersects; + } + + /// + /// This method uses constant extrapolation from the start point to the negative X direction and + /// from the end point to the positive X direction. Then the method tries to find intersection + /// points with the circle on that line. + /// + /// Circle's middle point X value + /// Circle's middle point Z value + /// Circle's radius + /// Point collection which defines a line. Extrapolation is performed at the start and end points. + /// Intersections of this line extrapolated to the negative and positive X with the circle. + public static List ExtendedSurfaceIntersectionPointsWithCircle(double xMid, double zMid, double radius, IList pointss) + { + List points = pointss.Where(p => !double.IsNaN(p.X)).ToList(); + if (points.Count >= 2) { - List points = pointss.Where(p => !double.IsNaN(p.X)).ToList(); - if (points.Count >= 2) + double requiredMinSurfacePointX = xMid - radius; + double requiredMaxSurfacePointX = xMid + radius; + if (requiredMinSurfacePointX < points[0].X) { - double requiredMinSurfacePointX = xMid - radius; - double requiredMaxSurfacePointX = xMid + radius; - if (requiredMinSurfacePointX < points[0].X) + points.Insert(0, new Point2D { - points.Insert(0, new Point2D - { - X = requiredMinSurfacePointX, - Z = points[0].Z - }); - } + X = requiredMinSurfacePointX, + Z = points[0].Z + }); + } - if (requiredMaxSurfacePointX > points[points.Count - 1].X) + if (requiredMaxSurfacePointX > points[points.Count - 1].X) + { + points.Insert(points.Count, new Point2D { - points.Insert(points.Count, new Point2D - { - X = requiredMaxSurfacePointX, - Z = points[points.Count - 1].Z - }); - } + X = requiredMaxSurfacePointX, + Z = points[points.Count - 1].Z + }); } - - return IntersectionPointsWithCircle(xMid, zMid, radius, points); } - /// - /// Intersections the points with circle. - /// - /// The x mid. - /// The z mid. - /// The radius. - /// The points. - /// - public static List IntersectionPointsWithCircle(double xMid, double zMid, double radius, IList points) + return IntersectionPointsWithCircle(xMid, zMid, radius, points); + } + + /// + /// Intersections the points with circle. + /// + /// The x mid. + /// The z mid. + /// The radius. + /// The points. + /// + public static List IntersectionPointsWithCircle(double xMid, double zMid, double radius, IList points) + { + var result = new List(); + if (points.Count >= 2) { - var result = new List(); - if (points.Count >= 2) + for (var pointIndex = 0; pointIndex < points.Count - 1; pointIndex++) { - for (var pointIndex = 0; pointIndex < points.Count - 1; pointIndex++) + Point2D start = points[pointIndex]; + Point2D end = points[pointIndex + 1]; + bool outOfReach = ((Math.Max(start.X, end.X) < xMid - radius) || + (Math.Min(start.X, end.X) > xMid + radius) || + (Math.Max(start.Z, end.Z) < zMid - radius) || + (Math.Min(start.Z, end.Z) > zMid + radius)); + if (!outOfReach) { - Point2D start = points[pointIndex]; - Point2D end = points[pointIndex + 1]; - bool outOfReach = ((Math.Max(start.X, end.X) < xMid - radius) || - (Math.Min(start.X, end.X) > xMid + radius) || - (Math.Max(start.Z, end.Z) < zMid - radius) || - (Math.Min(start.Z, end.Z) > zMid + radius)); - if (!outOfReach) + var line = new Line { - var line = new Line - { - BeginPoint = start, - EndPoint = end - }; - result.AddRange(Intersect_Circle_line(xMid, zMid, radius, line)); - } + BeginPoint = start, + EndPoint = end + }; + result.AddRange(Intersect_Circle_line(xMid, zMid, radius, line)); } } - - return result; } - public static GeometryPoint GetIntersectionPointWithExtrapolation(GeometryPoint p1, GeometryPoint p2, GeometryPoint p3, GeometryPoint p4) - { - return IntersectionPointWithExtrapolation(p1, p2, p3, p4); - } + return result; + } - /// - /// Intersects the circle line. - /// - /// The xm. - /// The ym. - /// The r. - /// The line. - /// - private static List Intersect_Circle_line(double xm, double ym, double r, Line line) - { - return Routines2D.IntersectCircleline(xm, ym, r, line.BeginPoint.X, line.EndPoint.X, line.BeginPoint.Z, line.EndPoint.Z); - } + public static GeometryPoint GetIntersectionPointWithExtrapolation(GeometryPoint p1, GeometryPoint p2, GeometryPoint p3, GeometryPoint p4) + { + return IntersectionPointWithExtrapolation(p1, p2, p3, p4); + } - /// - /// Determines the intersection point of two lines, allowing the intersection point being extrapolated. - /// - /// - /// - /// - /// - /// Intersection point or null (parallel lines) - private static GeometryPoint IntersectionPointWithExtrapolation(GeometryPoint p1, GeometryPoint p2, GeometryPoint p3, GeometryPoint p4) - { - GeometryPoint intersectPoint = null; + /// + /// Intersects the circle line. + /// + /// The xm. + /// The ym. + /// The r. + /// The line. + /// + private static List Intersect_Circle_line(double xm, double ym, double r, Line line) + { + return Routines2D.IntersectCircleline(xm, ym, r, line.BeginPoint.X, line.EndPoint.X, line.BeginPoint.Z, line.EndPoint.Z); + } - var point1 = new Point2D(p1.X, p1.Z); - var point2 = new Point2D(p2.X, p2.Z); - var point3 = new Point2D(p3.X, p3.Z); - var point4 = new Point2D(p4.X, p4.Z); + /// + /// Determines the intersection point of two lines, allowing the intersection point being extrapolated. + /// + /// + /// + /// + /// + /// Intersection point or null (parallel lines) + private static GeometryPoint IntersectionPointWithExtrapolation(GeometryPoint p1, GeometryPoint p2, GeometryPoint p3, GeometryPoint p4) + { + GeometryPoint intersectPoint = null; - Routines2D.DetermineIf2DLinesIntersectWithExtrapolation(point1, point2, point3, point4, out Point2D ip); - if (ip != null) - { - intersectPoint = new GeometryPoint(ip.X, ip.Z); - } + var point1 = new Point2D(p1.X, p1.Z); + var point2 = new Point2D(p2.X, p2.Z); + var point3 = new Point2D(p3.X, p3.Z); + var point4 = new Point2D(p4.X, p4.Z); - return intersectPoint; + Routines2D.DetermineIf2DLinesIntersectWithExtrapolation(point1, point2, point3, point4, out Point2D ip); + if (ip != null) + { + intersectPoint = new GeometryPoint(ip.X, ip.Z); } + + return intersectPoint; } } \ No newline at end of file