Index: Ringtoets/Piping/src/Ringtoets.Piping.Forms/PipingCalculationConfigurationHelper.cs =================================================================== diff -u -rb2b9fdf365e70928a05c57966eeed30d9050e528 -rfef932cbceb323536b66ee0278471cb77393a723 --- Ringtoets/Piping/src/Ringtoets.Piping.Forms/PipingCalculationConfigurationHelper.cs (.../PipingCalculationConfigurationHelper.cs) (revision b2b9fdf365e70928a05c57966eeed30d9050e528) +++ Ringtoets/Piping/src/Ringtoets.Piping.Forms/PipingCalculationConfigurationHelper.cs (.../PipingCalculationConfigurationHelper.cs) (revision fef932cbceb323536b66ee0278471cb77393a723) @@ -111,6 +111,29 @@ .ToList(); } + /// + /// Indicates whether a stochastic soil model intersects with a surface line. + /// + /// The stochastic soil model used to match a surface line. + /// The surface line used to match a stochastic soil model. + /// true when the intersects with the ; + /// false otherwise. + /// Thrown when any input parameter is null. + public static bool DoesSoilModelGeometryIntersectWithSurfaceLineGeometry(StochasticSoilModel stochasticSoilModel, RingtoetsPipingSurfaceLine surfaceLine) + { + if (stochasticSoilModel == null) + { + throw new ArgumentNullException(nameof(stochasticSoilModel)); + } + if (surfaceLine == null) + { + throw new ArgumentNullException(nameof(surfaceLine)); + } + Segment2D[] surfaceLineSegments = Math2D.ConvertLinePointsToLineSegments(surfaceLine.Points.Select(p => new Point2D(p.X, p.Y))).ToArray(); + + return DoesSoilModelGeometryIntersectWithSurfaceLineGeometry(stochasticSoilModel, surfaceLineSegments); + } + private static CalculationGroup CreateCalculationGroup(RingtoetsPipingSurfaceLine surfaceLine, IEnumerable soilModels, GeneralPipingInput generalInput) { var calculationGroup = new CalculationGroup(surfaceLine.Name, true); @@ -128,7 +151,7 @@ private static ICalculationBase CreatePipingCalculation(RingtoetsPipingSurfaceLine surfaceLine, StochasticSoilModel stochasticSoilModel, StochasticSoilProfile stochasticSoilProfile, IEnumerable calculations, GeneralPipingInput generalInput) { - var nameBase = string.Format("{0} {1}", surfaceLine.Name, stochasticSoilProfile); + var nameBase = $"{surfaceLine.Name} {stochasticSoilProfile}"; var name = NamingHelper.GetUniqueName(calculations, nameBase, c => c.Name); return new PipingCalculationScenario(generalInput) Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/PipingCalculationConfigurationHelperTest.cs =================================================================== diff -u -rac582bc093c8a275cd9b5dc2148af313b5242062 -rfef932cbceb323536b66ee0278471cb77393a723 --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/PipingCalculationConfigurationHelperTest.cs (.../PipingCalculationConfigurationHelperTest.cs) (revision ac582bc093c8a275cd9b5dc2148af313b5242062) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/PipingCalculationConfigurationHelperTest.cs (.../PipingCalculationConfigurationHelperTest.cs) (revision fef932cbceb323536b66ee0278471cb77393a723) @@ -50,6 +50,97 @@ Assert.AreEqual(generalInput.WhitesDragCoefficient, calculationInput.InputParameters.WhitesDragCoefficient); } + [Test] + public void DoesSoilModelGeometryIntersectWithSurfaceLineGeometry_SoilModelNull_ThrowArgumentNullException() + { + // Setup + var surfaceLine = new RingtoetsPipingSurfaceLine(); + surfaceLine.SetGeometry(new[] + { + new Point3D(3.0, 5.0, 0.0), + new Point3D(3.0, 0.0, 1.0), + new Point3D(3.0, -5.0, 0.0) + }); + + // Call + TestDelegate test = () => PipingCalculationConfigurationHelper.DoesSoilModelGeometryIntersectWithSurfaceLineGeometry(null, surfaceLine); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("stochasticSoilModel", exception.ParamName); + } + + [Test] + public void DoesSoilModelGeometryIntersectWithSurfaceLineGeometry_SurfaceLineNull_ThrowArgumentNullException() + { + // Setup + var soilModel = new StochasticSoilModel(1, "A", "B"); + soilModel.Geometry.AddRange(new[] + { + new Point2D(1.0, 0.0), + new Point2D(5.0, 0.0) + }); + + // Call + TestDelegate test = () => PipingCalculationConfigurationHelper.DoesSoilModelGeometryIntersectWithSurfaceLineGeometry(soilModel, null); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("surfaceLine", exception.ParamName); + } + + [Test] + public void DoesSoilModelGeometryIntersectWithSurfaceLineGeometry_SurfacelineIntersectingSoilModel_ReturnTrue() + { + // Setup + var soilModel = new StochasticSoilModel(1, "A", "B"); + soilModel.Geometry.AddRange(new[] + { + new Point2D(1.0, 0.0), + new Point2D(5.0, 0.0) + }); + + var surfaceLine = new RingtoetsPipingSurfaceLine(); + surfaceLine.SetGeometry(new[] + { + new Point3D(3.0, 5.0, 0.0), + new Point3D(3.0, 0.0, 1.0), + new Point3D(3.0, -5.0, 0.0) + }); + + // Call + bool intersecting = PipingCalculationConfigurationHelper.DoesSoilModelGeometryIntersectWithSurfaceLineGeometry(soilModel, surfaceLine); + + // Assert + Assert.IsTrue(intersecting); + } + + [Test] + public void DoesSoilModelGeometryIntersectWithSurfaceLineGeometry_SurfacelineNotIntersectingSoilModel_ReturnFalse() + { + // Setup + var soilModel = new StochasticSoilModel(1, "A", "B"); + soilModel.Geometry.AddRange(new[] + { + new Point2D(1.0, 0.0), + new Point2D(5.0, 0.0) + }); + + var surfaceLine = new RingtoetsPipingSurfaceLine(); + surfaceLine.SetGeometry(new[] + { + new Point3D(0.0, 1.0, 0.0), + new Point3D(2.5, 1.0, 1.0), + new Point3D(5.0, 1.0, 0.0) + }); + + // Call + bool intersecting = PipingCalculationConfigurationHelper.DoesSoilModelGeometryIntersectWithSurfaceLineGeometry(soilModel, surfaceLine); + + // Assert + Assert.IsFalse(intersecting); + } + #region GetPipingSoilProfilesForSurfaceLine [Test]