Index: Ringtoets/Piping/src/Ringtoets.Piping.Forms/Views/PipingChartDataFactory.cs =================================================================== diff -u -re62502b93eb5144e00dcba97a69b6c6088b99656 -rfd3f53993a2113c76da7d305a0e80621605bfe3f --- Ringtoets/Piping/src/Ringtoets.Piping.Forms/Views/PipingChartDataFactory.cs (.../PipingChartDataFactory.cs) (revision e62502b93eb5144e00dcba97a69b6c6088b99656) +++ Ringtoets/Piping/src/Ringtoets.Piping.Forms/Views/PipingChartDataFactory.cs (.../PipingChartDataFactory.cs) (revision fd3f53993a2113c76da7d305a0e80621605bfe3f) @@ -29,7 +29,6 @@ using Core.Common.Geometry; using Core.Components.Charting.Data; using Core.Components.Charting.Styles; -using Ringtoets.Common.Forms.Views; using Ringtoets.Piping.Forms.Properties; using Ringtoets.Piping.Primitives; using PipingDataResources = Ringtoets.Piping.Data.Properties.Resources; @@ -357,20 +356,13 @@ private static ChartData CreateLocalPoint(Point3D worldPoint, RingtoetsPipingSurfaceLine surfaceLine, string name, ChartPointStyle style) { - Point2D firstPoint = Point3DToPoint2D(surfaceLine.Points.First()); - Point2D lastPoint = Point3DToPoint2D(surfaceLine.Points.Last()); return new ChartPointData(new[] { - worldPoint.ProjectIntoLocalCoordinates(firstPoint, lastPoint) + surfaceLine.GetLocalPointFromGeometry(worldPoint) }, name) { Style = style }; } - - private static Point2D Point3DToPoint2D(Point3D point3D) - { - return new Point2D(point3D.X, point3D.Y); - } } } \ No newline at end of file Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/PipingSurfaceLinesCsvImporter.cs =================================================================== diff -u -r4e49e3da1fa385207c70c8cc28ed04cda530bc61 -rfd3f53993a2113c76da7d305a0e80621605bfe3f --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/PipingSurfaceLinesCsvImporter.cs (.../PipingSurfaceLinesCsvImporter.cs) (revision 4e49e3da1fa385207c70c8cc28ed04cda530bc61) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/PipingSurfaceLinesCsvImporter.cs (.../PipingSurfaceLinesCsvImporter.cs) (revision fd3f53993a2113c76da7d305a0e80621605bfe3f) @@ -209,12 +209,8 @@ return true; } - var firstPoint = readSurfaceLine.Points.First(); - var lastPoint = readSurfaceLine.Points.Last(); - var firstLocalPoint = new Point2D(firstPoint.X, firstPoint.Y); - var lastLocalPoint = new Point2D(lastPoint.X, lastPoint.Y); - var localDikeToeAtRiver = characteristicPoints.DikeToeAtRiver.ProjectIntoLocalCoordinates(firstLocalPoint, lastLocalPoint); - var localDikeToeAtPolder = characteristicPoints.DikeToeAtPolder.ProjectIntoLocalCoordinates(firstLocalPoint, lastLocalPoint); + var localDikeToeAtRiver = readSurfaceLine.GetLocalPointFromGeometry(characteristicPoints.DikeToeAtRiver); + var localDikeToeAtPolder = readSurfaceLine.GetLocalPointFromGeometry(characteristicPoints.DikeToeAtPolder); if (localDikeToeAtPolder.X <= localDikeToeAtRiver.X) { Index: Ringtoets/Piping/src/Ringtoets.Piping.Primitives/RingtoetsPipingSurfaceLine.cs =================================================================== diff -u -r619da07034480d4ba9e59fe0bea2dd06d83963e0 -rfd3f53993a2113c76da7d305a0e80621605bfe3f --- Ringtoets/Piping/src/Ringtoets.Piping.Primitives/RingtoetsPipingSurfaceLine.cs (.../RingtoetsPipingSurfaceLine.cs) (revision 619da07034480d4ba9e59fe0bea2dd06d83963e0) +++ Ringtoets/Piping/src/Ringtoets.Piping.Primitives/RingtoetsPipingSurfaceLine.cs (.../RingtoetsPipingSurfaceLine.cs) (revision fd3f53993a2113c76da7d305a0e80621605bfe3f) @@ -268,7 +268,7 @@ } var segments = new Collection(); - for (int i = 1; i < localGeometry.Length; i++) + for (int i = 1; i < LocalGeometry.Length; i++) { segments.Add(new Segment2D(LocalGeometry[i - 1], LocalGeometry[i])); } @@ -329,6 +329,29 @@ return !(firstLocalPoint.X > roundedLocalCoordinateL) && !(lastLocalPoint.X < roundedLocalCoordinateL); } + /// + /// Gets the local coordinate with rounded values based on the geometry of the surface line and the given world coordinate. + /// + /// The world coordinate to get the local coordinate for. + /// The local coordinate. + public Point2D GetLocalPointFromGeometry(Point3D worldCoordinate) + { + var count = Points.Length; + if (count <= 1) + { + return new Point2D(double.NaN, double.NaN); + } + + Point3D first = Points.First(); + Point3D last = Points.Last(); + Point2D firstPoint = new Point2D(first.X, first.Y); + Point2D lastPoint = new Point2D(last.X, last.Y); + + Point2D localCoordinate = worldCoordinate.ProjectIntoLocalCoordinates(firstPoint, lastPoint); + return new Point2D(new RoundedDouble(numberOfDecimalPlaces, localCoordinate.X), + new RoundedDouble(numberOfDecimalPlaces, localCoordinate.Y)); + } + public override string ToString() { return Name; Index: Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/RingtoetsPipingSurfaceLineTest.cs =================================================================== diff -u -r619da07034480d4ba9e59fe0bea2dd06d83963e0 -rfd3f53993a2113c76da7d305a0e80621605bfe3f --- Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/RingtoetsPipingSurfaceLineTest.cs (.../RingtoetsPipingSurfaceLineTest.cs) (revision 619da07034480d4ba9e59fe0bea2dd06d83963e0) +++ Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/RingtoetsPipingSurfaceLineTest.cs (.../RingtoetsPipingSurfaceLineTest.cs) (revision fd3f53993a2113c76da7d305a0e80621605bfe3f) @@ -648,13 +648,6 @@ // Assert Assert.IsFalse(valid); - -// // Call -// TestDelegate call = () => surfaceLine.ValidateInRange((RoundedDouble) invalidValue, surfaceLine.ProjectGeometryToLZ().ToArray()); -// -// // Assert -// var expectedMessage = string.Format("Kan geen hoogte bepalen. De lokale coördinaat moet in het bereik [0, {0}] liggen.", 1.37); -// TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage); } [Test] @@ -678,6 +671,58 @@ Assert.IsTrue(valid); } + [Test] + public void GetLocalPointFromGeometry_ValidSurfaceLine_ReturnsLocalPoint() + { + // Setup + var testX = 1.0; + var testY = 2.2; + var testZ = 4.4; + Point3D testPoint = new Point3D(testX, testY, testZ); + RingtoetsPipingSurfaceLine surfaceLine = new RingtoetsPipingSurfaceLine(); + CreateTestGeometry(testPoint, surfaceLine); + + // Call + Point2D localPoint = surfaceLine.GetLocalPointFromGeometry(testPoint); + + // Assert + Assert.AreEqual(new Point2D(0.04, 4.4), localPoint); + } + + [Test] + public void GetLocalPointFromGeometry_NoPointsOnSurfaceLine_ReturnsPointWithNanValues() + { + // Setup + RingtoetsPipingSurfaceLine surfaceLine = new RingtoetsPipingSurfaceLine(); + + // Call + Point2D localPoint = surfaceLine.GetLocalPointFromGeometry(new Point3D(1.0, 2.2, 4.4)); + + // Assert + Assert.AreEqual(new Point2D(double.NaN, double.NaN), localPoint); + } + + [Test] + public void GetLocalPointFromGeometry_OnePointOnSurfaceLine_ReturnsPointWithNanValues() + { + // Setup + var testX = 1.0; + var testY = 2.2; + var testZ = 4.4; + Point3D testPoint = new Point3D(testX, testY, testZ); + RingtoetsPipingSurfaceLine surfaceLine = new RingtoetsPipingSurfaceLine(); + surfaceLine.SetGeometry(new[] + { + testPoint + }); + + // Call + Point2D localPoint = surfaceLine.GetLocalPointFromGeometry(testPoint); + + // Assert + Assert.AreEqual(new Point2D(double.NaN, double.NaN), localPoint); + } + private static void CreateTestGeometry(Point3D testPoint, RingtoetsPipingSurfaceLine surfaceLine) { var random = new Random(21); Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Views/PipingChartDataFactoryTest.cs =================================================================== diff -u -re62502b93eb5144e00dcba97a69b6c6088b99656 -rfd3f53993a2113c76da7d305a0e80621605bfe3f --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Views/PipingChartDataFactoryTest.cs (.../PipingChartDataFactoryTest.cs) (revision e62502b93eb5144e00dcba97a69b6c6088b99656) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Views/PipingChartDataFactoryTest.cs (.../PipingChartDataFactoryTest.cs) (revision fd3f53993a2113c76da7d305a0e80621605bfe3f) @@ -770,9 +770,10 @@ Point2D firstPoint = new Point2D(first.X, first.Y); Point2D lastPoint = new Point2D(last.X, last.Y); + var localCoordinate = point.ProjectIntoLocalCoordinates(firstPoint, lastPoint); AssertEqualPointCollections(new[] { - point.ProjectIntoLocalCoordinates(firstPoint, lastPoint) + new Point2D(new RoundedDouble(2, localCoordinate.X), new RoundedDouble(2, localCoordinate.Y)) }, chartPoints); }