Index: DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryCurve.cs =================================================================== diff -u -r4540 -r4897 --- DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryCurve.cs (.../GeometryCurve.cs) (revision 4540) +++ DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryCurve.cs (.../GeometryCurve.cs) (revision 4897) @@ -47,7 +47,6 @@ /// public class GeometryCurve : GeometryObject { - private readonly Routines2D routines2D = new Routines2D(); private Point2D endPoint; private Point2D headPoint; @@ -199,7 +198,7 @@ public bool ContainsPoint(Point2D point, double tolerance = GeometryConstants.Accuracy * 0.5) { return HeadPoint != null && EndPoint != null && - routines2D.DoesPointExistInLine(HeadPoint, EndPoint, point, tolerance); + Routines2D.DoesPointExistInLine(HeadPoint, EndPoint, point, tolerance); } /// Index: DamEngine/trunk/src/Deltares.DamEngine.Data/Geotechnics/LayerDetector.cs =================================================================== diff -u -r4540 -r4897 --- DamEngine/trunk/src/Deltares.DamEngine.Data/Geotechnics/LayerDetector.cs (.../LayerDetector.cs) (revision 4540) +++ DamEngine/trunk/src/Deltares.DamEngine.Data/Geotechnics/LayerDetector.cs (.../LayerDetector.cs) (revision 4897) @@ -41,7 +41,6 @@ private readonly List intersectionSurfacesList = new List(); private readonly List pointList = new List(); private readonly IList soilSurfaces; - private readonly Routines2D routines2D = new Routines2D(); private double verticalXCoordinate; @@ -155,7 +154,7 @@ var verticalEndPoint = new Point2D(verticalXCoordinate, minvalue); Point2D intersectionPoint; - LineIntersection intersectionResult = routines2D.DetermineIf2DLinesIntersectStrickly(verticalHeadPoint, + LineIntersection intersectionResult = Routines2D.DetermineIf2DLinesIntersectStrickly(verticalHeadPoint, verticalEndPoint, aHeadpoint, aEndPoint, out intersectionPoint); if (intersectionResult == LineIntersection.Intersects) @@ -165,8 +164,8 @@ else if (intersectionResult == LineIntersection.NoIntersection || intersectionResult == LineIntersection.Parallel) { const double cEpsilon = 1.0e-3; - if ((routines2D.DoesPointExistInLine(verticalHeadPoint, verticalEndPoint, - aHeadpoint, cEpsilon)) && (routines2D.DoesPointExistInLine(verticalHeadPoint, + if ((Routines2D.DoesPointExistInLine(verticalHeadPoint, verticalEndPoint, + aHeadpoint, cEpsilon)) && (Routines2D.DoesPointExistInLine(verticalHeadPoint, verticalEndPoint, aEndPoint, cEpsilon))) { AddPointToList(new LayerIntersectionPoint(aHeadpoint, aSurfaceRefKey)); @@ -235,7 +234,7 @@ }; // check where the mid point lies - PointInPolygon polygonResult = routines2D.CheckIfPointIsInPolygon(aPoint1.SurfaceRefKey.GeometrySurface.OuterLoop, + PointInPolygon polygonResult = Routines2D.CheckIfPointIsInPolygon(aPoint1.SurfaceRefKey.GeometrySurface.OuterLoop, midPoint.X, midPoint.Z); Point2D startPoint = aPoint1.IntersectionPoint; @@ -249,7 +248,7 @@ List innerLoopList = aPoint1.SurfaceRefKey.GeometrySurface.InnerLoops; foreach (GeometryLoop innerLoop in innerLoopList) { - PointInPolygon innerPolygonResult = routines2D.CheckIfPointIsInPolygon(innerLoop, midPoint.X, midPoint.Z); + PointInPolygon innerPolygonResult = Routines2D.CheckIfPointIsInPolygon(innerLoop, midPoint.X, midPoint.Z); if (innerPolygonResult != PointInPolygon.OutsidePolygon) { isPresentInInnerLoop = true; Index: DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryData.cs =================================================================== diff -u -r4879 -r4897 --- DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryData.cs (.../GeometryData.cs) (revision 4879) +++ DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryData.cs (.../GeometryData.cs) (revision 4897) @@ -34,7 +34,6 @@ public class GeometryData : GeometryObject { private readonly GeometryPointString surfaceLine = new GeometryPointString(); - private readonly Routines2D routines2D = new Routines2D(); private GeometryGenerator geometryGenerator; private bool isRegeneratingGeometry; @@ -144,13 +143,13 @@ { SynchronizeLoops(); geometryGenerator.SetupCurveSurfaceAssociations(); - bool regenerateGeometry = false; + var regenerateGeometry = false; var curvesToDelete = new List(); - foreach (var curve in Curves) + foreach (GeometryCurve curve in Curves) { - if ((curve.SurfaceAtLeft == null && curve.SurfaceAtRight == null)) + if ((curve.SurfaceAtLeft == null && curve.SurfaceAtRight == null)) { - curvesToDelete.Add(curve); + curvesToDelete.Add(curve); } else if ((curve.SurfaceAtLeft != null && curve.SurfaceAtRight != null) && (curve.SurfaceAtLeft == curve.SurfaceAtRight)) @@ -160,10 +159,11 @@ } } - foreach (var curve in curvesToDelete) + foreach (GeometryCurve curve in curvesToDelete) { DeleteCurve(curve, false); } + if (regenerateGeometry) { RegenerateGeometry(); @@ -227,6 +227,25 @@ } /// + /// Finds the point at location. + /// + /// Point location to be found. + /// The tolerance. + /// The point at the location; if not found returns null. + public Point2D GetPointAtLocation(Point2D point2D, double tolerance) + { + for (var i = 0; i < Points.Count; i++) + { + if (Routines2D.DetermineIfPointsCoincide(point2D.X, point2D.Z, Points[i].X, Points[i].Z, tolerance)) + { + return Points[i]; + } + } + + return null; + } + + /// /// Returns a that represents this instance. /// /// @@ -960,7 +979,7 @@ ref Point2D intersect) { Point2D ip; - LineIntersection res = routines2D.DetermineIf2DLinesIntersectStrickly(beginPoint1, endPoint1, + LineIntersection res = Routines2D.DetermineIf2DLinesIntersectStrickly(beginPoint1, endPoint1, beginPoint2, endPoint2, out ip); if (ip != null) { Index: DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryLoop.cs =================================================================== diff -u -r4884 -r4897 --- DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryLoop.cs (.../GeometryLoop.cs) (revision 4884) +++ DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryLoop.cs (.../GeometryLoop.cs) (revision 4897) @@ -30,8 +30,6 @@ /// public class GeometryLoop : GeometryPointString { - private readonly Routines2D routines2D = new Routines2D(); - /// /// List of points that describe the physical surface line or surface. /// @@ -122,7 +120,7 @@ public bool IsClockWise() { List polyGon = GetLocalPoint2DList(); - Clockwise isClockWise = routines2D.IsClockWise(polyGon); + Clockwise isClockWise = Routines2D.IsClockWise(polyGon); if (isClockWise == Clockwise.NotEnoughUniquePoints) { throw new NotEnoughUniquePointsException(); @@ -142,13 +140,14 @@ /// True if continuous, false if not public bool IsContinuous() { - for (int i = 0; i < CurveList.Count - 1; i++) + for (var i = 0; i < CurveList.Count - 1; i++) { if (CurveList[i].EndPoint != CurveList[i + 1].HeadPoint) { return false; } } + return true; } @@ -159,7 +158,7 @@ /// public bool IsPointInLoopArea(Point2D aPoint) { - return routines2D.CheckIfPointIsInPolygon(this, aPoint.X, aPoint.Z) != PointInPolygon.OutsidePolygon; + return Routines2D.CheckIfPointIsInPolygon(this, aPoint.X, aPoint.Z) != PointInPolygon.OutsidePolygon; } /// Index: DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryGenerator.cs =================================================================== diff -u -r4879 -r4897 --- DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryGenerator.cs (.../GeometryGenerator.cs) (revision 4879) +++ DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryGenerator.cs (.../GeometryGenerator.cs) (revision 4897) @@ -37,7 +37,6 @@ // private readonly List intersectedCurveList = new List(); private readonly List newlyDetectedSurfaceList = new List(); - private readonly Routines2D routines2D = new Routines2D(); /// /// Regenerates the geometry. @@ -116,6 +115,19 @@ } /// + /// Setups the curve surface associations. + /// + public void SetupCurveSurfaceAssociations() + { + SetUpGeometryLoopDirections(); + // only try to connect curves to surfaces when there are loops (i.e. surfaces) + if (geometryLoopDirections.Count > 0) + { + SetupCurveSurfaceAssociation(); + } + } + + /// /// Adds the curve to the list in given direction. /// /// @@ -466,7 +478,7 @@ point4.X = attachedCurveList[index2].GetEndPoint().X; point4.Z = attachedCurveList[index2].GetEndPoint().Z; - double angle = routines2D.FindAngle(point1, point2, point3, point4); + double angle = Routines2D.FindAngle(point1, point2, point3, point4); if (angle < minAngle) { @@ -770,19 +782,6 @@ } } - /// - /// Setups the curve surface associations. - /// - public void SetupCurveSurfaceAssociations() - { - SetUpGeometryLoopDirections(); - // only try to connect curves to surfaces when there are loops (i.e. surfaces) - if (geometryLoopDirections.Count > 0) - { - SetupCurveSurfaceAssociation(); - } - } - private void SetUpGeometryLoopDirections() { geometryLoopDirections.Clear(); @@ -863,7 +862,7 @@ // check if it is an inner loop for (var innerIndex = 0; innerIndex < newPointCount; innerIndex++) { - PointInPolygon location = routines2D.CheckIfPointIsInPolygon(loop, newPolygon[innerIndex].X, newPolygon[innerIndex].Z); + PointInPolygon location = Routines2D.CheckIfPointIsInPolygon(loop, newPolygon[innerIndex].X, newPolygon[innerIndex].Z); if (location == PointInPolygon.InsidePolygon) { @@ -878,7 +877,7 @@ // check if it has an inner loop for (var innerIndex1 = 0; innerIndex1 < existingLoopPointCount; innerIndex1++) { - PointInPolygon location = routines2D.CheckIfPointIsInPolygon(newLoop, polygon[innerIndex1].X, polygon[innerIndex1].Z); + PointInPolygon location = Routines2D.CheckIfPointIsInPolygon(newLoop, polygon[innerIndex1].X, polygon[innerIndex1].Z); if (location == PointInPolygon.InsidePolygon) { Index: DamEngine/trunk/src/Deltares.DamEngine.Data.Tests/General/GeometryDataTests.cs =================================================================== diff -u -r4627 -r4897 --- DamEngine/trunk/src/Deltares.DamEngine.Data.Tests/General/GeometryDataTests.cs (.../GeometryDataTests.cs) (revision 4627) +++ DamEngine/trunk/src/Deltares.DamEngine.Data.Tests/General/GeometryDataTests.cs (.../GeometryDataTests.cs) (revision 4897) @@ -132,6 +132,42 @@ Assert.That(geom.Surfaces[0].OuterLoop.IsPointInLoopArea(new Point2D(25, 5.1)), Is.False); } + [Test] + [TestCase(1, 0, true)] + [TestCase(10, 0, true)] + [TestCase(10, 10, true)] + [TestCase(1, 10, true)] + [TestCase(1, 1, false)] + [TestCase(0, 1, false)] + public void GivenPointsWhenGetPointAtLocationCalledThenCorrectPointIsReturned(double x, double z, bool isPresent) + { + const double tolerance = 1e-6; + var geometryModel = new GeometryData(); + var point1 = new Point2D(1, 0); + var point2 = new Point2D(10, 0); + var point3 = new Point2D(10, 10); + var point4 = new Point2D(1, 10); + geometryModel.Points.AddRange(new[] + { + point1, + point2, + point3, + point4 + }); + + Point2D point = geometryModel.GetPointAtLocation(new Point2D(x, z), tolerance); + if (isPresent) + { + Assert.That(point, Is.Not.Null); + Assert.That(point.X, Is.EqualTo(x).Within(tolerance)); + Assert.That(point.Z, Is.EqualTo(z).Within(tolerance)); + } + else + { + Assert.That(point, Is.Null); + } + } + private GeometryData CreateGeometrySurface() { var geometryModel = new GeometryData(); Index: DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/LineHelper.cs =================================================================== diff -u -r4540 -r4897 --- DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/LineHelper.cs (.../LineHelper.cs) (revision 4540) +++ DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/LineHelper.cs (.../LineHelper.cs) (revision 4897) @@ -30,8 +30,6 @@ /// public class LineHelper { - private readonly Routines2D routines2D = new Routines2D(); - /// /// Calculate intersection between two lines (strict interpolation) /// @@ -47,7 +45,7 @@ var point4 = new Point2D(line2.EndPoint.X, line2.EndPoint.Z); Point2D ip; - LineIntersection res = routines2D.DetermineIf2DLinesIntersectStrickly(point1, point2, point3, + LineIntersection res = Routines2D.DetermineIf2DLinesIntersectStrickly(point1, point2, point3, point4, out ip); if (ip != null) { @@ -148,7 +146,7 @@ /// private List Intersect_Circle_line(double xm, double ym, double r, Line line) { - return routines2D.IntersectCircleline(xm, ym, r, line.BeginPoint.X, line.EndPoint.X, line.BeginPoint.Z, line.EndPoint.Z); + return Routines2D.IntersectCircleline(xm, ym, r, line.BeginPoint.X, line.EndPoint.X, line.BeginPoint.Z, line.EndPoint.Z); } /// @@ -168,7 +166,7 @@ var point3 = new Point2D(p3.X, p3.Z); var point4 = new Point2D(p4.X, p4.Z); - routines2D.DetermineIf2DLinesIntersectWithExtrapolation(point1, point2, point3, point4, out Point2D ip); + Routines2D.DetermineIf2DLinesIntersectWithExtrapolation(point1, point2, point3, point4, out Point2D ip); if (ip != null) { intersectPoint = new GeometryPoint(ip.X, ip.Z); Index: DamEngine/trunk/src/Deltares.DamEngine.Data.Tests/Geotechnics/GeometryHelperTests.cs =================================================================== diff -u -r4879 -r4897 --- DamEngine/trunk/src/Deltares.DamEngine.Data.Tests/Geotechnics/GeometryHelperTests.cs (.../GeometryHelperTests.cs) (revision 4879) +++ DamEngine/trunk/src/Deltares.DamEngine.Data.Tests/Geotechnics/GeometryHelperTests.cs (.../GeometryHelperTests.cs) (revision 4897) @@ -100,4 +100,27 @@ // When & Then Assert.Throws(() => { GeometryHelper.ExtendGeometryRight(soilProfile2D.Geometry, 8); }); } + + [Test, Ignore("Work in progress")] + public void GivenTwoLayerGeometryWhenCuttingLeftThenLeftBoundaryIsChanged() + { + // Given + SoilProfile2D soilProfile2D = FactoryForSoilProfiles.CreateSoilProfile2DWithThreeLayers(); + // For debugging purposes + // GeometryExporter.ExportToFile(soilProfile2D.Geometry, visualizationFolder + "Geometry.txt"); + // GeometryExporter.ExportToJsonFile(soilProfile2D.Geometry, visualizationFolder + "Geometry.json"); + + // When + GeometryHelper.CutGeometryLeft(soilProfile2D.Geometry, 2); + // For debugging purposes + GeometryExporter.ExportToFile(soilProfile2D.Geometry, visualizationFolder + "Geometry.txt"); + GeometryExporter.ExportToJsonFile(soilProfile2D.Geometry, visualizationFolder + "Geometry.json"); + + // Then + var geometryBounds = soilProfile2D.Geometry.GetGeometryBounds(); + Assert.That(geometryBounds.Left, Is.EqualTo(2).Within(cTolerance)); + Assert.That(soilProfile2D.Geometry.Left, Is.EqualTo(2).Within(cTolerance)); + Assert.That(soilProfile2D.Geometry.Surfaces.Count, Is.EqualTo(3)); + } + } \ No newline at end of file Index: DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryHelper.cs =================================================================== diff -u -r4880 -r4897 --- DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryHelper.cs (.../GeometryHelper.cs) (revision 4880) +++ DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryHelper.cs (.../GeometryHelper.cs) (revision 4897) @@ -116,4 +116,75 @@ geometry.Rebox(); geometry.Right = toX; } + + /// + /// Cuts the geometry left at the given value of x. + /// + /// The geometry. + /// X position to cut the geometry. + public static void CutGeometryLeft(GeometryData geometry, double atX) + { + // TODO: This method is duplicated in SoilSurfaceProfile2D, should be refactored to a single method + GeometryCurve intersectionCurve = GetIntersectionCurveAt(geometry, atX); + // check if a curve intersects the atX, if so move point. + GeometryCurve[] curves = geometry.Curves.ToArray(); + foreach (GeometryCurve geometryCurve in curves) + { + var resPoint = new Point2D(); + 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, skip this curve + 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 resPoint); + if (res == LineIntersection.Intersects) + { + var splitPoint = new Point2D(resPoint.X, resPoint.Z); + // Split the curve at the split point + SplitCurveAtPoint(geometry, geometryCurve, splitPoint); + } + } + } + } + + /// + /// Gets the intersection curve which is a vertical helper line which can be used to find all intersections at a given x. + /// + /// The geometry. + /// X position to create the intersection. + /// + private static GeometryCurve GetIntersectionCurveAt(GeometryData geometry, double atX) + { + var headPoint = new Point2D(atX, geometry.MaxGeometryPointsZ + 1); + var endPoint = new Point2D(atX, geometry.MinGeometryPointsZ - 1); + return new GeometryCurve(headPoint, endPoint); + } + + /// + /// Splits the (existing) curve at this point and adds the splitPoint when needed. + /// + /// The geometry. + /// The geometry curve. + /// The split point. + private static void SplitCurveAtPoint(GeometryData geometry, GeometryCurve geometryCurve, Point2D splitPoint) + { + Point2D existingPoint = geometry.GetPointAtLocation(new Point2D(splitPoint.X, splitPoint.Z), GeometryConstants.Accuracy); + // If point already exists do not add but use it + if (existingPoint == null) + { + geometry.Points.Add(splitPoint); + } + else + { + splitPoint = existingPoint; + } + + GeometryCurve oldCurve = geometryCurve; + Point2D oldEnd = oldCurve.EndPoint; + oldCurve.EndPoint = splitPoint; + var newCurve = new GeometryCurve(splitPoint, oldEnd); + geometry.Curves.Add(newCurve); + } } \ No newline at end of file Index: DamEngine/trunk/src/Deltares.DamEngine.Data.Tests/Geotechnics/SoilProfile2DSurfaceLineHelperTests.cs =================================================================== diff -u -r4879 -r4897 --- DamEngine/trunk/src/Deltares.DamEngine.Data.Tests/Geotechnics/SoilProfile2DSurfaceLineHelperTests.cs (.../SoilProfile2DSurfaceLineHelperTests.cs) (revision 4879) +++ DamEngine/trunk/src/Deltares.DamEngine.Data.Tests/Geotechnics/SoilProfile2DSurfaceLineHelperTests.cs (.../SoilProfile2DSurfaceLineHelperTests.cs) (revision 4897) @@ -23,13 +23,16 @@ using Deltares.DamEngine.Data.Geometry; using Deltares.DamEngine.Data.Geotechnics; using Deltares.DamEngine.TestHelpers.Factories; +using Deltares.DamEngine.TestHelpers.Geometry; using NUnit.Framework; namespace Deltares.DamEngine.Data.Tests.Geotechnics; [TestFixture] public class SoilProfile2DSurfaceLineHelperTests { + // For debugging purposes + private const string visualizationFolder = @"D:\src\dam\DamTools\GeometryVisualizer\"; [Test] [TestCase(PositionToSoilProfile2D.LeftOfSoilProfile, false)] [TestCase(PositionToSoilProfile2D.RightOfSoilProfile, false)] @@ -39,6 +42,9 @@ { // Given SoilProfile2D soilProfile2D = FactoryForSoilProfiles.CreateSoilProfile2DWithTwoLayers(); + // For debugging purposes + // GeometryExporter.ExportToFile(soilProfile2D.Geometry, visualizationFolder + "Geometry.txt"); + // GeometryExporter.ExportToJsonFile(soilProfile2D.Geometry, visualizationFolder + "Geometry.json"); SurfaceLine2 surfaceLine = CreateSurfaceLineForSoilProfile2D(soilProfile2D, positionToSoilProfile2D); // When-Then Index: DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/Routines2D.cs =================================================================== diff -u -r4540 -r4897 --- DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/Routines2D.cs (.../Routines2D.cs) (revision 4540) +++ DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/Routines2D.cs (.../Routines2D.cs) (revision 4897) @@ -82,9 +82,9 @@ /// /// Static class Routines2D /// -public class Routines2D +public static class Routines2D { - private const double CEpsilon = 1.0e-4; + private const double tolerance = 1.0e-4; /// /// Checks if the 2D Lines strictly intersect. Strictly means that the intersection point must be part of both lines so @@ -101,11 +101,11 @@ /// /// For connected parallel lines, the connection point will be returned as valid intersection point. /// - public LineIntersection DetermineIf2DLinesIntersectStrickly(Point2D point1, Point2D point2, Point2D point3, - Point2D point4, out Point2D intersectionPoint) + public static LineIntersection DetermineIf2DLinesIntersectStrickly(Point2D point1, Point2D point2, Point2D point3, + Point2D point4, out Point2D intersectionPoint) { return DetermineIf2DLinesIntersectStrickly(point1, point2, point3, point4, - out intersectionPoint, CEpsilon); + out intersectionPoint, tolerance); } /// @@ -116,7 +116,7 @@ /// The point. /// The tolerance. /// - public bool DoesPointExistInLine(Point2D linePoint1, Point2D linePoint2, Point2D point, double tolerance) + 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 @@ -168,7 +168,7 @@ /// /// /// - public Clockwise IsClockWise(IEnumerable aPolygon) + public static Clockwise IsClockWise(IEnumerable aPolygon) { Point2D[] distinctPoints = aPolygon.Distinct().ToArray(); if (distinctPoints.Length < 3) @@ -227,7 +227,7 @@ /// The x. /// The z. /// - public PointInPolygon CheckIfPointIsInPolygon(GeometryLoop polygon, double x, double z) + public static PointInPolygon CheckIfPointIsInPolygon(GeometryLoop polygon, double x, double z) { // This is done by calculating and adding the angles from the point to all points // of the polygon (using the ArcTan2 function). If the sum of these angles is @@ -331,7 +331,7 @@ /// /// /// - public List IntersectCircleline(double aX, double aY, double aR, double aX1, double aX2, double aY1, double aY2) + public static List IntersectCircleline(double aX, double aY, double aR, double aX1, double aX2, double aY1, double aY2) { // Solve by filling in parametric equation of line : // X = x1 + u*(x2 - x1) @@ -413,8 +413,8 @@ /// /// /// - public double FindAngle(Point2D line1Point1, Point2D line1Point2, Point2D line2Point1, - Point2D line2Point2) + public static double FindAngle(Point2D line1Point1, Point2D line1Point2, Point2D line2Point1, + Point2D line2Point2) { double x1 = line1Point2.X - line1Point1.X; double z1 = line1Point2.Z - line1Point1.Z; @@ -442,7 +442,7 @@ /// /// /// - public bool AreEqual(double x1, double x2, double tolerance) + public static bool AreEqual(double x1, double x2, double tolerance) { return (Math.Abs(x1 - x2) < tolerance); } @@ -456,7 +456,7 @@ /// a point4. /// a intersection point. /// - public LineIntersection DetermineIf2DLinesIntersectWithExtrapolation(Point2D aPoint1, Point2D aPoint2, Point2D aPoint3, Point2D aPoint4, out Point2D aIntersectionPoint) + public static LineIntersection DetermineIf2DLinesIntersectWithExtrapolation(Point2D aPoint1, Point2D aPoint2, Point2D aPoint3, Point2D aPoint4, out Point2D aIntersectionPoint) { LineConstant lLineConstant1 = CalculateNormalLineConstants(aPoint1, aPoint2); LineConstant lLineConstant2 = CalculateNormalLineConstants(aPoint3, aPoint4); @@ -475,7 +475,7 @@ /// /// /// - public LineIntersection DetermineIf2DLinesIntersectWithExtrapolation(LineConstant aLine1Constant, LineConstant aLine2Constant, out Point2D aIntersectionPoint) + public static LineIntersection DetermineIf2DLinesIntersectWithExtrapolation(LineConstant aLine1Constant, LineConstant aLine2Constant, out Point2D aIntersectionPoint) { aIntersectionPoint = new Point2D(0.0, 0.0); @@ -486,7 +486,7 @@ double lB2 = aLine2Constant.Y; double lC2 = aLine2Constant.Z; - if (AreLinesParallel(lA1, lA2, lB1, lB2, CEpsilon)) + if (AreLinesParallel(lA1, lA2, lB1, lB2, tolerance)) { aIntersectionPoint = null; return LineIntersection.Parallel; @@ -510,7 +510,7 @@ /// The point2 z. /// The tolerance. /// - public bool DetermineIfPointsCoincide(double point1X, double point1Z, double point2X, double point2Z, double tolerance) + public static bool DetermineIfPointsCoincide(double point1X, double point1Z, double point2X, double point2Z, double tolerance) { if ((Math.Abs(point1X - point2X)) < tolerance && Math.Abs(point1Z - point2Z) < tolerance) { @@ -520,7 +520,7 @@ return false; } - private void UndoAddIfNeeded(GeometryLoop polygon, bool needed) + private static void UndoAddIfNeeded(GeometryLoop polygon, bool needed) { if (needed) { @@ -536,7 +536,7 @@ /// X-coordinate of the second point /// Y-coordinate of the second point /// - private double CrossProduct(double pointAx, double pointAy, double pointBx, double pointBy) + private static double CrossProduct(double pointAx, double pointAy, double pointBx, double pointBy) { return pointAx * pointBy - pointBx * pointAy; } @@ -547,7 +547,7 @@ /// The point1. /// The point2. /// - private LineConstant CalculateNormalLineConstants(Point2D point1, Point2D point2) + private static LineConstant CalculateNormalLineConstants(Point2D point1, Point2D point2) { double point1X = point1.X; double point1Z = point1.Z; @@ -573,7 +573,7 @@ /// a line2 constant y. /// The tolerance. /// - private bool AreLinesParallel(double aLine1ConstantX, double aLine1ConstantY, double aLine2ConstantX, double aLine2ConstantY, double tolerance) + private static bool AreLinesParallel(double aLine1ConstantX, double aLine1ConstantY, double aLine2ConstantX, double aLine2ConstantY, double tolerance) { return Math.Abs(CrossProduct(aLine1ConstantX, aLine2ConstantX, aLine1ConstantY, aLine2ConstantY)) < tolerance; } @@ -586,7 +586,7 @@ /// X-coordinate of the second point /// Y-coordinate of the second point /// The distance between the given points. - private double Compute2DDistance(double aX1, double aY1, double aX2, double aY2) + private static double Compute2DDistance(double aX1, double aY1, double aX2, double aY2) { double lX = aX1 - aX2; double lY = aY1 - aY2; @@ -610,8 +610,8 @@ /// /// For connected parallel lines, the connection point will be returned as valid intersection point. /// - private LineIntersection DetermineIf2DLinesIntersectStrickly(Point2D point1, Point2D point2, Point2D point3, - Point2D point4, out Point2D intersectionPoint, double tolerance) + private static LineIntersection DetermineIf2DLinesIntersectStrickly(Point2D point1, Point2D point2, Point2D point3, + Point2D point4, out Point2D intersectionPoint, double tolerance) { double point1X = point1.X; double point1Z = point1.Z; @@ -674,8 +674,8 @@ /// The point4 z. /// The tolerance. /// - private bool DoLinesAtLeastPartialyOverlap(double point1X, double point1Z, double point2X, double point2Z, - double point3X, double point3Z, double point4X, double point4Z, double tolerance) + private static bool DoLinesAtLeastPartialyOverlap(double point1X, double point1Z, double point2X, double point2Z, + double point3X, double point3Z, double point4X, double point4Z, double tolerance) { bool result = AreLinesParallel(point1X, point1Z, point2X, point2Z, point3X, point3Z, point4X, point4Z, tolerance); @@ -730,8 +730,8 @@ /// /// True when parallel /// - private bool AreLinesParallel(double point1X, double point1Z, double point2X, double point2Z, - double point3X, double point3Z, double point4X, double point4Z, double tolerance) + private static bool AreLinesParallel(double point1X, double point1Z, double point2X, double point2Z, + double point3X, double point3Z, double point4X, double point4Z, double tolerance) { double aX = point2X - point1X; double aY = point2Z - point1Z; @@ -747,7 +747,7 @@ /// /// Normalizes this instance. /// - private void Normalize(ref double pointX, ref double pointY) + private static void Normalize(ref double pointX, ref double pointY) { double q = Math.Sqrt(pointX * pointX + pointY * pointY); Index: DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryPointString.cs =================================================================== diff -u -r4540 -r4897 --- DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryPointString.cs (.../GeometryPointString.cs) (revision 4540) +++ DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryPointString.cs (.../GeometryPointString.cs) (revision 4897) @@ -86,7 +86,6 @@ protected readonly List calcPoints = new List(); private readonly List points = new List(); - private readonly Routines2D routines2D = new Routines2D(); private bool isFrozen; private bool hasNaNx; private double frozenMaxZ = double.NaN; @@ -702,7 +701,7 @@ double slopeBefore = (calcPoints[i].Z - calcPoints[i - 1].Z) / (calcPoints[i].X - calcPoints[i - 1].X); double slopeAfter = (calcPoints[i + 1].Z - calcPoints[i].Z) / (calcPoints[i + 1].X - calcPoints[i].X); - if (routines2D.AreEqual(slopeBefore, slopeAfter, slopeTolerance)) + if (Routines2D.AreEqual(slopeBefore, slopeAfter, slopeTolerance)) { calcPoints.RemoveAt(i); }