Index: DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometrySurface.cs =================================================================== diff -u -r5111 -r5493 --- DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometrySurface.cs (.../GeometrySurface.cs) (revision 5111) +++ DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometrySurface.cs (.../GeometrySurface.cs) (revision 5493) @@ -22,7 +22,6 @@ using System; using System.Collections.Generic; using System.Linq; -using Deltares.DamEngine.Data.Standard; namespace Deltares.DamEngine.Data.Geometry; @@ -35,9 +34,6 @@ { private GeometryLoop outerLoop = new GeometryLoop(); - private readonly List previousInnerLoops = new List(); - private GeometryLoop previousOuterLoop = new GeometryLoop(); - /// /// Empty constructor /// @@ -66,33 +62,35 @@ outerLoop = value; } } - + /// + /// All internal loops encompassed by . + /// + public List InnerLoops { get; } = new List(); + + /// + /// Placeholder for the previous outer loop. + /// + public GeometryLoop PreviousOuterLoop { get; private set; } = new GeometryLoop(); + + public List PreviousInnerLoops { get; } = new List(); + + /// /// Sets the outer loop to loop whilst storing the "old" value as previousOuterLoop. /// /// public void SetOuterLoop(GeometryLoop loop) { if (loop == OuterLoop) + { return; - previousOuterLoop = OuterLoop; + } + + PreviousOuterLoop = OuterLoop; OuterLoop = loop; } - - /// - /// All internal loops encompassed by . - /// - public List InnerLoops { get; } = new List(); /// - /// Placeholder for the previous outer loop. - /// - public GeometryLoop PreviousOuterLoop => this.previousOuterLoop; - - - public List PreviousInnerLoops => this.previousInnerLoops; - - /// /// Add to if it isn't already /// in that collection. /// @@ -103,16 +101,19 @@ InnerLoops.Add(aLoop); } } - + /// /// Remove all inner loops from the surface whilst updating the previous inner loops list. /// public void RemoveAllInnerLoops() { - previousInnerLoops.Clear(); + PreviousInnerLoops.Clear(); if (InnerLoops.Count <= 0) + { return; - previousInnerLoops.AddRange((IEnumerable) InnerLoops); + } + + PreviousInnerLoops.AddRange(InnerLoops); InnerLoops.Clear(); } @@ -135,6 +136,20 @@ } /// + /// Creates a clone of the geometry surface + /// + /// The cloned GeometrySurface + public GeometrySurface Clone() + { + // Only clone the name, the outer loop and the inner loops are not to be cloned here! + var clonedGeometrySurface = new GeometrySurface + { + Name = Name + }; + return clonedGeometrySurface; + } + + /// /// Gets the geometry bounds. /// /// @@ -149,7 +164,6 @@ /// private GeometryPointString DetermineTopCurves() { - //TODO: Lot of similar code to DetermineBottomCurves; Refactoring recommended. IEnumerable minXPoints = OuterLoop.GetPointsAtX(OuterLoop.GetMinX()); IEnumerable maxXPoints = OuterLoop.GetPointsAtX(OuterLoop.GetMaxX()); @@ -163,21 +177,8 @@ int currentIndex = OuterLoop.CalcPoints.IndexOf(startTopPoint); - while (!topPoints.CalcPoints.Contains(endTopPoint)) - { - topPoints.CalcPoints.Add(OuterLoop.CalcPoints[currentIndex++]); - if (currentIndex >= OuterLoop.CalcPoints.Count) - { - currentIndex = 0; - } - } + FillTopOrBottomPoints(topPoints, endTopPoint, currentIndex); - // Replace the points by clones - for (var i = 0; i < topPoints.CalcPoints.Count; i++) - { - topPoints.CalcPoints[i] = new Point2D(topPoints.CalcPoints[i].X, topPoints.CalcPoints[i].Z); - } - return topPoints; } @@ -187,7 +188,6 @@ /// private GeometryPointString DetermineBottomCurves() { - //TODO: Lot of similar code to DetermineTopCurves; Refactoring recommended. //create copy, leave original IEnumerable minXPoints = OuterLoop.GetPointsAtX(OuterLoop.GetMinX()); IEnumerable maxXPoints = OuterLoop.GetPointsAtX(OuterLoop.GetMaxX()); @@ -202,38 +202,28 @@ int currentIndex = OuterLoop.CalcPoints.IndexOf(endBottomPoint); - while (!bottomPoints.CalcPoints.Contains(startBottomPoint)) + FillTopOrBottomPoints(bottomPoints, startBottomPoint, currentIndex); + + // As the curves are sorted clockwise, the bottomcurves are always orientated from right to left + // while this result of this method must be from left to right so reverse the curves + bottomPoints.CalcPoints.Reverse(); + return bottomPoints; + } + + private void FillTopOrBottomPoints(GeometryPointString linePoints, Point2D endPoint, int currentIndex) + { + while (!linePoints.CalcPoints.Contains(endPoint)) { - bottomPoints.CalcPoints.Add(OuterLoop.CalcPoints[currentIndex++]); + linePoints.CalcPoints.Add(OuterLoop.CalcPoints[currentIndex++]); if (currentIndex >= OuterLoop.CalcPoints.Count) { currentIndex = 0; } } - - // Replace the points by clones - for (var i = 0; i < bottomPoints.CalcPoints.Count; i++) + + for (var i = 0; i < linePoints.CalcPoints.Count; i++) { - bottomPoints.CalcPoints[i] = new Point2D(bottomPoints.CalcPoints[i].X, bottomPoints.CalcPoints[i].Z); + linePoints.CalcPoints[i] = new Point2D(linePoints.CalcPoints[i].X, linePoints.CalcPoints[i].Z); } - - // As the curves are sorted clockwise, the bottomcurves are always orientated from right to left - // while this result of this method must be from left to right so reverse the curves - bottomPoints.CalcPoints.Reverse(); - return bottomPoints; } - - /// - /// Creates a clone of the geometry surface - /// - /// The cloned GeometrySurface - public GeometrySurface Clone() - { - // Only clone the name, the outer loop and the inner loops are not to be cloned here! - var clonedGeometrySurface = new GeometrySurface - { - Name = Name - }; - return clonedGeometrySurface; - } } \ No newline at end of file