Index: Riskeer/Piping/src/Riskeer.Piping.Data/PipingCalculationExtensions.cs
===================================================================
diff -u
--- Riskeer/Piping/src/Riskeer.Piping.Data/PipingCalculationExtensions.cs (revision 0)
+++ Riskeer/Piping/src/Riskeer.Piping.Data/PipingCalculationExtensions.cs (revision ccb60a944093b408bf2af4ecbefc3ade9ff5700b)
@@ -0,0 +1,54 @@
+// Copyright (C) Stichting Deltares 2019. All rights reserved.
+//
+// This file is part of Riskeer.
+//
+// Riskeer is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+//
+// All names, logos, and references to "Deltares" are registered trademarks of
+// 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 Riskeer.Piping.Primitives;
+
+namespace Riskeer.Piping.Data
+{
+ ///
+ /// Defines extension methods dealing with instances.
+ ///
+ public static class PipingCalculationExtensions
+ {
+ ///
+ /// Determines if the surface line of a calculation is intersecting with the section reference line.
+ ///
+ /// The piping calculation containing the surface line.
+ /// The line segments that define the reference line.
+ /// true when intersecting. false otherwise.
+ /// Thrown when contains no elements.
+ public static bool IsSurfaceLineIntersectionWithReferenceLineInSection(this IPipingCalculation pipingCalculation, IEnumerable lineSegments)
+ {
+ PipingSurfaceLine surfaceLine = pipingCalculation?.InputParameters.SurfaceLine;
+ if (surfaceLine == null)
+ {
+ return false;
+ }
+
+ double minimalDistance = lineSegments.Min(segment => segment.GetEuclideanDistanceToPoint(surfaceLine.ReferenceLineIntersectionWorldPoint));
+ return minimalDistance < 1e-6;
+ }
+ }
+}
\ No newline at end of file
Fisheye: Tag ccb60a944093b408bf2af4ecbefc3ade9ff5700b refers to a dead (removed) revision in file `Riskeer/Piping/src/Riskeer.Piping.Data/PipingCalculationScenarioExtensions.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Index: Riskeer/Piping/test/Riskeer.Piping.Data.Test/PipingCalculationExtensionsTest.cs
===================================================================
diff -u
--- Riskeer/Piping/test/Riskeer.Piping.Data.Test/PipingCalculationExtensionsTest.cs (revision 0)
+++ Riskeer/Piping/test/Riskeer.Piping.Data.Test/PipingCalculationExtensionsTest.cs (revision ccb60a944093b408bf2af4ecbefc3ade9ff5700b)
@@ -0,0 +1,161 @@
+// Copyright (C) Stichting Deltares 2019. All rights reserved.
+//
+// This file is part of Riskeer.
+//
+// Riskeer is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+//
+// All names, logos, and references to "Deltares" are registered trademarks of
+// 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 Riskeer.Common.Data.AssessmentSection;
+using Riskeer.Piping.Data.SemiProbabilistic;
+using Riskeer.Piping.Primitives;
+
+namespace Riskeer.Piping.Data.Test
+{
+ [TestFixture]
+ public class PipingCalculationExtensionsTest
+ {
+ [Test]
+ public void IsSurfaceLineIntersectionWithReferenceLineInSection_SurfaceLineNull_ReturnsFalse()
+ {
+ // Setup
+ var calculation = new SemiProbabilisticPipingCalculationScenario(new GeneralPipingInput());
+
+ // Call
+ bool intersects = calculation.IsSurfaceLineIntersectionWithReferenceLineInSection(Enumerable.Empty());
+
+ // Assert
+ Assert.IsFalse(intersects);
+ }
+
+ [Test]
+ public void IsSurfaceLineIntersectionWithReferenceLineInSection_EmptySegmentCollection_ThrowsInvalidOperationException()
+ {
+ // Setup
+ var surfaceLine = new PipingSurfaceLine(string.Empty)
+ {
+ 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 SemiProbabilisticPipingCalculationScenario(new GeneralPipingInput())
+ {
+ InputParameters =
+ {
+ SurfaceLine = surfaceLine
+ }
+ };
+
+ // Call
+ TestDelegate call = () => calculation.IsSurfaceLineIntersectionWithReferenceLineInSection(Enumerable.Empty());
+
+ // Assert
+ Assert.Throws(call);
+ }
+
+ [Test]
+ public void IsSurfaceLineIntersectionWithReferenceLineInSection_SurfaceLineIntersectsReferenceline_ReturnsTrue()
+ {
+ // Setup
+ var surfaceLine = new PipingSurfaceLine(string.Empty)
+ {
+ 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 SemiProbabilisticPipingCalculationScenario(new GeneralPipingInput())
+ {
+ InputParameters =
+ {
+ SurfaceLine = surfaceLine
+ }
+ };
+
+ IEnumerable lineSegments = Math2D.ConvertPointsToLineSegments(referenceLine.Points);
+
+ // Call
+ bool intersects = calculation.IsSurfaceLineIntersectionWithReferenceLineInSection(lineSegments);
+
+ // Assert
+ Assert.IsTrue(intersects);
+ }
+
+ [Test]
+ public void IsSurfaceLineIntersectionWithReferenceLineInSection_SurfaceLineDoesNotIntersectReferenceline_ReturnsFalse()
+ {
+ // Setup
+ var surfaceLine = new PipingSurfaceLine(string.Empty)
+ {
+ 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 SemiProbabilisticPipingCalculationScenario(new GeneralPipingInput())
+ {
+ InputParameters =
+ {
+ SurfaceLine = surfaceLine
+ }
+ };
+
+ IEnumerable lineSegments = Math2D.ConvertPointsToLineSegments(referenceLine.Points);
+
+ // Call
+ bool intersects = calculation.IsSurfaceLineIntersectionWithReferenceLineInSection(lineSegments);
+
+ // Assert
+ Assert.IsFalse(intersects);
+ }
+ }
+}
\ No newline at end of file
Fisheye: Tag ccb60a944093b408bf2af4ecbefc3ade9ff5700b refers to a dead (removed) revision in file `Riskeer/Piping/test/Riskeer.Piping.Data.Test/PipingCalculationScenarioExtensionsTest.cs'.
Fisheye: No comparison available. Pass `N' to diff?