Index: DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryGenerator.cs =================================================================== diff -u -r5618 -r5687 --- DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryGenerator.cs (.../GeometryGenerator.cs) (revision 5618) +++ DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryGenerator.cs (.../GeometryGenerator.cs) (revision 5687) @@ -518,11 +518,12 @@ return CreateSurfaces(newLoopList); } #if DEBUG - catch //(Exception ex) + catch (Exception ex) { //Todo:Show error msg box //var lm = new LogMessage(LogMessageType.FatalError, this, "DetectSurfaces:" + ex.Message); //LogManager.Add(lm); + var text = ex.Message; return 0; } #else @@ -560,7 +561,7 @@ } } - if (!loop.IsLoop()) + if (!loop.IsLoop() || !loop.HasArea()) { continue; } @@ -1073,9 +1074,14 @@ line.HeadPoint.X, line.HeadPoint.Z, line.EndPoint.X, line.EndPoint.Z); if (distance1 > distance2) + { isPoint1ClosestToLine = false; - else + } + + if (distance1 < distance2) + { isPoint2ClosestToLine = false; + } } protected internal static void DeterminePointClosestToAnotherPoint(Point2D point1, Point2D point2, Point2D point3, @@ -1111,10 +1117,10 @@ bool isPoint4OnLine1 = Routines2D.DoesPointExistInLine(localPoint1, localPoint2, localPoint4, GeometryConstants.Accuracy); bool isPoint1OnLine2 = Routines2D.DoesPointExistInLine(localPoint3, localPoint4, localPoint1, GeometryConstants.Accuracy); bool isPoint2OnLine2 = Routines2D.DoesPointExistInLine(localPoint3, localPoint4, localPoint2, GeometryConstants.Accuracy); - bool isPoint1SameAsPoint3 = Routines2D.DetermineIfPointsCoincide(localPoint1.X, localPoint1.Z, localPoint3.X, localPoint3.Z,GeometryConstants.Accuracy); - bool isPoint1SameAsPoint4 = Routines2D.DetermineIfPointsCoincide(localPoint1.X, localPoint1.Z, localPoint4.X, localPoint4.Z, GeometryConstants.Accuracy); - bool isPoint2SameAsPoint3 = Routines2D.DetermineIfPointsCoincide(localPoint2.X, localPoint2.Z, localPoint3.X, localPoint3.Z, GeometryConstants.Accuracy); - bool isPoint2SameAsPoint4 = Routines2D.DetermineIfPointsCoincide(localPoint2.X, localPoint2.Z, localPoint4.X, localPoint4.Z, GeometryConstants.Accuracy); + bool isPoint1SameAsPoint3 = localPoint1.LocationEquals(localPoint3); + bool isPoint1SameAsPoint4 = localPoint1.LocationEquals(localPoint4); + bool isPoint2SameAsPoint3 = localPoint2.LocationEquals(localPoint3); + bool isPoint2SameAsPoint4 = localPoint2.LocationEquals(localPoint4); double slope1 = DetermineSlope(line1); double slope2 = DetermineSlope(line2); @@ -1145,8 +1151,24 @@ if ((isPoint1OnLine2 && isPoint2OnLine2) || (isPoint3OnLine1 && isPoint4OnLine1) || ((isPoint3OnLine1 || isPoint4OnLine1) && (isPoint1OnLine2 || isPoint2OnLine2))) { - // p1----p3------p2----p4 GeometryCurve newLine; + // p1----p3----p2/p4 (p2/p4 coincide) + if (isPoint3OnLine1 && isPoint4OnLine1 && !isPoint1SameAsPoint3 && !isPoint1SameAsPoint4 && !isPoint2SameAsPoint3 && isPoint2SameAsPoint4) + { + SplitCurve(line1, line2.HeadPoint); + return true; + } + + // p1/p3----p2----p4 (p1/p3 coincide) + // if (isPoint1OnLine2 && isPoint2OnLine2 && isPoint1SameAsPoint3 && !isPoint1SameAsPoint4 && !isPoint2SameAsPoint3 && !isPoint2SameAsPoint4) + // { + // SplitCurve(line1, line2.HeadPoint); + // return true; + // } + + + + // p1----p3------p2----p4 if (isPoint3OnLine1 && !isPoint4OnLine1 && !isPoint1SameAsPoint3 && !isPoint2SameAsPoint3) { newLine = SplitCurve(line1, line2.HeadPoint); @@ -1284,10 +1306,12 @@ GeometryCurve newCurve = geometryData.CreateCurve(pointOnCurve, srcCurve.EndPoint); srcCurve.EndPoint = newCurve.HeadPoint; newCurve.AssignSurfacesFromCurve(srcCurve); - this.AddToIntersectedCurveList(srcCurve); - this.AddToIntersectedCurveList(newCurve); - if (!geometryData.Curves.Contains(newCurve)) + AddToIntersectedCurveList(srcCurve); + AddToIntersectedCurveList(newCurve); + if (!geometryData.DoesCurveExist(newCurve)) + { geometryData.Curves.Add(newCurve); + } return newCurve; } Index: DamEngine/trunk/src/Deltares.DamEngine.Data/Geotechnics/SoilProfile2DSurfaceLineHelper.cs =================================================================== diff -u -r5565 -r5687 --- DamEngine/trunk/src/Deltares.DamEngine.Data/Geotechnics/SoilProfile2DSurfaceLineHelper.cs (.../SoilProfile2DSurfaceLineHelper.cs) (revision 5565) +++ DamEngine/trunk/src/Deltares.DamEngine.Data/Geotechnics/SoilProfile2DSurfaceLineHelper.cs (.../SoilProfile2DSurfaceLineHelper.cs) (revision 5687) @@ -80,7 +80,7 @@ SoilProfile2D clonedProfile = soilProfile2D.Clone(); GeometryPointString clonedSurfaceLine = surfaceLine.Clone(); - RoundCoordinates(clonedSurfaceLine, clonedProfile.Geometry); + RoundCoordinates(clonedProfile.Geometry, clonedSurfaceLine); shift = GeometryObject.RoundValue(shift); if (Math.Abs(shift) >= GeometryConstants.Accuracy) { @@ -99,7 +99,7 @@ var oldSurfaces = new List(); oldSurfaces.AddRange((IEnumerable) soilProfile2D2.Surfaces); - AddGeometryIntersectionsToSurfaceLine(clonedProfile.Geometry, ref clonedSurfaceLine); + //AddGeometryIntersectionsToSurfaceLine(clonedProfile.Geometry, ref clonedSurfaceLine); // #Bka dit moet weg kunnen, eerst wel even testen var result = new SoilProfile2D(); BuildGeometryModel(clonedSurfaceLine, clonedProfile, ref result); @@ -109,6 +109,7 @@ ReconstructPreConsolidations(ref result, clonedProfile, shift); result.Geometry.Rebox(); result.Geometry.UpdateSurfaceLine(); + RoundCoordinates(result.Geometry); return result; } @@ -132,7 +133,7 @@ return true; } - private static void RoundCoordinates(GeometryPointString surfaceLine, GeometryData geometry) + private static void RoundCoordinates(GeometryData geometry, GeometryPointString surfaceLine = null) { const double accuracy = 1e-7; foreach (Point2D point in geometry.Points) @@ -144,7 +145,10 @@ geometry.Right = GeometryObject.RoundValue(geometry.Right, accuracy); geometry.Left = GeometryObject.RoundValue(geometry.Left, accuracy); geometry.Bottom = GeometryObject.RoundValue(geometry.Bottom, accuracy); - surfaceLine.RoundPointsCoordinates(accuracy); + if (surfaceLine != null) + { + surfaceLine.RoundPointsCoordinates(accuracy); + } } private static void AddGeometryIntersectionsToSurfaceLine(GeometryData geometry, ref GeometryPointString clonedSurfaceLine) { @@ -224,7 +228,7 @@ geometry.NewlyEffectedPoints.Add(currentPoint1); if (leftPoints[^1].Z < currentPoint1.Z) { - // When the first point of the surface line is above the geometry (leftpoits) add a curve to the geometry + // When the first point of the surface line is above the geometry (left points) add a curve to the geometry // from the last (= top) point of the left points to the first point of the surface line. GeometryCurve newLeftCurve = new GeometryCurve(leftPoints[^1], currentPoint1); geometryData.NewlyEffectedCurves.Add(newLeftCurve); @@ -248,6 +252,8 @@ geometry.NewlyEffectedPoints.Add(currentPoint2); if (rightPoints[^1].Z < currentPoint2.Z) { + // When the last point of the surface line is above the geometry (right points) add a curve to the + // geometry from the last (= top) point of the right points to the last point of the surface line. GeometryCurve newRightCurve = new GeometryCurve(rightPoints[^1], currentPoint2); geometryData.NewlyEffectedCurves.Add(newRightCurve); } Index: DamEngine/trunk/src/Deltares.DamEngine.Data.Tests/Geometry/GeometryGeneratorTests.cs =================================================================== diff -u -r5222 -r5687 --- DamEngine/trunk/src/Deltares.DamEngine.Data.Tests/Geometry/GeometryGeneratorTests.cs (.../GeometryGeneratorTests.cs) (revision 5222) +++ DamEngine/trunk/src/Deltares.DamEngine.Data.Tests/Geometry/GeometryGeneratorTests.cs (.../GeometryGeneratorTests.cs) (revision 5687) @@ -30,7 +30,7 @@ { [TestCase(0.52, 0.51, false, true)] [TestCase(0.51, 0.52, true, false)] - [TestCase(0.51, 0.51, true, false)] + [TestCase(0.51, 0.51, true, true)] [Test] public void WhenDeterminePointClosestToLine_ThenResultIsAsExpected(double x1, double x2, bool isPoint1Closest, bool isPoint2Closest) { Index: DamEngine/trunk/src/Deltares.DamEngine.IntegrationTests/IntegrationTests/OperationalHHNKTests.cs =================================================================== diff -u -r5656 -r5687 --- DamEngine/trunk/src/Deltares.DamEngine.IntegrationTests/IntegrationTests/OperationalHHNKTests.cs (.../OperationalHHNKTests.cs) (revision 5656) +++ DamEngine/trunk/src/Deltares.DamEngine.IntegrationTests/IntegrationTests/OperationalHHNKTests.cs (.../OperationalHHNKTests.cs) (revision 5687) @@ -20,6 +20,10 @@ // All rights reserved. using System.IO; +using Deltares.DamEngine.Data.Geometry; +using Deltares.DamEngine.Data.GeometryExport; +using Deltares.DamEngine.Data.Geotechnics; +using Deltares.DamEngine.Interface; using Deltares.DamEngine.Io.XmlOutput; using Deltares.DamEngine.TestHelpers; using NUnit.Framework; @@ -48,6 +52,26 @@ inputString = XmlAdapter.ChangeValueInXml(inputString, "ProjectPath", ""); // Current directory will be used inputString = XmlAdapter.ChangeValueInXml(inputString, "CalculationMap", calcDir); // Current directory will be used + var engineInterface = new EngineInterface(inputString); + int segmentIndex = 0; + var soilProfile2D = engineInterface.DamProjectData.Dike.Locations[0].Segment.SoilProfileProbabilities[0].SoilProfile2D; + GeometryData geometry = soilProfile2D.Geometry; + SurfaceLine2 surfaceLine = engineInterface.DamProjectData.Dike.Locations[0].SurfaceLine; + + GeometryExporter.ExportToFile(geometry, GeometryExporter.VisualizationFolder + "BeforeGeometry.txt"); + GeometryExporter.ExportWithSurfaceLineToJsonFile(GeometryExporter.VisualizationFolder + + GeometryExporter.ExportJasonFile, geometry, surfaceLine.Geometry); + + string soilName = engineInterface.DamProjectData.Dike.Locations[0].DikeEmbankmentMaterial; + Soil soil = engineInterface.DamProjectData.Dike.SoilList.GetSoilByName(soilName); + // To be able to check the geometry, create it here. + + SoilProfile2D soilProfile2DNew = SoilProfile2DSurfaceLineHelper.CombineSurfaceLineWithSoilProfile2D(surfaceLine.Geometry, soilProfile2D, soil, 0.0); + + GeometryExporter.ExportToFile(soilProfile2DNew.Geometry, GeometryExporter.VisualizationFolder + "AfterGeometry.txt"); + GeometryExporter.ExportWithSurfaceLineToJsonFile(GeometryExporter.VisualizationFolder + + GeometryExporter.ExportJasonFile, soilProfile2DNew.Geometry, null); + Output output = GeneralHelper.RunAfterInputValidation(inputString); // Output output = GeneralHelper.RunAfterInputValidation(inputString, false, "Output.xml"); Index: DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/Routines2D.cs =================================================================== diff -u -r5564 -r5687 --- DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/Routines2D.cs (.../Routines2D.cs) (revision 5564) +++ DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/Routines2D.cs (.../Routines2D.cs) (revision 5687) @@ -109,32 +109,32 @@ } /// - /// Does the point exist in line. + /// Does the point exist in line (within the given tolerance). /// /// The line point1. /// The line point2. /// The point. /// The tolerance. - /// + /// True when point is on line or equals a line point public static bool DoesPointExistInLine(Point2D linePoint1, Point2D linePoint2, Point2D point, double tolerance) { // Function to find if lies on or close to a line (within a given tolerance) // Input - a line defined by lTwo points, a third point to test and tolerance aValue // Output - TRUE or FALSE + // first check whether the point is equal to a line point + if (linePoint1.LocationEquals(point, tolerance) || linePoint2.LocationEquals(point, tolerance)) + { + return true; + } + double linePoint1X = linePoint1.X; double linePoint1Z = linePoint1.Z; double linePoint2X = linePoint2.X; double linePoint2Z = linePoint2.Z; double pointX = point.X; double pointZ = point.Z; - - // first check whether the points are identical - if (Math.Abs(linePoint1X - linePoint2X) < tolerance && Math.Abs(linePoint1Z - linePoint2Z) < tolerance) - { - return Compute2DDistance(pointX, pointZ, linePoint1X, linePoint1Z) < tolerance; - } - + // then check if point is within the bounding rectangle formed by 2 line points double maxX = Math.Max(linePoint1X, linePoint2X); double minX = Math.Min(linePoint1X, linePoint2X); Index: DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryData.cs =================================================================== diff -u -r5635 -r5687 --- DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryData.cs (.../GeometryData.cs) (revision 5635) +++ DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryData.cs (.../GeometryData.cs) (revision 5687) @@ -897,6 +897,16 @@ RemoveDoublesFromNewlyEffectedCurves(); } + /// + /// Determines whether a curve already exists. + /// + /// + /// + public bool DoesCurveExist(GeometryCurve curve) + { + return Curves.Any(c => c.LocationEquals(curve)); + } + private void RemoveDoublesFromNewlyEffectedCurves() { RemoveIllegalDoublesFromNewlyEffectedCurves();