Index: DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryHelper.cs =================================================================== diff -u -r6245 -r6404 --- DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryHelper.cs (.../GeometryHelper.cs) (revision 6245) +++ DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryHelper.cs (.../GeometryHelper.cs) (revision 6404) @@ -1,4 +1,4 @@ -// Copyright (C) Stichting Deltares 2024. All rights reserved. +// Copyright (C) Stichting Deltares 2025. All rights reserved. // // This file is part of the Dam Engine. // @@ -68,52 +68,6 @@ geometry.Right = toX; } - private static void AddNewPointsCurvesLoopsAndSurfacesForExtension(GeometryData geometry, double toX, Point2D[] edgePoints, - List edgeCurves) - { - var newBottomPoint = new Point2D(toX, edgePoints[0].Z); - geometry.Points.Add(newBottomPoint); - var newhorizontalCurve1 = new GeometryCurve(edgePoints[0], newBottomPoint); - geometry.Curves.Add(newhorizontalCurve1); - for (var i = 1; i < edgePoints.Length; i++) - { - if (edgePoints[i].LocationEquals(edgePoints[i - 1])) - { - continue; - } - - var newSurface = new GeometrySurface(); - - var newTopPoint = new Point2D(toX, edgePoints[i].Z); - geometry.Points.Add(newTopPoint); - var newHorizontalCurve2 = new GeometryCurve(edgePoints[i], newTopPoint); - geometry.Curves.Add(newHorizontalCurve2); - var newVerticalCurve = new GeometryCurve(newBottomPoint, newTopPoint); - geometry.Curves.Add(newVerticalCurve); - - var newLoop = new GeometryLoop(); - newLoop.CurveList.Add(newhorizontalCurve1); - newLoop.CurveList.Add(newVerticalCurve); - newHorizontalCurve2.Reverse(); - newLoop.CurveList.Add(newHorizontalCurve2); - var existingVerticalCurve = GetCurvesWithPoints(edgePoints[i], edgePoints[i - 1], edgeCurves); - newLoop.CurveList.Add(existingVerticalCurve); - if (newLoop.IsContinuous()) - { - geometry.Loops.Add(newLoop); - newSurface.OuterLoop = newLoop; - geometry.Surfaces.Add(newSurface); - } - else - { - // Should not ever happen so can not be tested. - throw new ArgumentException("The new loop is not a real continuous loop."); - } - newBottomPoint = newTopPoint; - newhorizontalCurve1 = newHorizontalCurve2; - } - } - /// /// Cuts the geometry left at the given value of x. /// @@ -122,7 +76,7 @@ public static void CutGeometryLeft(GeometryData geometry, double atX) { GeometryCurve intersectionCurve = GetIntersectionCurveAt(geometry, atX); - + // check if a curve intersects the atX, if so move point. GeometryCurve[] curves = geometry.Curves.ToArray(); var splitPoints = new List(); @@ -144,19 +98,19 @@ } } } - + // Add the vertical curves between the split points AddCurvesBetweenSplitPoints(geometry, splitPoints); - + geometry.RegenerateGeometry(); - + // Remove all surfaces left of the new limit List surfs = GetSurfacesLeftOfNewLimit(geometry, atX); foreach (GeometrySurface aSurface in surfs) { DeleteSurface(geometry, aSurface); } - + // Remove all now obsolete curves and point at the left of the new limit Point2D[] points = geometry.Points.ToArray(); for (var i = 0; i < points.Length; i++) @@ -166,6 +120,7 @@ geometry.DeletePointWithCurves(points[i]); } } + geometry.Rebox(); } @@ -177,7 +132,7 @@ public static void CutGeometryRight(GeometryData geometry, double atX) { GeometryCurve intersectionCurve = GetIntersectionCurveAt(geometry, atX); - + // check if a curve intersects the atX, if so move point. GeometryCurve[] curves = geometry.Curves.ToArray(); var splitPoints = new List(); @@ -199,10 +154,10 @@ } } } - + // Add the vertical curves between the split points AddCurvesBetweenSplitPoints(geometry, splitPoints); - + geometry.RegenerateGeometry(); // Remove all surfaces right of the new limit @@ -211,7 +166,7 @@ { DeleteSurface(geometry, aSurface); } - + // Remove all now obsolete curves and points at the right of the new limit Point2D[] points = geometry.Points.ToArray(); for (var i = 0; i < points.Length; i++) @@ -221,9 +176,77 @@ geometry.DeletePointWithCurves(points[i]); } } + geometry.Rebox(); } - + + /// + /// Check if a curve already exists in the geometry. + /// + /// + /// + /// + public static GeometryCurve DoesCurveExist(GeometryData geometry, GeometryCurve newCurve) + { + foreach (GeometryCurve curve in geometry.Curves) + { + if (curve.HeadPoint.LocationEquals(newCurve.HeadPoint) && curve.EndPoint.LocationEquals(newCurve.EndPoint) || + curve.HeadPoint.LocationEquals(newCurve.EndPoint) && curve.EndPoint.LocationEquals(newCurve.HeadPoint)) + { + return curve; + } + } + + return null; + } + + private static void AddNewPointsCurvesLoopsAndSurfacesForExtension(GeometryData geometry, double toX, Point2D[] edgePoints, + List edgeCurves) + { + var newBottomPoint = new Point2D(toX, edgePoints[0].Z); + geometry.Points.Add(newBottomPoint); + var newhorizontalCurve1 = new GeometryCurve(edgePoints[0], newBottomPoint); + geometry.Curves.Add(newhorizontalCurve1); + for (var i = 1; i < edgePoints.Length; i++) + { + if (edgePoints[i].LocationEquals(edgePoints[i - 1])) + { + continue; + } + + var newSurface = new GeometrySurface(); + + var newTopPoint = new Point2D(toX, edgePoints[i].Z); + geometry.Points.Add(newTopPoint); + var newHorizontalCurve2 = new GeometryCurve(edgePoints[i], newTopPoint); + geometry.Curves.Add(newHorizontalCurve2); + var newVerticalCurve = new GeometryCurve(newBottomPoint, newTopPoint); + geometry.Curves.Add(newVerticalCurve); + + var newLoop = new GeometryLoop(); + newLoop.CurveList.Add(newhorizontalCurve1); + newLoop.CurveList.Add(newVerticalCurve); + newHorizontalCurve2.Reverse(); + newLoop.CurveList.Add(newHorizontalCurve2); + GeometryCurve existingVerticalCurve = GetCurvesWithPoints(edgePoints[i], edgePoints[i - 1], edgeCurves); + newLoop.CurveList.Add(existingVerticalCurve); + if (newLoop.IsContinuous()) + { + geometry.Loops.Add(newLoop); + newSurface.OuterLoop = newLoop; + geometry.Surfaces.Add(newSurface); + } + else + { + // Should not ever happen so can not be tested. + throw new ArgumentException("The new loop is not a real continuous loop."); + } + + newBottomPoint = newTopPoint; + newhorizontalCurve1 = newHorizontalCurve2; + } + } + private static void AddCurvesBetweenSplitPoints(GeometryData geometry, List splitPoints) { if (splitPoints.Count > 1) @@ -246,7 +269,7 @@ private static List GetSurfacesLeftOfNewLimit(GeometryData geometry, double atX) { - List surfacesLeftOfLimits = new List(); + var surfacesLeftOfLimits = new List(); foreach (GeometrySurface surface in geometry.Surfaces) { foreach (Point2D point in (IEnumerable) surface.OuterLoop.Points) @@ -258,12 +281,13 @@ } } } + return surfacesLeftOfLimits; } - + private static List GetSurfacesRightOfNewLimit(GeometryData geometry, double atX) { - List surfacesRightOfLimits = new List(); + var surfacesRightOfLimits = new List(); foreach (GeometrySurface surface in geometry.Surfaces) { foreach (Point2D point in (IEnumerable) surface.OuterLoop.Points) @@ -275,29 +299,34 @@ } } } + return surfacesRightOfLimits; } - + private static void DeleteSurface(GeometryData geometry, GeometrySurface surface) { GeometrySurface aData = surface; GeometryLoop outerLoop = surface.OuterLoop; - List geometryCurveList = new List(); + var geometryCurveList = new List(); foreach (GeometryCurve curve in outerLoop.CurveList) { if (IsCurveAnExistingCurve(curve, aData)) + { geometryCurveList.Add(curve); + } else + { geometry.NewlyEffectedCurves.Add(curve); + } } foreach (GeometryCurve aCurve in geometryCurveList) { geometry.DeleteCurve(aCurve, true); } - geometry.Remove( outerLoop); - geometry.Remove( surface); + geometry.Remove(outerLoop); + geometry.Remove(surface); geometry.NewlyEffectedCurves.Clear(); } @@ -308,6 +337,7 @@ { return true; } + return false; } @@ -326,7 +356,6 @@ private static GeometryCurve GetCurvesWithPoints(Point2D headPoint, Point2D endPoint, List curves) { - int curveCount = curves.Count; // loop through the list of curves, check if point on line @@ -338,27 +367,12 @@ if (Routines2D.DoesPointExistInLine(curve.HeadPoint, curve.EndPoint, headPoint, GeometryConstants.Accuracy)) { if (Routines2D.DoesPointExistInLine(curve.HeadPoint, curve.EndPoint, endPoint, GeometryConstants.Accuracy)) + { return curve; + } } } + return null; } - - /// - /// Check if a curve already exists in the geometry. - /// - /// - /// - /// - public static GeometryCurve DoesCurveExist(GeometryData geometry, GeometryCurve newCurve) - { - foreach (GeometryCurve curve in geometry.Curves) - { - if (curve.HeadPoint.LocationEquals(newCurve.HeadPoint) && curve.EndPoint.LocationEquals(newCurve.EndPoint) || - curve.HeadPoint.LocationEquals(newCurve.EndPoint) && curve.EndPoint.LocationEquals(newCurve.HeadPoint)) - return curve; - } - return null; - } - } \ No newline at end of file