Index: DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryGenerator.cs =================================================================== diff -u -r5217 -r5218 --- DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryGenerator.cs (.../GeometryGenerator.cs) (revision 5217) +++ DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryGenerator.cs (.../GeometryGenerator.cs) (revision 5218) @@ -1049,16 +1049,21 @@ bool flag2 = Routines2D.DoesPointExistInLine(headPoint1, endPoint1, endPoint2, 0.001); bool flag3 = Routines2D.DoesPointExistInLine(headPoint2, endPoint2, headPoint1, 0.001); bool flag4 = Routines2D.DoesPointExistInLine(headPoint2, endPoint2, endPoint1, 0.001); - double num1 = !headPoint1.Z.IsNearEqual(endPoint1.Z) ? (headPoint1.X - endPoint1.X) / (headPoint1.Z - endPoint1.Z) : double.MaxValue; - double num2 = !headPoint2.Z.IsNearEqual(endPoint2.Z) ? (headPoint2.X - endPoint2.X) / (headPoint2.Z - endPoint2.Z) : double.MaxValue; - if (Math.Abs(Math.Abs(num1) - Math.Abs(num2)) > 5E-12) + double slope1 = !headPoint1.Z.IsNearEqual(endPoint1.Z) ? (headPoint1.X - endPoint1.X) / (headPoint1.Z - endPoint1.Z) : double.MaxValue; + double slope2 = !headPoint2.Z.IsNearEqual(endPoint2.Z) ? (headPoint2.X - endPoint2.X) / (headPoint2.Z - endPoint2.Z) : double.MaxValue; + if (Math.Abs(Math.Abs(slope1) - Math.Abs(slope2)) > 5E-12) { + // The lines are not parallel if (flag1 && flag2) { + // When both headPoint2 and endPoint2 are (almost) on line1, then flag point that is closest to line1 + // When the distance is the same, flag endPoint2 DetermineFlagValuesWithDistanceToLine(headPoint2, endPoint2, headPoint1, endPoint1, ref flag1, ref flag2); } if (flag3 && flag4) { + // When both headPoint1 and endPoint1 are (almost) on line2, then flag point that is closest to line2 + // When the distance is the same, flag endPoint1 DetermineFlagValuesWithDistanceToLine(headPoint1, endPoint1, headPoint2, endPoint2, ref flag3, ref flag4); } } @@ -1067,14 +1072,19 @@ bool flag6 = Routines2D.DetermineIfPointsCoincide(headPoint1.X, headPoint1.Z, endPoint2.X, endPoint2.Z, 0.001); bool flag7 = Routines2D.DetermineIfPointsCoincide(endPoint1.X, endPoint1.Z, headPoint2.X, headPoint2.Z, 0.001); bool flag8 = Routines2D.DetermineIfPointsCoincide(endPoint1.X, endPoint1.Z, endPoint2.X, endPoint2.Z, 0.001); - if (Math.Abs(Math.Abs(num1) - Math.Abs(num2)) > 5E-12) + if (Math.Abs(Math.Abs(slope1) - Math.Abs(slope2)) > 5E-12) { + // The lines are not parallel if (flag5 && flag7) { + // When both headPoint1 and endPoint1 (almost) coincide with headPoint2, then flag point that is closest to headPoint2 + // When the distance is the same, flag endPoint1 DetermineFlagValuesWithDistanceBetweenPoints(headPoint1, endPoint1, headPoint2, ref flag5, ref flag7); } if (flag6 && flag8) { + // When both headPoint1 and endPoint1 (almost) coincide with endPoint2, then flag point that is closest to endPoint2 + // When the distance is the same, flag endPoint1 DetermineFlagValuesWithDistanceBetweenPoints(headPoint1, endPoint1, endPoint2, ref flag6, ref flag8); } } @@ -1179,13 +1189,13 @@ flagB = false; } - private static void DetermineFlagValuesWithDistanceToLine(Point2D point1, Point2D point2, Point2D headPoint, Point2D endPoint, + private static void DetermineFlagValuesWithDistanceToLine(Point2D point1, Point2D point2, Point2D linePoint1, Point2D linePoint2, ref bool flagA, ref bool flagB) { double distancePoint1ToLine = Routines2D.CalculateDistanceToLine(point1.X, point1.Z, - headPoint.X, headPoint.Z, endPoint.X, endPoint.Z); + linePoint1.X, linePoint1.Z, linePoint2.X, linePoint2.Z); double distancePoint2ToLine = Routines2D.CalculateDistanceToLine(point2.X, point2.Z, - headPoint.X, headPoint.Z, endPoint.X, endPoint.Z); + linePoint1.X, linePoint1.Z, linePoint2.X, linePoint2.Z); if (distancePoint1ToLine > distancePoint2ToLine) flagA = false; else