Index: DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryGenerator.cs =================================================================== diff -u -r6528 -r6529 --- DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryGenerator.cs (.../GeometryGenerator.cs) (revision 6528) +++ DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryGenerator.cs (.../GeometryGenerator.cs) (revision 6529) @@ -37,8 +37,6 @@ private readonly Dictionary> geometryLoopDirections = new(); - private readonly List newlyDetectedSurfaceList = new(); - /// /// Regenerates the geometry. /// @@ -56,7 +54,6 @@ RegenerateAllCurvesIntersection(); - newlyDetectedSurfaceList.Clear(); geometryLoopDirections.Clear(); int curvesCount = geometryData.Curves.Count; @@ -110,9 +107,10 @@ /// public void SetIsUsed(GeometryCurve curve, CurveDirection direction, bool isUsed) { + bool isKeyPresent = geometryCurveForwardsIsUsed.ContainsKey(curve); if (direction == CurveDirection.Forward) { - if (!(geometryCurveForwardsIsUsed.ContainsKey(curve))) + if (!isKeyPresent) { geometryCurveForwardsIsUsed.Add(curve, isUsed); } @@ -123,7 +121,7 @@ } else { - if (!(geometryCurveReversedIsUsed.ContainsKey(curve))) + if (!isKeyPresent) { geometryCurveReversedIsUsed.Add(curve, isUsed); } @@ -343,7 +341,7 @@ IdentifyAndRegisterDoublePoints(doublePoints); // replace double points in curves with originals - ReplaceDoublePointReferencesInCurves(doublePoints); + ReplaceDoublePointReferencesInAllCurves(doublePoints); // remove curves which have the same head as end point, update surfaces that use these curves RemoveInvalidCurvesAndUpdateSurfaces(); @@ -403,34 +401,44 @@ } } - private void ReplaceDoublePointReferencesInCurves(Dictionary doublePoints) + private void ReplaceDoublePointReferencesInAllCurves(Dictionary doublePoints) { foreach (Point2D doublePoint in doublePoints.Keys) { - foreach (GeometryCurve curve in geometryData.Curves) + ReplaceDoublePointReferencesInCurves(doublePoints, doublePoint); + + ReplaceDoublePointReferencesInNewlyEffectedCurves(doublePoints, doublePoint); + } + } + + private void ReplaceDoublePointReferencesInNewlyEffectedCurves(Dictionary doublePoints, Point2D doublePoint) + { + foreach (GeometryCurve curve in geometryData.NewlyEffectedCurves) + { + if (curve.HeadPoint == doublePoint) { - if (curve.HeadPoint == doublePoint) - { - curve.HeadPoint = doublePoints[doublePoint]; - } + curve.HeadPoint = doublePoints[doublePoint]; + } - if (curve.EndPoint == doublePoint) - { - curve.EndPoint = doublePoints[doublePoint]; - } + if (curve.EndPoint == doublePoint) + { + curve.EndPoint = doublePoints[doublePoint]; } + } + } - foreach (GeometryCurve curve in geometryData.NewlyEffectedCurves) + private void ReplaceDoublePointReferencesInCurves(Dictionary doublePoints, Point2D doublePoint) + { + foreach (GeometryCurve curve in geometryData.Curves) + { + if (curve.HeadPoint == doublePoint) { - if (curve.HeadPoint == doublePoint) - { - curve.HeadPoint = doublePoints[doublePoint]; - } + curve.HeadPoint = doublePoints[doublePoint]; + } - if (curve.EndPoint == doublePoint) - { - curve.EndPoint = doublePoints[doublePoint]; - } + if (curve.EndPoint == doublePoint) + { + curve.EndPoint = doublePoints[doublePoint]; } } } @@ -506,137 +514,190 @@ } // get the direction of the current curve - CurveDirection currentCurveDirection; - if (index % 2 == 0) + if (DetermineCurveDirection(index, currentCurve, out CurveDirection currentCurveDirection)) { - if (GetIsUsed(currentCurve, CurveDirection.Forward)) - { - continue; - } - - currentCurveDirection = CurveDirection.Forward; + continue; } - else - { - if (GetIsUsed(currentCurve, CurveDirection.Reverse)) - { - continue; - } - currentCurveDirection = CurveDirection.Reverse; - } - - // create aValue1 new loop + // create new loop var newLoop = new GeometryLoop(); newLoopList.Add(newLoop); - // initialise LoopBeginCurve + // initialise LoopBeginCurve/direction GeometryCurve loopBeginCurve = geometryData.Curves[curveIndex]; CurveDirection loopBeginDirection = currentCurveDirection; - while (true) - { - // set the IsUsed status - SetIsUsed(currentCurve, currentCurveDirection, true); + ProcessCurvesForLoopCompletion(currentCurve, currentCurveDirection, newLoop, attachedCurveList, curvesCount, + loopBeginCurve, loopBeginDirection); + } - // add the current curve to new loop - if (!AddCurve(currentCurve, currentCurveDirection, newLoop)) - { - // the curve wasn't added bcos the curve-direction pair was already present in loop. - // problem case - break here, else we'd get aValue1 hang! - throw new ArgumentException("DetectSurfaces: The curve could not be added to the loop"); - } + // create surfaces! + CreateSurfaces(newLoopList); + } +#if DEBUG + catch (Exception ex) + { + Debug.WriteLine(ex); + } +#else + catch (Exception) + { + throw; + } +#endif + } - Point2D curveEndPoint = currentCurve.GetEndPoint(currentCurveDirection); - attachedCurveList.Clear(); - var minAngle = 365.0; - var minIndex = 0; + private void ProcessCurvesForLoopCompletion(GeometryCurve currentCurve, CurveDirection currentCurveDirection, + GeometryLoop newLoop, List attachedCurveList, int curvesCount, + GeometryCurve loopBeginCurve, CurveDirection loopBeginDirection) + { + while (true) + { + // set the IsUsed status + SetIsUsed(currentCurve, currentCurveDirection, true); - // find all the curves that are connected to the Current Curve at curveEndPoint - for (var index2 = 0; index2 < curvesCount; index2++) - { - GeometryCurve curve = geometryData.Curves[index2]; - if (curve.LocationEquals(currentCurve)) // lets not get the reverse direction of the current curve here - { - continue; - } + // add the current curve to new loop + TryToAddCurve(currentCurve, currentCurveDirection, newLoop); - if (curve.HeadPoint == curveEndPoint) - { - attachedCurveList.Add(new DirectionCurve(curve, CurveDirection.Forward)); - } - else if (curve.EndPoint == curveEndPoint) - { - attachedCurveList.Add(new DirectionCurve(curve, CurveDirection.Reverse)); - } - } + Point2D curveEndPoint = currentCurve.GetEndPoint(currentCurveDirection); + attachedCurveList.Clear(); + var minAngle = 365.0; + var minIndex = 0; - if (attachedCurveList.Count == 0) // no curves found - { - throw new ArgumentException("DetectSurfaces: No connected Curve found"); - } + // find all the curves that are connected to the Current Curve at curveEndPoint + IdentifyAttachedCurves(curvesCount, currentCurve, curveEndPoint, attachedCurveList); - // we have aValue1 set of curves, find the one that turns right the most - if (attachedCurveList.Count > 1) - { - minIndex = -1; + EnsureAttachedCurve(attachedCurveList); - Point2D point1 = currentCurve.GetEndPoint(currentCurveDirection); - Point2D point2 = currentCurve.GetHeadPoint(currentCurveDirection); + // we have a set of curves, find the one that turns right the most + minIndex = FindConnectedCurveWithMostRightAngle(attachedCurveList, minIndex, currentCurve, currentCurveDirection, minAngle); - for (var index2 = 0; index2 < attachedCurveList.Count; index2++) - { - var point3 = new Point2D(); - var point4 = new Point2D(); + DirectionCurve pickedDirectionCurve = attachedCurveList[minIndex]; - point3.X = attachedCurveList[index2].GetHeadPoint().X; - point3.Z = attachedCurveList[index2].GetHeadPoint().Z; - point4.X = attachedCurveList[index2].GetEndPoint().X; - point4.Z = attachedCurveList[index2].GetEndPoint().Z; + if (CheckWhetherLoopIsFinished(pickedDirectionCurve, loopBeginCurve, loopBeginDirection)) + { + break; + } - double angle = Routines2D.FindAngle(point1, point2, point3, point4); + // assign the CurrentCurve from the picked one + currentCurve = pickedDirectionCurve.Curve; + currentCurveDirection = pickedDirectionCurve.Direction; + } + } - if (angle < minAngle) - { - minAngle = angle; - minIndex = index2; - } - } - } + private static bool CheckWhetherLoopIsFinished(DirectionCurve pickedDirectionCurve, GeometryCurve loopBeginCurve, + CurveDirection loopBeginDirection) + { + if (pickedDirectionCurve.Curve == loopBeginCurve && pickedDirectionCurve.Direction == loopBeginDirection) + { + return true; + } - DirectionCurve pickedDirectionCurve = attachedCurveList[minIndex]; + return false; + } - if (pickedDirectionCurve.Curve == loopBeginCurve && pickedDirectionCurve.Direction == loopBeginDirection) - { - break; - } + private static void EnsureAttachedCurve(List attachedCurveList) + { + if (attachedCurveList.Count == 0) // no curves found + { + throw new ArgumentException("DetectSurfaces: No connected Curve found"); + } + } - // assign the CurrentCurve from the picked one - currentCurve = pickedDirectionCurve.Curve; - currentCurveDirection = pickedDirectionCurve.Direction; - } + private void TryToAddCurve(GeometryCurve currentCurve, CurveDirection currentCurveDirection, GeometryLoop newLoop) + { + if (!AddCurve(currentCurve, currentCurveDirection, newLoop)) + { + // the curve wasn't added bcos the curve-direction pair was already present in loop. + // problem case - break here, else we'd get a hang! + throw new ArgumentException("DetectSurfaces: The curve could not be added to the loop"); + } + } + + private bool DetermineCurveDirection(int index, GeometryCurve currentCurve, out CurveDirection currentCurveDirection) + { + if (index % 2 == 0) + { + if (GetIsUsed(currentCurve, CurveDirection.Forward)) + { + currentCurveDirection = CurveDirection.Forward; + return true; } - // create surfaces! - CreateSurfaces(newLoopList); + currentCurveDirection = CurveDirection.Forward; } -#if DEBUG - catch (Exception ex) + else { - Debug.WriteLine(ex); + if (GetIsUsed(currentCurve, CurveDirection.Reverse)) + { + currentCurveDirection = CurveDirection.Reverse; + return true; + } + + currentCurveDirection = CurveDirection.Reverse; } -#else - catch (Exception) + + return false; + } + + private static int FindConnectedCurveWithMostRightAngle(List attachedCurveList, int minIndex, + GeometryCurve currentCurve, CurveDirection currentCurveDirection, + double minAngle) + { + if (attachedCurveList.Count > 1) { - throw; + minIndex = -1; + + Point2D point1 = currentCurve.GetEndPoint(currentCurveDirection); + Point2D point2 = currentCurve.GetHeadPoint(currentCurveDirection); + + for (var index2 = 0; index2 < attachedCurveList.Count; index2++) + { + var point3 = new Point2D(); + var point4 = new Point2D(); + + point3.X = attachedCurveList[index2].GetHeadPoint().X; + point3.Z = attachedCurveList[index2].GetHeadPoint().Z; + point4.X = attachedCurveList[index2].GetEndPoint().X; + point4.Z = attachedCurveList[index2].GetEndPoint().Z; + + double angle = Routines2D.FindAngle(point1, point2, point3, point4); + + if (angle < minAngle) + { + minAngle = angle; + minIndex = index2; + } + } } -#endif + + return minIndex; } - private void CreateSurfaces(List newLoopList) + private void IdentifyAttachedCurves(int curvesCount, GeometryCurve currentCurve, Point2D curveEndPoint, + List attachedCurveList) { - var newSurfacesGeoDtaObjectList = new List(); + for (var index2 = 0; index2 < curvesCount; index2++) + { + GeometryCurve curve = geometryData.Curves[index2]; + if (curve.LocationEquals(currentCurve)) // lets not get the reverse direction of the current curve here + { + continue; + } + if (curve.HeadPoint == curveEndPoint) + { + attachedCurveList.Add(new DirectionCurve(curve, CurveDirection.Forward)); + } + else if (curve.EndPoint == curveEndPoint) + { + attachedCurveList.Add(new DirectionCurve(curve, CurveDirection.Reverse)); + } + } + } + + private void CreateSurfaces(List newLoopList) + { int loopsCount = newLoopList.Count; int curvesCount; GeometrySurface newSurface; @@ -647,45 +708,17 @@ GeometryLoop loop = newLoopList[index]; curvesCount = loop.CurveList.Count; - if (curvesCount < 2) // dont create aValue1 surface for loops that have less than 2 curves + if (!ValidateLoopCurves(curvesCount, loop)) { continue; } - if (curvesCount == 2) // if only 2 curves in loop, make sure they are distinct (non-repeated) - { - if (loop.CurveList[0] == loop.CurveList[1]) - { - continue; - } - } - - if (!loop.IsContinuous() || !loop.HasArea()) - { - continue; - } - - // if the loop is clockwise, create aValue1 surface + // if the loop is clockwise, create a surface if (loop.IsClockWise() && !CheckIfLoopEnclosesOpenPolyline(loop)) { - // TEMP: aVector1 mechanism to remember surfaces after Geometry Regeneration - // find the surface that is most repeated in the loop's in curves - newSurface = GetReassignmentSurfaceFromCurves(loop); - - // an existing surface (in geometryLoopDirections) has been found + newSurface = CreateSurface(loop); if (newSurface != null) { - newSurface = CreateSurface(loop); - } - else // no existing surface found from its comprising curves... create aValue1 brand new surface! - { - newSurface = CreateSurface(loop); - newlyDetectedSurfaceList.Add(newSurface); // populate the newly detected surface list - newSurfacesGeoDtaObjectList.Add(newSurface); - } - - if (newSurface != null) - { newSurfaceList.Add(newSurface); AssignSurfaceAtLeftOrRightToCurves(newSurface); } @@ -711,6 +744,29 @@ } } + private static bool ValidateLoopCurves(int curvesCount, GeometryLoop loop) + { + if (curvesCount < 2) // dont create a surface for loops that have less than 2 curves + { + return false; + } + + if (curvesCount == 2) // if only 2 curves in loop, make sure they are distinct (non-repeated) + { + if (loop.CurveList[0] == loop.CurveList[1]) + { + return false; + } + } + + if (!loop.IsContinuous() || !loop.HasArea()) + { + return false; + } + + return true; + } + /// /// Checks if loop encloses open polyline. /// @@ -753,70 +809,6 @@ return true; } - private GeometrySurface GetReassignmentSurfaceFromCurves(GeometryLoop loop) - { - GeometrySurface surface = null; - GeometrySurface reassignmentSurface = null; - int curvesCount = loop.CurveList.Count; - - if (!geometryLoopDirections.ContainsKey(loop)) - { - return null; - } - - for (var index = 0; index < curvesCount; index++) - { - GeometryCurve curve = loop.CurveList[index]; - if (geometryLoopDirections[loop][index] == CurveDirection.Forward) - { - if (curve.SurfaceAtRight != null) - { - surface = curve.SurfaceAtRight; - } - } - else - { - if (curve.SurfaceAtLeft != null) - { - surface = curve.SurfaceAtLeft; - } - } - - if (surface == null) - { - continue; - } - - var maxTimesSurfacesFound = 0; - var noTimesSurfaceFound = 0; - for (var index1 = 0; index1 < curvesCount; index1++) - { - if (geometryLoopDirections[loop][index] == CurveDirection.Forward) - { - if (curve.SurfaceAtRight == surface) - { - noTimesSurfaceFound++; - } - } - else - { - if (curve.SurfaceAtLeft == surface) - { - noTimesSurfaceFound++; - } - } - } - - if (noTimesSurfaceFound > maxTimesSurfacesFound) - { - maxTimesSurfacesFound = noTimesSurfaceFound; - reassignmentSurface = surface; - } - } - - return reassignmentSurface; - } - /// /// Assigns the surface at left or right to its curves on the outerloop. This tells at which side of the curve the surface is present. /// So after this, for each curve in the outerloop of this surface, it is known at which side the surface is located. @@ -956,56 +948,71 @@ var innerPointCount = 0; var outerPointCount = 0; - var isOnPointCount = 0; var hasOnPointCount = 0; GeometryLoop loop = geometryData.Surfaces[index].OuterLoop; List polygon = loop.Points; int existingLoopPointCount = polygon.Count; - // check if it is an inner loop - for (var innerIndex = 0; innerIndex < newPointCount; innerIndex++) - { - PointInPolygon location = Routines2D.CheckIfPointIsInPolygon(loop, newPolygon[innerIndex].X, newPolygon[innerIndex].Z); + // check if newloop is an inner loop within the existing loop + innerPointCount = CheckIfNewLoopIsInnerLoopOfGivenLoop(newPointCount, loop, newPolygon, innerPointCount); - if (location == PointInPolygon.InsidePolygon) - { - innerPointCount++; - } - else if (location == PointInPolygon.OnPolygonEdge) - { - isOnPointCount++; - } - } + // check if existing loop is an inner loop to the new loop, making the newloop an outerloop for that. + outerPointCount = CheckIfLoopIsInnerLoopOfNewLoop(existingLoopPointCount, newLoop, polygon, outerPointCount, + ref hasOnPointCount); - // check if it has an inner loop - for (var innerIndex1 = 0; innerIndex1 < existingLoopPointCount; innerIndex1++) - { - PointInPolygon location = Routines2D.CheckIfPointIsInPolygon(newLoop, polygon[innerIndex1].X, polygon[innerIndex1].Z); - - if (location == PointInPolygon.InsidePolygon) - { - outerPointCount++; - } - else if (location == PointInPolygon.OnPolygonEdge) - { - hasOnPointCount++; - } - } - //Add New Loop as inner loop to the existing Surface if (innerPointCount == newPointCount) { geometryData.Surfaces[index].AddInnerLoop(newLoop); } //Add Inner Loop to the New Surface - if ((outerPointCount == existingLoopPointCount) || ((outerPointCount > 0) && (existingLoopPointCount == (outerPointCount + hasOnPointCount)))) + if ((outerPointCount == existingLoopPointCount) || ((outerPointCount > 0) && (existingLoopPointCount == + (outerPointCount + hasOnPointCount)))) { newSurface.AddInnerLoop(loop); } } } + private static int CheckIfLoopIsInnerLoopOfNewLoop(int existingLoopPointCount, GeometryLoop newLoop, List polygon, + int outerPointCount, ref int hasOnPointCount) + { + for (var innerIndex1 = 0; innerIndex1 < existingLoopPointCount; innerIndex1++) + { + PointInPolygon location = Routines2D.CheckIfPointIsInPolygon(newLoop, polygon[innerIndex1].X, + polygon[innerIndex1].Z); + + if (location == PointInPolygon.InsidePolygon) + { + outerPointCount++; + } + else if (location == PointInPolygon.OnPolygonEdge) + { + hasOnPointCount++; + } + } + + return outerPointCount; + } + + private static int CheckIfNewLoopIsInnerLoopOfGivenLoop(int newPointCount, GeometryLoop loop, List newPolygon, + int innerPointCount) + { + for (var innerIndex = 0; innerIndex < newPointCount; innerIndex++) + { + PointInPolygon location = Routines2D.CheckIfPointIsInPolygon(loop, newPolygon[innerIndex].X, + newPolygon[innerIndex].Z); + + if (location == PointInPolygon.InsidePolygon) + { + innerPointCount++; + } + } + + return innerPointCount; + } + /// /// Regenerates all the curves that have intersections. /// Find all intersections between curves and split them at the intersection points, adding curves where needed. @@ -1025,7 +1032,8 @@ { foreach (GeometryCurve geometryCurve2 in geometryData.Curves.ToArray()) { - isCurveInserted = FindAndProcessCurveIntersections(geometryCurve1, geometryCurve2, isCurveInserted, ref hasCurveBeenSplit); + isCurveInserted = FindAndProcessCurveIntersections(geometryCurve1, geometryCurve2, isCurveInserted, + ref hasCurveBeenSplit); } } EnsureCorrectGeometry(); @@ -1044,21 +1052,28 @@ Point2D geometryCurve2EndPoint = geometryCurve2.EndPoint; if (!geometryCurve1.LocationEquals(geometryCurve2) && !RegenerateParallelCurves(geometryCurve2, geometryCurve1, ref isCurveInserted) && - Routines2D.DetermineIf2DLinesIntersectStrickly(geometryCurve1HeadPoint, geometryCurve1EndPoint, geometryCurve2HeadPoint, geometryCurve2EndPoint, out Point2D intersectionPoint) == - LineIntersection.Intersects) + Routines2D.DetermineIf2DLinesIntersectStrickly(geometryCurve1HeadPoint, geometryCurve1EndPoint, + geometryCurve2HeadPoint, geometryCurve2EndPoint, + out Point2D intersectionPoint) == LineIntersection.Intersects) { - if (!Routines2D.DetermineIfPointsCoincide(geometryCurve1HeadPoint.X, geometryCurve1HeadPoint.Z, intersectionPoint.X, intersectionPoint.Z, 0.001) - && !Routines2D.DetermineIfPointsCoincide(geometryCurve1EndPoint.X, geometryCurve1EndPoint.Z, intersectionPoint.X, intersectionPoint.Z, 0.001)) + if (!Routines2D.DetermineIfPointsCoincide(geometryCurve1HeadPoint.X, geometryCurve1HeadPoint.Z, intersectionPoint.X, + intersectionPoint.Z, 0.001) + && !Routines2D.DetermineIfPointsCoincide(geometryCurve1EndPoint.X, geometryCurve1EndPoint.Z, intersectionPoint.X, + intersectionPoint.Z, 0.001)) { - Point2D point = geometryData.CreatePointAndAddItToTheProperListsWhenNeeded(new Point2D(intersectionPoint.X, intersectionPoint.Z)); + Point2D point = geometryData.CreatePointAndAddItToTheProperListsWhenNeeded(new Point2D(intersectionPoint.X, + intersectionPoint.Z)); SplitCurve(geometryCurve1, point); hasCurveBeenSplit = true; } - if (!Routines2D.DetermineIfPointsCoincide(geometryCurve2HeadPoint.X, geometryCurve2HeadPoint.Z, intersectionPoint.X, intersectionPoint.Z, 0.001) && - !Routines2D.DetermineIfPointsCoincide(geometryCurve2EndPoint.X, geometryCurve2EndPoint.Z, intersectionPoint.X, intersectionPoint.Z, 0.001)) + if (!Routines2D.DetermineIfPointsCoincide(geometryCurve2HeadPoint.X, geometryCurve2HeadPoint.Z, intersectionPoint.X, + intersectionPoint.Z, 0.001) && + !Routines2D.DetermineIfPointsCoincide(geometryCurve2EndPoint.X, geometryCurve2EndPoint.Z, intersectionPoint.X, + intersectionPoint.Z, 0.001)) { - Point2D point = geometryData.CreatePointAndAddItToTheProperListsWhenNeeded(new Point2D(intersectionPoint.X, intersectionPoint.Z)); + Point2D point = geometryData.CreatePointAndAddItToTheProperListsWhenNeeded(new Point2D(intersectionPoint.X, + intersectionPoint.Z)); SplitCurve(geometryCurve2, point); hasCurveBeenSplit = true; } @@ -1087,7 +1102,8 @@ { aConnectedAtHeadCurveList.Clear(); aConnectedAtEndCurveList.Clear(); - DetermineConnectedCurves(geometryData.Points[index1], ref aConnectedAtHeadCurveList, ref aConnectedAtEndCurveList); + DetermineConnectedCurves(geometryData.Points[index1], ref aConnectedAtHeadCurveList, + ref aConnectedAtEndCurveList); AssignPointToCurves(aConnectedAtHeadCurveList, geometryData.Points[index2], true); AssignPointToCurves(aConnectedAtEndCurveList, geometryData.Points[index2], false); --count; @@ -1115,14 +1131,16 @@ bool isPoint1OnLine2, bool isPoint2OnLine2, bool isPoint1SameAsPoint3, bool isPoint2SameAsPoint4, bool isPoint2SameAsPoint3, bool isPoint1SameAsPoint4) { - GeometryCurve newLine; // p3----p1------p2----p4 if (isPoint1OnLine2 && isPoint2OnLine2 && !isPoint1SameAsPoint3 && !isPoint2SameAsPoint4 && !isPoint2SameAsPoint3 && !isPoint1SameAsPoint4) { - double distance1 = Routines2D.Compute2DDistance(line2.HeadPoint.X, line2.HeadPoint.Z, line1.HeadPoint.X, line1.HeadPoint.Z); - double distance2 = Routines2D.Compute2DDistance(line2.HeadPoint.X, line2.HeadPoint.Z, line1.EndPoint.X, line1.EndPoint.Z); + double distance1 = Routines2D.Compute2DDistance(line2.HeadPoint.X, line2.HeadPoint.Z, line1.HeadPoint.X, + line1.HeadPoint.Z); + double distance2 = Routines2D.Compute2DDistance(line2.HeadPoint.X, line2.HeadPoint.Z, line1.EndPoint.X, + line1.EndPoint.Z); + GeometryCurve newLine; if (distance1 < distance2) { newLine = SplitCurve(line2, line1.HeadPoint); @@ -1145,7 +1163,6 @@ bool isPoint3OnLine1, bool isPoint4OnLine1, bool isPoint1SameAsPoint3, bool isPoint2SameAsPoint4, bool isPoint2SameAsPoint3, bool isPoint1SameAsPoint4) { - GeometryCurve newLine; // p1----p3------p4----p2 if (isPoint3OnLine1 && isPoint4OnLine1 && !isPoint1SameAsPoint3 && !isPoint2SameAsPoint4 && !isPoint2SameAsPoint3 && !isPoint1SameAsPoint4) @@ -1155,6 +1172,7 @@ double distance2 = Routines2D.Compute2DDistance(line1.HeadPoint.X, line1.HeadPoint.Z, line2.EndPoint.X, line2.EndPoint.Z); + GeometryCurve newLine; if (distance1 < distance2) { newLine = SplitCurve(line1, line2.HeadPoint); @@ -1359,7 +1377,8 @@ private void DeleteInvalidAndDuplicateCurves() { - List curvesToDelete = geometryData.Curves.Where((Func) (curve => curve.HeadPoint == curve.EndPoint)).ToList(); + List curvesToDelete = geometryData.Curves.Where((Func) + (curve => curve.HeadPoint == curve.EndPoint)).ToList(); foreach (GeometryCurve aCurve in curvesToDelete) { geometryData.DeleteCurve(aCurve, true); @@ -1388,7 +1407,7 @@ #region Nested type: DirectionCurve - internal struct DirectionCurve + private readonly struct DirectionCurve { internal DirectionCurve(GeometryCurve aCurve, CurveDirection aDirection) {