Index: DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryData.cs =================================================================== diff -u -r5527 -r5541 --- DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryData.cs (.../GeometryData.cs) (revision 5527) +++ DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryData.cs (.../GeometryData.cs) (revision 5541) @@ -247,21 +247,23 @@ } /// - /// Deletes the point and the curves it belongs too. + /// Deletes the point and the curves it belongs too when curves are 0------point------0. /// - /// - public void DeletePoint(Point2D aPoint) + /// + public void DeletePointAndPossibleObsoleteCurveItsPartOf(Point2D point) { var source = new List(); if (Curves.Count > 0) { - source.AddRange(Curves.Where((Func) (c => c.HeadPoint == aPoint || c.EndPoint == aPoint))); + // Check if TWO curves are in line with each other and the point is on both curves. + // If so, the point is not needed and can be removed from the curves too. + source.AddRange(Curves.Where((Func) (c => c.HeadPoint == point || c.EndPoint == point))); if (source.Count == 2) { - CheckForCurvesWherePointIsOnBothConnectedCurvesInLineWithEachOther(aPoint, source); + CheckForCurvesWherePointIsOnBothConnectedCurvesInLineWithEachOtherAndFixThem(point, source); } - Remove(aPoint); + Remove(point); foreach (GeometryCurve aCurve in source) { @@ -271,20 +273,20 @@ return; } - Remove(aPoint); + Remove(point); } /// /// Creates a curve between the two points if no such curve already exists. /// - /// - /// + /// + /// /// - public GeometryCurve CreateCurve(Point2D aPoint1, Point2D aPoint2) + public GeometryCurve CreateCurve(Point2D point1, Point2D point2) { foreach (GeometryCurve curve in Curves) { - if (curve.HeadPoint == aPoint1 && curve.EndPoint == aPoint2 || curve.HeadPoint == aPoint2 && curve.EndPoint == aPoint1) + if (curve.HeadPoint == point1 && curve.EndPoint == point2 || curve.HeadPoint == point2 && curve.EndPoint == point1) { return curve; } @@ -293,8 +295,8 @@ var curve1 = new GeometryCurve(); geometryGenerator.SetIsUsed(curve1, CurveDirection.Forward, false); geometryGenerator.SetIsUsed(curve1, CurveDirection.Reverse, false); - curve1.HeadPoint = aPoint1; - curve1.EndPoint = aPoint2; + curve1.HeadPoint = point1; + curve1.EndPoint = point2; AddDataItemToProperList(curve1); NewlyEffectedCurves.Add(curve1); return curve1; @@ -632,56 +634,58 @@ return newPoint; } - private void AddDataItemToProperList(IGeometryObject aData) + private void AddDataItemToProperList(IGeometryObject data) { - if (aData.GetType() == typeof(Point2D)) + if (data.GetType() == typeof(Point2D)) { - var point = (Point2D) aData; + var point = (Point2D) data; Points.Add(point); } - else if (aData.GetType() == typeof(GeometryCurve)) + else if (data.GetType() == typeof(GeometryCurve)) { - var geometryCurve = (GeometryCurve) aData; + var geometryCurve = (GeometryCurve) data; Curves.Add(geometryCurve); } - else if (aData.GetType() == typeof(GeometryLoop)) + else if (data.GetType() == typeof(GeometryLoop)) { - Loops.Add((GeometryLoop) aData); + Loops.Add((GeometryLoop) data); } - else if (aData.GetType() == typeof(GeometrySurface)) + else if (data.GetType() == typeof(GeometrySurface)) { - Surfaces.Add((GeometrySurface) aData); + Surfaces.Add((GeometrySurface) data); } } - private void CheckForCurvesWherePointIsOnBothConnectedCurvesInLineWithEachOther(Point2D aPoint, List source) + private void CheckForCurvesWherePointIsOnBothConnectedCurvesInLineWithEachOtherAndFixThem(Point2D point, List source) { var line1Point1 = new Point2D(); var line2Point1 = new Point2D(); - line1Point1.Init(source[0].HeadPoint != aPoint ? source[0].HeadPoint : source[0].EndPoint); - line2Point1.Init(source[1].HeadPoint != aPoint ? source[1].HeadPoint : source[1].EndPoint); - double angle = Routines2D.FindAngle(line1Point1, aPoint, line2Point1, aPoint); - if (angle.IsGreaterThanOrEqualTo(179.0) && angle.IsLessThanOrEqualTo(181.0)) + const double almost180 = 179.0; + const double justOver180 = 181.0; + line1Point1.Init(source[0].HeadPoint != point ? source[0].HeadPoint : source[0].EndPoint); + line2Point1.Init(source[1].HeadPoint != point ? source[1].HeadPoint : source[1].EndPoint); + double angle = Routines2D.FindAngle(line1Point1, point, line2Point1, point); + if (angle.IsGreaterThanOrEqualTo(almost180) && angle.IsLessThanOrEqualTo(justOver180)) { - FixCurvesWherePointIsOnBothConnectedCurvesInLineWithEachOther(aPoint, source); + FixCurvesWherePointIsOnBothConnectedCurvesInLineWithEachOther(point, source); } } - private void FixCurvesWherePointIsOnBothConnectedCurvesInLineWithEachOther(Point2D aPoint, List source) + private void FixCurvesWherePointIsOnBothConnectedCurvesInLineWithEachOther(Point2D point, List source) { for (var index = 0; index < Curves.Count - 1; ++index) { if (Curves[index] == source[0]) { - if (Curves[index].EndPoint != source[1].EndPoint && aPoint == source[0].HeadPoint && aPoint == source[1].HeadPoint) + if (Curves[index].EndPoint != source[1].EndPoint && point == source[0].HeadPoint && point == source[1].HeadPoint) { Curves[index].HeadPoint = source[1].EndPoint; } - else if (Curves[index].EndPoint != source[1].EndPoint && aPoint == source[1].HeadPoint) + else if (Curves[index].EndPoint != source[1].EndPoint && point == source[1].HeadPoint) { Curves[index].EndPoint = source[1].EndPoint; } - else if (Curves[index].HeadPoint != source[1].HeadPoint && aPoint == Curves[index].EndPoint) + else if (Curves[index].HeadPoint != source[1].HeadPoint && point == Curves[index].EndPoint) { Curves[index].EndPoint = source[1].HeadPoint; } @@ -690,7 +694,7 @@ Curves[index].HeadPoint = source[1].HeadPoint; } - Remove(aPoint); + Remove(point); Remove(source[1]); } } @@ -1121,7 +1125,7 @@ #region calculation function - private int GetDependentCurveCount(Point2D aPoint) + private int GetDependentCurveCount(Point2D point) { int curveCount = Curves.Count; var curvePointDependency = 0; @@ -1130,7 +1134,7 @@ { for (var index = 0; index < curveCount; index++) { - if (Curves[index].HeadPoint == aPoint || Curves[index].EndPoint == aPoint) + if (Curves[index].HeadPoint == point || Curves[index].EndPoint == point) { curvePointDependency++; }