Index: Ringtoets/Piping/src/Ringtoets.Piping.Data/PipingInput.cs =================================================================== diff -u -r35db69dfe64b7e7deeaf9ef85d4df42ff6009b11 -r619da07034480d4ba9e59fe0bea2dd06d83963e0 --- Ringtoets/Piping/src/Ringtoets.Piping.Data/PipingInput.cs (.../PipingInput.cs) (revision 35db69dfe64b7e7deeaf9ef85d4df42ff6009b11) +++ Ringtoets/Piping/src/Ringtoets.Piping.Data/PipingInput.cs (.../PipingInput.cs) (revision 619da07034480d4ba9e59fe0bea2dd06d83963e0) @@ -105,12 +105,19 @@ { var newEntryPointL = value.ToPrecision(entryPointL.NumberOfDecimalPlaces); - if (!double.IsNaN(newEntryPointL) && !double.IsNaN(exitPointL)) + if (!double.IsNaN(newEntryPointL)) { - ValidateEntryExitPoint(newEntryPointL, exitPointL); + if (!double.IsNaN(exitPointL)) + { + ValidateEntryExitPoint(newEntryPointL, exitPointL); + } + + if (surfaceLine != null) + { + ValidatePointOnSurfaceLine(newEntryPointL); + } } - ValidatePointOnSurfaceLine(newEntryPointL); entryPointL = newEntryPointL; } } @@ -137,12 +144,19 @@ { var newExitPointL = value.ToPrecision(exitPointL.NumberOfDecimalPlaces); - if (!double.IsNaN(entryPointL) && !double.IsNaN(newExitPointL)) + if (!double.IsNaN(newExitPointL)) { - ValidateEntryExitPoint(entryPointL, newExitPointL); + if (!double.IsNaN(entryPointL)) + { + ValidateEntryExitPoint(entryPointL, newExitPointL); + } + + if (surfaceLine != null) + { + ValidatePointOnSurfaceLine(newExitPointL); + } } - ValidatePointOnSurfaceLine(newExitPointL); exitPointL = newExitPointL; } } @@ -157,9 +171,12 @@ private void ValidatePointOnSurfaceLine(RoundedDouble newLocalXCoordinate) { - if (surfaceLine != null) + if (!surfaceLine.ValidateInRange(newLocalXCoordinate)) { - surfaceLine.ValidateInRange(newLocalXCoordinate, surfaceLine.ProjectGeometryToLZ().ToArray()); + var outOfRangeMessage = string.Format("De lengte van de lokale coördinaat moet in het bereik [{0}, {1}] liggen.", + surfaceLine.LocalGeometry.First().X, + surfaceLine.LocalGeometry.Last().X); + throw new ArgumentOutOfRangeException(null, outOfRangeMessage); } } Index: Ringtoets/Piping/src/Ringtoets.Piping.Primitives/RingtoetsPipingSurfaceLine.cs =================================================================== diff -u -r35db69dfe64b7e7deeaf9ef85d4df42ff6009b11 -r619da07034480d4ba9e59fe0bea2dd06d83963e0 --- Ringtoets/Piping/src/Ringtoets.Piping.Primitives/RingtoetsPipingSurfaceLine.cs (.../RingtoetsPipingSurfaceLine.cs) (revision 35db69dfe64b7e7deeaf9ef85d4df42ff6009b11) +++ Ringtoets/Piping/src/Ringtoets.Piping.Primitives/RingtoetsPipingSurfaceLine.cs (.../RingtoetsPipingSurfaceLine.cs) (revision 619da07034480d4ba9e59fe0bea2dd06d83963e0) @@ -37,15 +37,15 @@ public class RingtoetsPipingSurfaceLine : IStorable { private const int numberOfDecimalPlaces = 2; - private Point3D[] geometryPoints; + private Point2D[] localGeometry; /// /// Initializes a new instance of the class. /// public RingtoetsPipingSurfaceLine() { Name = string.Empty; - geometryPoints = new Point3D[0]; + Points = new Point3D[0]; } /// @@ -56,13 +56,7 @@ /// /// Gets the 3D points describing its geometry. /// - public Point3D[] Points - { - get - { - return geometryPoints; - } - } + public Point3D[] Points { get; private set; } /// /// Gets or sets the first 3D geometry point defining the surfaceline in world coordinates. @@ -109,6 +103,17 @@ /// public Point2D ReferenceLineIntersectionWorldPoint { get; set; } + /// + /// Gets the 2D points describing the local geometry of the surface line. + /// + public Point2D[] LocalGeometry + { + get + { + return localGeometry ?? (localGeometry = ProjectGeometryToLZ().ToArray()); + } + } + public long StorageId { get; set; } /// @@ -127,13 +132,15 @@ { throw new ArgumentException(Resources.RingtoetsPipingSurfaceLine_A_point_in_the_collection_was_null); } - geometryPoints = points.ToArray(); + Points = points.ToArray(); - if (geometryPoints.Length > 0) + if (Points.Length > 0) { - StartingWorldPoint = geometryPoints[0]; - EndingWorldPoint = geometryPoints[geometryPoints.Length - 1]; + StartingWorldPoint = Points[0]; + EndingWorldPoint = Points[Points.Length - 1]; } + + localGeometry = null; } /// @@ -251,19 +258,24 @@ { ValidateHasPoints(); - Point2D[] pointsInLocalCoordinates = ProjectGeometryToLZ().ToArray(); + if (!ValidateInRange(l)) + { + var outOfRangeMessage = string.Format(Resources.RingtoetsPipingSurfaceLine_0_L_needs_to_be_in_1_2_range, + Resources.RingtoetsPipingSurfaceLine_GetZAtL_Cannot_determine_height, + LocalGeometry.First().X, + LocalGeometry.Last().X); + throw new ArgumentOutOfRangeException(null, outOfRangeMessage); + } - ValidateInRange(l, pointsInLocalCoordinates); - var segments = new Collection(); - for (int i = 1; i < pointsInLocalCoordinates.Length; i++) + for (int i = 1; i < localGeometry.Length; i++) { - segments.Add(new Segment2D(pointsInLocalCoordinates[i - 1], pointsInLocalCoordinates[i])); + segments.Add(new Segment2D(LocalGeometry[i - 1], LocalGeometry[i])); } IEnumerable intersectionPoints = Math2D.SegmentsIntersectionWithVerticalLine(segments, l).OrderBy(p => p.Y).ToArray(); - const double intersectionTolerance = 1e-6; + const double intersectionTolerance = 1e-2; bool equalIntersections = Math.Abs(intersectionPoints.First().Y - intersectionPoints.Last().Y) < intersectionTolerance; if (equalIntersections) @@ -282,7 +294,7 @@ /// Collection of 2D points in the LZ-plane. public RoundedPoint2DCollection ProjectGeometryToLZ() { - var count = geometryPoints.Length; + var count = Points.Length; if (count == 0) { return new RoundedPoint2DCollection(numberOfDecimalPlaces, Enumerable.Empty()); @@ -291,7 +303,10 @@ Point3D first = Points.First(); if (count == 1) { - return new RoundedPoint2DCollection(numberOfDecimalPlaces, new[] { new Point2D(0.0, first.Z)}); + return new RoundedPoint2DCollection(numberOfDecimalPlaces, new[] + { + new Point2D(0.0, first.Z) + }); } Point3D last = Points.Last(); @@ -300,6 +315,20 @@ return new RoundedPoint2DCollection(numberOfDecimalPlaces, Points.Select(p => p.ProjectIntoLocalCoordinates(firstPoint, lastPoint))); } + /// + /// Checks whether is in range of the geometry projected in local coordinate system + /// where the points are ordered on the L-coordinate being monotonically non-decreasing. + /// + /// The local L-coordinate value to check for. + /// true when local L-coordinate is in range of the local geometry. false otherwise. + public bool ValidateInRange(double localCoordinateL) + { + Point2D firstLocalPoint = LocalGeometry.First(); + Point2D lastLocalPoint = LocalGeometry.Last(); + RoundedDouble roundedLocalCoordinateL = new RoundedDouble(numberOfDecimalPlaces, localCoordinateL); + return !(firstLocalPoint.X > roundedLocalCoordinateL) && !(lastLocalPoint.X < roundedLocalCoordinateL); + } + public override string ToString() { return Name; @@ -339,27 +368,5 @@ throw new InvalidOperationException(Resources.RingtoetsPipingSurfaceLine_SurfaceLine_has_no_Geometry); } } - - /// - /// Checks whether is in range of the . - /// - /// The value to check for. - /// Geometry projected in local coordinate system where the points are ordered on the - /// L-coordinate being monotonically non-decreasing - /// falls outside the L-coordiante span - /// defined by . - public void ValidateInRange(RoundedDouble localCoordinateL, Point2D[] geometryInLocalCoordinates) - { - Point2D firstLocalPoint = geometryInLocalCoordinates.First(); - Point2D lastLocalPoint = geometryInLocalCoordinates.Last(); - if (firstLocalPoint.X > localCoordinateL || lastLocalPoint.X < localCoordinateL) - { - var outOfRangeMessage = string.Format(Resources.RingtoetsPipingSurfaceLine_0_L_needs_to_be_in_1_2_range, - Resources.RingtoetsPipingSurfaceLine_GetZAtL_Cannot_determine_height, - firstLocalPoint.X, - lastLocalPoint.X); - throw new ArgumentOutOfRangeException(null, outOfRangeMessage); - } - } } } \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/PipingInputTest.cs =================================================================== diff -u -r35db69dfe64b7e7deeaf9ef85d4df42ff6009b11 -r619da07034480d4ba9e59fe0bea2dd06d83963e0 --- Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/PipingInputTest.cs (.../PipingInputTest.cs) (revision 35db69dfe64b7e7deeaf9ef85d4df42ff6009b11) +++ Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/PipingInputTest.cs (.../PipingInputTest.cs) (revision 619da07034480d4ba9e59fe0bea2dd06d83963e0) @@ -200,14 +200,14 @@ TestDelegate call = () => input.ExitPointL = (RoundedDouble) value; // Assert - var expectedMessage = "Kan geen hoogte bepalen. De lokale coördinaat moet in het bereik [0, 1] liggen."; + var expectedMessage = "De lengte van de lokale coördinaat moet in het bereik [0, 1] liggen."; TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage); } [Test] [TestCase(double.NaN)] [TestCase(-1e-3, Description = "Valid ExitPointL due to rounding to 0.0")] - [TestCase(0.994)] + [TestCase(0.1004)] [TestCase(0.50)] public void ExitPointL_SetToNew_ValueIsRounded(double exitPointValue) { @@ -259,15 +259,15 @@ TestDelegate call = () => input.EntryPointL = (RoundedDouble)value; // Assert - var expectedMessage = "Kan geen hoogte bepalen. De lokale coördinaat moet in het bereik [0, 1] liggen."; + var expectedMessage = "De lengte van de lokale coördinaat moet in het bereik [0, 1] liggen."; TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage); } [Test] [TestCase(double.NaN)] [TestCase(-1e-3, Description = "Valid EntryPointL due to rounding to 0.0")] [TestCase(0.005)] - [TestCase(0.994)] + [TestCase(0.1004)] [TestCase(0.50)] public void EntryPointL_SetToNew_ValueIsRounded(double entryPointValue) { Index: Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/RingtoetsPipingSurfaceLineTest.cs =================================================================== diff -u -r35db69dfe64b7e7deeaf9ef85d4df42ff6009b11 -r619da07034480d4ba9e59fe0bea2dd06d83963e0 --- Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/RingtoetsPipingSurfaceLineTest.cs (.../RingtoetsPipingSurfaceLineTest.cs) (revision 35db69dfe64b7e7deeaf9ef85d4df42ff6009b11) +++ Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/RingtoetsPipingSurfaceLineTest.cs (.../RingtoetsPipingSurfaceLineTest.cs) (revision 619da07034480d4ba9e59fe0bea2dd06d83963e0) @@ -267,8 +267,8 @@ [Test] [TestCase(-1)] - [TestCase(-1e-6)] - [TestCase(3.1 + 1e-6)] + [TestCase(-5e-3)] + [TestCase(3.1 + 5e-3)] [TestCase(4.0)] public void GetZAtL_SurfaceLineDoesNotContainsPointAtL_ThrowsArgumentOutOfRange(double l) { @@ -633,7 +633,7 @@ [TestCase(1.375)] [TestCase(-0.005)] [TestCase(-5)] - public void ValidateInRange_PointNotInRange_ThrowsArgumentOutOfRangeException(double invalidValue) + public void ValidateInRange_PointNotInRange_ReturnsFalse(double invalidValue) { // Setup var testX = 1.0; @@ -644,18 +644,24 @@ CreateTestGeometry(testPoint, surfaceLine); // Call - TestDelegate call = () => surfaceLine.ValidateInRange((RoundedDouble) invalidValue, surfaceLine.ProjectGeometryToLZ().ToArray()); + bool valid = surfaceLine.ValidateInRange(invalidValue); // 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); + 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] [TestCase(-0e-3)] [TestCase(1.37)] [TestCase(1.0)] - public void ValidateInRange_PointInRange_DoesNotThrow(double validValue) + public void ValidateInRange_PointInRange_ReturnsTrue(double validValue) { // Setup var testX = 1.0; @@ -666,10 +672,10 @@ CreateTestGeometry(testPoint, surfaceLine); // Call - TestDelegate call = () => surfaceLine.ValidateInRange((RoundedDouble) validValue, surfaceLine.ProjectGeometryToLZ().ToArray()); + bool valid = surfaceLine.ValidateInRange(validValue); // Assert - Assert.DoesNotThrow(call); + Assert.IsTrue(valid); } private static void CreateTestGeometry(Point3D testPoint, RingtoetsPipingSurfaceLine surfaceLine) Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/PropertyClasses/PipingInputContextPropertiesTest.cs =================================================================== diff -u -r35db69dfe64b7e7deeaf9ef85d4df42ff6009b11 -r619da07034480d4ba9e59fe0bea2dd06d83963e0 --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/PropertyClasses/PipingInputContextPropertiesTest.cs (.../PipingInputContextPropertiesTest.cs) (revision 35db69dfe64b7e7deeaf9ef85d4df42ff6009b11) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/PropertyClasses/PipingInputContextPropertiesTest.cs (.../PipingInputContextPropertiesTest.cs) (revision 619da07034480d4ba9e59fe0bea2dd06d83963e0) @@ -474,7 +474,7 @@ TestDelegate call = () => properties.EntryPointL = (RoundedDouble)(-15.0); // Assert - var expectedMessage = string.Format("Kan geen hoogte bepalen. De lokale coördinaat moet in het bereik [{0}, {1}] liggen.", 0, 4); + var expectedMessage = "De lengte van de lokale coördinaat moet in het bereik [0, 4] liggen."; TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage); mocks.VerifyAll(); // No observer notified @@ -514,7 +514,7 @@ TestDelegate call = () => properties.ExitPointL = (RoundedDouble) 10.0; // Assert - var expectedMessage = string.Format("Kan geen hoogte bepalen. De lokale coördinaat moet in het bereik [{0}, {1}] liggen.", 0, 4); + var expectedMessage = "De lengte van de lokale coördinaat moet in het bereik [0, 4] liggen."; TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage); mocks.VerifyAll(); // No observer notified Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Views/PipingCalculationRowTest.cs =================================================================== diff -u -r35db69dfe64b7e7deeaf9ef85d4df42ff6009b11 -r619da07034480d4ba9e59fe0bea2dd06d83963e0 --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Views/PipingCalculationRowTest.cs (.../PipingCalculationRowTest.cs) (revision 35db69dfe64b7e7deeaf9ef85d4df42ff6009b11) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Views/PipingCalculationRowTest.cs (.../PipingCalculationRowTest.cs) (revision 619da07034480d4ba9e59fe0bea2dd06d83963e0) @@ -337,7 +337,7 @@ TestDelegate call = () => row.EntryPointL = (RoundedDouble) newValue; // Assert - var expectedMessage = string.Format("Kan geen hoogte bepalen. De lokale coördinaat moet in het bereik [{0}, {1}] liggen.", 0, 1); + var expectedMessage = "De lengte van de lokale coördinaat moet in het bereik [0, 1] liggen."; TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage); mocks.VerifyAll(); // No observer notified } @@ -410,7 +410,7 @@ TestDelegate call = () => row.ExitPointL = (RoundedDouble)newValue; // Assert - var expectedMessage = string.Format("Kan geen hoogte bepalen. De lokale coördinaat moet in het bereik [{0}, {1}] liggen.", 0, 1); + var expectedMessage = "De lengte van de lokale coördinaat moet in het bereik [0, 1] liggen."; TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage); mocks.VerifyAll(); // No observer notified } Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Views/PipingCalculationsViewTest.cs =================================================================== diff -u -r35db69dfe64b7e7deeaf9ef85d4df42ff6009b11 -r619da07034480d4ba9e59fe0bea2dd06d83963e0 --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Views/PipingCalculationsViewTest.cs (.../PipingCalculationsViewTest.cs) (revision 35db69dfe64b7e7deeaf9ef85d4df42ff6009b11) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Views/PipingCalculationsViewTest.cs (.../PipingCalculationsViewTest.cs) (revision 619da07034480d4ba9e59fe0bea2dd06d83963e0) @@ -919,7 +919,7 @@ dataGridView.Rows[0].Cells[cellIndex].Value = (RoundedDouble)newValue; // Assert - var expectedMessage = string.Format("Kan geen hoogte bepalen. De lokale coördinaat moet in het bereik [{0}, {1}] liggen.", 0, 10); + var expectedMessage = "De lengte van de lokale coördinaat moet in het bereik [0, 10] liggen."; Assert.AreEqual(expectedMessage, dataGridView.Rows[0].ErrorText); mocks.VerifyAll(); // No observer notified } Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Views/PipingFailureMechanismViewTest.cs =================================================================== diff -u -rf04895089d34bddb618db8c7001c574428be10c6 -r619da07034480d4ba9e59fe0bea2dd06d83963e0 --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Views/PipingFailureMechanismViewTest.cs (.../PipingFailureMechanismViewTest.cs) (revision f04895089d34bddb618db8c7001c574428be10c6) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Views/PipingFailureMechanismViewTest.cs (.../PipingFailureMechanismViewTest.cs) (revision 619da07034480d4ba9e59fe0bea2dd06d83963e0) @@ -362,7 +362,7 @@ surfaceLine.SetGeometry(new Collection { new Point3D(1, 2, 3), - new Point3D(1, 2, 3) + new Point3D(4, 5, 6) }); pipingFailureMechanism.SurfaceLines.Add(surfaceLine);