Index: DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryGenerator.cs =================================================================== diff -u -r6538 -r7042 --- DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryGenerator.cs (.../GeometryGenerator.cs) (revision 6538) +++ DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryGenerator.cs (.../GeometryGenerator.cs) (revision 7042) @@ -150,12 +150,12 @@ double distance2 = Routines2D.CalculateDistanceToLine(point2.X, point2.Z, line.HeadPoint.X, line.HeadPoint.Z, line.EndPoint.X, line.EndPoint.Z); - if (distance1 > distance2 && distance1 > GeometryConstants.Accuracy) + if (distance1 > distance2 && distance1 > GeometryConstants.Tolerance) { isPoint1ClosestToLine = false; } - if (distance1 < distance2 && distance2 > GeometryConstants.Accuracy) + if (distance1 < distance2 && distance2 > GeometryConstants.Tolerance) { isPoint2ClosestToLine = false; } @@ -179,10 +179,10 @@ Point2D localPoint3 = line2.HeadPoint; Point2D localPoint4 = line2.EndPoint; - bool isPoint3OnLine1 = Routines2D.DoesPointExistInLine(localPoint1, localPoint2, localPoint3, GeometryConstants.Accuracy); - 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 isPoint3OnLine1 = Routines2D.DoesPointExistInLine(localPoint1, localPoint2, localPoint3, GeometryConstants.Tolerance); + bool isPoint4OnLine1 = Routines2D.DoesPointExistInLine(localPoint1, localPoint2, localPoint4, GeometryConstants.Tolerance); + bool isPoint1OnLine2 = Routines2D.DoesPointExistInLine(localPoint3, localPoint4, localPoint1, GeometryConstants.Tolerance); + bool isPoint2OnLine2 = Routines2D.DoesPointExistInLine(localPoint3, localPoint4, localPoint2, GeometryConstants.Tolerance); bool isPoint1SameAsPoint3 = localPoint1.LocationEquals(localPoint3); bool isPoint1SameAsPoint4 = localPoint1.LocationEquals(localPoint4); bool isPoint2SameAsPoint3 = localPoint2.LocationEquals(localPoint3); @@ -1154,7 +1154,7 @@ /// /// Regenerates all the curves that have intersections. /// Find all intersections between curves and split them at the intersection points, adding curves where needed. - /// Find all parallel curves and split them at the intersection pointss, adding curves where needed. + /// Find all parallel curves and split them at the intersection points, adding curves where needed. /// At the end, clean up the points and curves. /// private void RegenerateAllCurvesIntersection() @@ -1204,9 +1204,9 @@ out Point2D intersectionPoint) == LineIntersection.Intersects) { if (!Routines2D.DetermineIfPointsCoincide(geometryCurve1HeadPoint.X, geometryCurve1HeadPoint.Z, intersectionPoint.X, - intersectionPoint.Z, 0.001) + intersectionPoint.Z, GeometryConstants.Tolerance) && !Routines2D.DetermineIfPointsCoincide(geometryCurve1EndPoint.X, geometryCurve1EndPoint.Z, intersectionPoint.X, - intersectionPoint.Z, 0.001)) + intersectionPoint.Z, GeometryConstants.Tolerance)) { Point2D point = geometryData.CreatePointAndAddItToTheProperListsWhenNeeded(new Point2D(intersectionPoint.X, intersectionPoint.Z)); @@ -1215,9 +1215,9 @@ } if (!Routines2D.DetermineIfPointsCoincide(geometryCurve2HeadPoint.X, geometryCurve2HeadPoint.Z, intersectionPoint.X, - intersectionPoint.Z, 0.001) && + intersectionPoint.Z, GeometryConstants.Tolerance) && !Routines2D.DetermineIfPointsCoincide(geometryCurve2EndPoint.X, geometryCurve2EndPoint.Z, intersectionPoint.X, - intersectionPoint.Z, 0.001)) + intersectionPoint.Z, GeometryConstants.Tolerance)) { Point2D point = geometryData.CreatePointAndAddItToTheProperListsWhenNeeded(new Point2D(intersectionPoint.X, intersectionPoint.Z)); @@ -1248,7 +1248,7 @@ { if ((index2 != index1) && (Routines2D.DetermineIfPointsCoincide( geometryData.Points[index1].X, geometryData.Points[index1].Z, - geometryData.Points[index2].X, geometryData.Points[index2].Z, 0.001))) + geometryData.Points[index2].X, geometryData.Points[index2].Z, GeometryConstants.Tolerance))) { aConnectedAtHeadCurveList.Clear(); aConnectedAtEndCurveList.Clear(); Index: DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryData.cs =================================================================== diff -u -r6525 -r7042 --- DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryData.cs (.../GeometryData.cs) (revision 6525) +++ DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryData.cs (.../GeometryData.cs) (revision 7042) @@ -176,7 +176,7 @@ /// Point location to be found. /// Maximum allowed distance between the points /// The point at the location; if not found returns null. - public Point2D GetPointAtLocation(Point2D point2D, double distance = GeometryConstants.Accuracy) + public Point2D GetPointAtLocation(Point2D point2D, double distance = GeometryConstants.Tolerance) { for (var i = 0; i < Points.Count; i++) { Index: DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/Point2D.cs =================================================================== diff -u -r6404 -r7042 --- DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/Point2D.cs (.../Point2D.cs) (revision 6404) +++ DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/Point2D.cs (.../Point2D.cs) (revision 7042) @@ -69,7 +69,7 @@ /// The other. /// The precision. /// - public bool LocationEquals(Point2D other, double precision = GeometryConstants.Accuracy) + public bool LocationEquals(Point2D other, double precision = GeometryConstants.Tolerance) { if (ReferenceEquals(other, null)) { Index: DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryHelper.cs =================================================================== diff -u -r7041 -r7042 --- DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryHelper.cs (.../GeometryHelper.cs) (revision 7041) +++ DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryHelper.cs (.../GeometryHelper.cs) (revision 7042) @@ -22,6 +22,7 @@ using System; using System.Collections.Generic; using System.Linq; +using Deltares.DamEngine.Data.Standard; namespace Deltares.DamEngine.Data.Geometry; @@ -85,26 +86,28 @@ var p1 = new Point2D(geometryCurve.HeadPoint.X, geometryCurve.HeadPoint.Z); var p2 = new Point2D(geometryCurve.EndPoint.X, geometryCurve.EndPoint.Z); // If head or endpoint is at atX, add this existing point to the local list - if (Math.Abs(p1.X - atX) < GeometryConstants.Accuracy) + if (p1.X.AlmostEquals(atX)) { splitPoints.Add(p1); } - if (Math.Abs(p2.X - atX) < GeometryConstants.Accuracy) + else { - splitPoints.Add(p2); - } - - if (Math.Abs(p1.X - atX) > GeometryConstants.Accuracy && Math.Abs(p2.X - atX) > GeometryConstants.Tolerance) - { - var p3 = new Point2D(intersectionCurve.HeadPoint.X, intersectionCurve.HeadPoint.Z); - var p4 = new Point2D(intersectionCurve.EndPoint.X, intersectionCurve.EndPoint.Z); - LineIntersection res = Routines2D.DetermineIf2DLinesIntersectStrickly(p1, p2, p3, p4, out Point2D resPoint); - if (res == LineIntersection.Intersects) + if (p2.X.AlmostEquals(atX)) { - var splitPoint = new Point2D(resPoint.X, resPoint.Z); - // Add SplitPoint to the local list - splitPoints.Add(splitPoint); + splitPoints.Add(p2); } + else + { + var p3 = new Point2D(intersectionCurve.HeadPoint.X, intersectionCurve.HeadPoint.Z); + var p4 = new Point2D(intersectionCurve.EndPoint.X, intersectionCurve.EndPoint.Z); + LineIntersection res = Routines2D.DetermineIf2DLinesIntersectStrickly(p1, p2, p3, p4, out Point2D resPoint); + if (res == LineIntersection.Intersects) + { + var splitPoint = new Point2D(resPoint.X, resPoint.Z); + // Add SplitPoint to the local list + splitPoints.Add(splitPoint); + } + } } } @@ -149,27 +152,29 @@ { var p1 = new Point2D(geometryCurve.HeadPoint.X, geometryCurve.HeadPoint.Z); var p2 = new Point2D(geometryCurve.EndPoint.X, geometryCurve.EndPoint.Z); - // If head or endpoint is at atX, add this existing point to the local list - if (Math.Abs(p1.X - atX) < GeometryConstants.Accuracy) + + if (p1.X.AlmostEquals(atX)) { splitPoints.Add(p1); } - if (Math.Abs(p2.X - atX) < GeometryConstants.Accuracy) + else { - splitPoints.Add(p2); - } - - if (Math.Abs(p1.X - atX) > GeometryConstants.Accuracy && Math.Abs(p2.X - atX) > GeometryConstants.Accuracy) - { - var p3 = new Point2D(intersectionCurve.HeadPoint.X, intersectionCurve.HeadPoint.Z); - var p4 = new Point2D(intersectionCurve.EndPoint.X, intersectionCurve.EndPoint.Z); - LineIntersection res = Routines2D.DetermineIf2DLinesIntersectStrickly(p1, p2, p3, p4, out Point2D resPoint); - if (res == LineIntersection.Intersects) + if (p2.X.AlmostEquals(atX)) { - var splitPoint = new Point2D(resPoint.X, resPoint.Z); - // Add SplitPoint to the local list - splitPoints.Add(splitPoint); + splitPoints.Add(p2); } + else + { + var p3 = new Point2D(intersectionCurve.HeadPoint.X, intersectionCurve.HeadPoint.Z); + var p4 = new Point2D(intersectionCurve.EndPoint.X, intersectionCurve.EndPoint.Z); + LineIntersection res = Routines2D.DetermineIf2DLinesIntersectStrickly(p1, p2, p3, p4, out Point2D resPoint); + if (res == LineIntersection.Intersects) + { + var splitPoint = new Point2D(resPoint.X, resPoint.Z); + // Add SplitPoint to the local list + splitPoints.Add(splitPoint); + } + } } } @@ -350,8 +355,8 @@ private static bool IsCurveAnExistingCurve(GeometryCurve curve, GeometrySurface surface) { - if (((curve.SurfaceAtLeft == null ? (1) : (curve.SurfaceAtLeft == surface ? 1 : 0)) & - (curve.SurfaceAtRight == null ? 1 : (curve.SurfaceAtRight == surface ? 1 : 0))) != 0) + if (((curve.SurfaceAtLeft == null ? 1 : curve.SurfaceAtLeft == surface ? 1 : 0) & + (curve.SurfaceAtRight == null ? 1 : curve.SurfaceAtRight == surface ? 1 : 0)) != 0) { return true; } Index: DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryCurve.cs =================================================================== diff -u -r6404 -r7042 --- DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryCurve.cs (.../GeometryCurve.cs) (revision 6404) +++ DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryCurve.cs (.../GeometryCurve.cs) (revision 7042) @@ -122,7 +122,7 @@ public virtual GeometrySurface SurfaceAtRight { get; set; } /// - /// Locations the equals. + /// Indicates if the curves are equal. /// /// a curve. /// Index: DamEngine/trunk/src/Deltares.DamEngine.Data.Tests/Geotechnics/SoilProfile2DSurfaceLineHelperTests.cs =================================================================== diff -u -r7040 -r7042 --- DamEngine/trunk/src/Deltares.DamEngine.Data.Tests/Geotechnics/SoilProfile2DSurfaceLineHelperTests.cs (.../SoilProfile2DSurfaceLineHelperTests.cs) (revision 7040) +++ DamEngine/trunk/src/Deltares.DamEngine.Data.Tests/Geotechnics/SoilProfile2DSurfaceLineHelperTests.cs (.../SoilProfile2DSurfaceLineHelperTests.cs) (revision 7042) @@ -458,41 +458,49 @@ } [Test] - public void GivenSoilProfile2DWithASurfacePointCoincidingWithEndPointOfSurfaceLine_WhenCombiningWithSurfaceLine_ThenCorrectNewSoilProfile2DIsCreated() + [TestCase(35.002, 7)] + [TestCase(35.001,7)] + [TestCase(35.000, 6)] + [TestCase(34.999, 6)] + [TestCase(34.998, 6)] + public void GivenSoilProfile2DWithAPointCloseOrAlongXEndOfNewSurfaceLine_WhenCombiningWithSurfaceLine_ThenCorrectNewSoilProfile2DIsCreated(double xEndSurfaceLine, int expectedLayerCount) { // Given SoilProfile2D soilProfile2D = FactoryForSoilProfiles.CreateSoilProfile2DWithSixSurfacesFormingTwoLayers(); var defaultSoil = new Soil { Name = "Filling material" }; - SurfaceLine2 surfaceLine = FactoryForSurfaceLines.CreateHorizontalSurfaceLine(11, -50, 35); + SurfaceLine2 surfaceLine = FactoryForSurfaceLines.CreateHorizontalSurfaceLine(11, -50, xEndSurfaceLine); // When SoilProfile2D newSoilProfile2D = SoilProfile2DSurfaceLineHelper.CombineSurfaceLineWithSoilProfile2D( surfaceLine.Geometry, soilProfile2D, defaultSoil); // Then Assert.That(newSoilProfile2D, Is.Not.Null); - Assert.That(newSoilProfile2D.Surfaces, Has.Count.EqualTo(6)); - var soil1 = new Soil("Soil1"); - var soil2 = new Soil("Soil2"); - var soil3 = new Soil("Soil3"); - var soil4 = new Soil("Soil4"); - var soil5 = new Soil("Soil5"); - SoilLayer2D expectedSurface1 = FactoryForSoilProfiles.CreateRectangularSoilLayer2D(10, 0, -50, -20, newSoilProfile2D, soil1); - SoilLayer2D expectedSurface2 = FactoryForSoilProfiles.CreatePentagonSoilLayer2D(new Point2D(-20, 10), new Point2D(0, 10), new Point2D(0, 0), new Point2D(-10, 0), new Point2D(-20, 0), newSoilProfile2D, soil2); - SoilLayer2D expectedSurface3 = FactoryForSoilProfiles.CreateRectangularSoilLayer2D(10, 0, 0, 35, newSoilProfile2D, soil3); - SoilLayer2D expectedSurface4 = FactoryForSoilProfiles.CreatePentagonSoilLayer2D(new Point2D(-50, 0), new Point2D(-20, 0), new Point2D(-10, 0), new Point2D(-10, -15), new Point2D(-50, -15), newSoilProfile2D, soil4); - SoilLayer2D expectedSurface5 = FactoryForSoilProfiles.CreatePentagonSoilLayer2D(new Point2D(-10, 0), new Point2D(0, 0), new Point2D(35, 0), new Point2D(35, -15), new Point2D(-10, -15), newSoilProfile2D, soil5); - SoilLayer2D expectedSurfaceFilling = FactoryForSoilProfiles.CreatePolygoneSoilLayer2D([ - new Point2D(-50, 11), new Point2D(-28.75, 11), new Point2D(-7.5, 11), new Point2D(13.75, 11), new Point2D(35, 11), new Point2D(35, 10), new Point2D(0, 10), new Point2D(-20, 10), new Point2D(-50, 10) - ], defaultSoil, newSoilProfile2D); - CheckSoilProfileContainsSoilLayer(newSoilProfile2D, expectedSurface1); - CheckSoilProfileContainsSoilLayer(newSoilProfile2D, expectedSurface2); - CheckSoilProfileContainsSoilLayer(newSoilProfile2D, expectedSurface3); - CheckSoilProfileContainsSoilLayer(newSoilProfile2D, expectedSurface4); - CheckSoilProfileContainsSoilLayer(newSoilProfile2D, expectedSurface5); - CheckSoilProfileContainsSoilLayer(newSoilProfile2D, expectedSurfaceFilling); + Assert.That(newSoilProfile2D.Surfaces, Has.Count.EqualTo(expectedLayerCount)); + if (expectedLayerCount == 6) + { + var soil1 = new Soil("Soil1"); + var soil2 = new Soil("Soil2"); + var soil3 = new Soil("Soil3"); + var soil4 = new Soil("Soil4"); + var soil5 = new Soil("Soil5"); + SoilLayer2D expectedSurface1 = FactoryForSoilProfiles.CreateRectangularSoilLayer2D(10, 0, -50, -20, newSoilProfile2D, soil1); + SoilLayer2D expectedSurface2 = FactoryForSoilProfiles.CreatePentagonSoilLayer2D(new Point2D(-20, 10), new Point2D(0, 10), new Point2D(0, 0), new Point2D(-10, 0), new Point2D(-20, 0), newSoilProfile2D, soil2); + SoilLayer2D expectedSurface3 = FactoryForSoilProfiles.CreateRectangularSoilLayer2D(10, 0, 0, xEndSurfaceLine, newSoilProfile2D, soil3); + SoilLayer2D expectedSurface4 = FactoryForSoilProfiles.CreatePentagonSoilLayer2D(new Point2D(-50, 0), new Point2D(-20, 0), new Point2D(-10, 0), new Point2D(-10, -15), new Point2D(-50, -15), newSoilProfile2D, soil4); + SoilLayer2D expectedSurface5 = FactoryForSoilProfiles.CreatePentagonSoilLayer2D(new Point2D(-10, 0), new Point2D(0, 0), new Point2D(xEndSurfaceLine, 0), new Point2D(xEndSurfaceLine, -15), new Point2D(-10, -15), newSoilProfile2D, soil5); + SoilLayer2D expectedSurfaceFilling = FactoryForSoilProfiles.CreatePolygoneSoilLayer2D([ + new Point2D(-50, 11), surfaceLine.CharacteristicPoints[1].Point, surfaceLine.CharacteristicPoints[2].Point, surfaceLine.CharacteristicPoints[3].Point, new Point2D(xEndSurfaceLine, 11), new Point2D(xEndSurfaceLine, 10), new Point2D(0, 10), new Point2D(-20, 10), new Point2D(-50, 10) + ], defaultSoil, newSoilProfile2D); + CheckSoilProfileContainsSoilLayer(newSoilProfile2D, expectedSurface1); + CheckSoilProfileContainsSoilLayer(newSoilProfile2D, expectedSurface2); + CheckSoilProfileContainsSoilLayer(newSoilProfile2D, expectedSurface3); + CheckSoilProfileContainsSoilLayer(newSoilProfile2D, expectedSurface4); + CheckSoilProfileContainsSoilLayer(newSoilProfile2D, expectedSurface5); + CheckSoilProfileContainsSoilLayer(newSoilProfile2D, expectedSurfaceFilling); + } } ///