Index: Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/IPipingCalculationItemExtensionsTest.cs =================================================================== diff -u -rc7c07db38829afdc5965c331844e1d39123944ff -r1279dcba187f56c0ba96dfdb962067304e333475 --- Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/IPipingCalculationItemExtensionsTest.cs (.../IPipingCalculationItemExtensionsTest.cs) (revision c7c07db38829afdc5965c331844e1d39123944ff) +++ Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/IPipingCalculationItemExtensionsTest.cs (.../IPipingCalculationItemExtensionsTest.cs) (revision 1279dcba187f56c0ba96dfdb962067304e333475) @@ -19,10 +19,13 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System; using System.Collections.Generic; using System.Linq; - +using Core.Common.Base.Geometry; using NUnit.Framework; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Piping.Primitives; namespace Ringtoets.Piping.Data.Test { @@ -205,5 +208,147 @@ }; CollectionAssert.AreEquivalent(expectedCalculationItems, result); } + + #region IsSurfaceLineIntersectionWithReferenceLineInSection + + [Test] + public void IsSurfaceLineIntersectionWithReferenceLineInSection_IPipingCalculationItemNotPipingCalculationScenario_ReturnsFalse() + { + // Setup + var calculation = new PipingCalculation(new GeneralPipingInput(), new SemiProbabilisticPipingInput()); + + // Call + var intersects = calculation.IsSurfaceLineIntersectionWithReferenceLineInSection(Enumerable.Empty()); + + // Assert + Assert.IsFalse(intersects); + } + + [Test] + public void IsSurfaceLineIntersectionWithReferenceLineInSection_SurfaceLineNull_ReturnsFalse() + { + // Setup + var calculation = new PipingCalculationScenario(new GeneralPipingInput(), new SemiProbabilisticPipingInput()); + + // Call + var intersects = calculation.IsSurfaceLineIntersectionWithReferenceLineInSection(Enumerable.Empty()); + + // Assert + Assert.IsFalse(intersects); + } + + [Test] + public void IsSurfaceLineIntersectionWithReferenceLineInSection_EmptySegmentCollection_ThrowsInvalidOperationException() + { + // Setup + var surfaceLine = new RingtoetsPipingSurfaceLine + { + ReferenceLineIntersectionWorldPoint = new Point2D(0.0, 0.0) + }; + surfaceLine.SetGeometry(new[] + { + new Point3D(0.0, 5.0, 0.0), + new Point3D(0.0, 0.0, 1.0), + new Point3D(0.0, -5.0, 0.0) + }); + var referenceLine = new ReferenceLine(); + referenceLine.SetGeometry(new[] + { + new Point2D(0.0, 0.0), + new Point2D(10.0, 0.0) + }); + + var calculation = new PipingCalculationScenario(new GeneralPipingInput(), new SemiProbabilisticPipingInput()) + { + InputParameters = + { + SurfaceLine = surfaceLine + } + }; + + // Call + TestDelegate call = () => calculation.IsSurfaceLineIntersectionWithReferenceLineInSection(Enumerable.Empty()); + + // Assert + Assert.Throws(call); + } + + [Test] + public void IsSurfaceLineIntersectionWithReferenceLineInSection_SurfaceLineIntersectsReferenceline_ReturnsTrue() + { + // Setup + var surfaceLine = new RingtoetsPipingSurfaceLine + { + ReferenceLineIntersectionWorldPoint = new Point2D(0.0, 0.0) + }; + surfaceLine.SetGeometry(new[] + { + new Point3D(0.0, 5.0, 0.0), + new Point3D(0.0, 0.0, 1.0), + new Point3D(0.0, -5.0, 0.0) + }); + var referenceLine = new ReferenceLine(); + referenceLine.SetGeometry(new[] + { + new Point2D(0.0, 0.0), + new Point2D(10.0, 0.0) + }); + + var calculation = new PipingCalculationScenario(new GeneralPipingInput(), new SemiProbabilisticPipingInput()) + { + InputParameters = + { + SurfaceLine = surfaceLine + } + }; + + var lineSegments = Math2D.ConvertLinePointsToLineSegments(referenceLine.Points); + + // Call + var intersects = calculation.IsSurfaceLineIntersectionWithReferenceLineInSection(lineSegments); + + // Assert + Assert.IsTrue(intersects); + } + + [Test] + public void IsSurfaceLineIntersectionWithReferenceLineInSection_SurfaceLineDoesNotIntersectsReferenceline_ReturnsFalse() + { + // Setup + var surfaceLine = new RingtoetsPipingSurfaceLine + { + ReferenceLineIntersectionWorldPoint = new Point2D(0.0, 0.0) + }; + surfaceLine.SetGeometry(new[] + { + new Point3D(0.0, 5.0, 0.0), + new Point3D(0.0, 0.0, 1.0), + new Point3D(0.0, -5.0, 0.0) + }); + var referenceLine = new ReferenceLine(); + referenceLine.SetGeometry(new[] + { + new Point2D(10.0, 0.0), + new Point2D(20.0, 0.0) + }); + + var calculation = new PipingCalculationScenario(new GeneralPipingInput(), new SemiProbabilisticPipingInput()) + { + InputParameters = + { + SurfaceLine = surfaceLine + } + }; + + var lineSegments = Math2D.ConvertLinePointsToLineSegments(referenceLine.Points); + + // Call + var intersects = calculation.IsSurfaceLineIntersectionWithReferenceLineInSection(lineSegments); + + // Assert + Assert.IsFalse(intersects); + } + + #endregion } } \ No newline at end of file