Index: Riskeer/ClosingStructures/src/Riskeer.ClosingStructures.Forms/Views/ClosingStructuresScenariosView.cs =================================================================== diff -u -r38a2fc76e88b63b2a680e9ceb2a77a9aa5509918 -r3b987d7e53ec6e53ce6b3200b7db1719114e2d4d --- Riskeer/ClosingStructures/src/Riskeer.ClosingStructures.Forms/Views/ClosingStructuresScenariosView.cs (.../ClosingStructuresScenariosView.cs) (revision 38a2fc76e88b63b2a680e9ceb2a77a9aa5509918) +++ Riskeer/ClosingStructures/src/Riskeer.ClosingStructures.Forms/Views/ClosingStructuresScenariosView.cs (.../ClosingStructuresScenariosView.cs) (revision 3b987d7e53ec6e53ce6b3200b7db1719114e2d4d) @@ -26,7 +26,6 @@ using Riskeer.ClosingStructures.Data; using Riskeer.Common.Data.AssessmentSection; using Riskeer.Common.Data.Calculation; -using Riskeer.Common.Data.DikeProfiles; using Riskeer.Common.Data.FailureMechanism; using Riskeer.Common.Data.Structures; using Riskeer.Common.Forms.Views; @@ -68,21 +67,11 @@ protected override IEnumerable GetScenarioRows(FailureMechanismSection failureMechanismSection) { IEnumerable lineSegments = Math2D.ConvertPointsToLineSegments(failureMechanismSection.Points); - IEnumerable> calculations = CalculationGroup.GetCalculations().OfType>() - .Where(cs => IsForeshoreProfileIntersectionWithReferenceLineInSection(cs, lineSegments)); + IEnumerable> calculations = CalculationGroup.GetCalculations() + .OfType>() + .Where(cs => cs.IsStructureIntersectionWithReferenceLineInSection(lineSegments)); return calculations.Select(c => new ClosingStructuresScenarioRow(c, FailureMechanism, assessmentSection)).ToList(); } - - private static bool IsForeshoreProfileIntersectionWithReferenceLineInSection(ICalculation calculationScenario, IEnumerable lineSegments) - { - ForeshoreProfile foreshoreProfile = calculationScenario.InputParameters.ForeshoreProfile; - if (foreshoreProfile == null) - { - return false; - } - - return lineSegments.Min(segment => segment.GetEuclideanDistanceToPoint(foreshoreProfile.WorldReferencePoint)) <= 1; - } } } \ No newline at end of file Index: Riskeer/ClosingStructures/test/Riskeer.ClosingStructures.Forms.Test/Views/ClosingStructuresScenariosViewTest.cs =================================================================== diff -u -r38a2fc76e88b63b2a680e9ceb2a77a9aa5509918 -r3b987d7e53ec6e53ce6b3200b7db1719114e2d4d --- Riskeer/ClosingStructures/test/Riskeer.ClosingStructures.Forms.Test/Views/ClosingStructuresScenariosViewTest.cs (.../ClosingStructuresScenariosViewTest.cs) (revision 38a2fc76e88b63b2a680e9ceb2a77a9aa5509918) +++ Riskeer/ClosingStructures/test/Riskeer.ClosingStructures.Forms.Test/Views/ClosingStructuresScenariosViewTest.cs (.../ClosingStructuresScenariosViewTest.cs) (revision 3b987d7e53ec6e53ce6b3200b7db1719114e2d4d) @@ -27,10 +27,10 @@ using NUnit.Framework; using Rhino.Mocks; using Riskeer.ClosingStructures.Data; +using Riskeer.ClosingStructures.Data.TestUtil; using Riskeer.ClosingStructures.Forms.Views; using Riskeer.Common.Data.AssessmentSection; using Riskeer.Common.Data.Calculation; -using Riskeer.Common.Data.DikeProfiles; using Riskeer.Common.Data.FailureMechanism; using Riskeer.Common.Data.Structures; using Riskeer.Common.Data.TestUtil; @@ -137,8 +137,8 @@ private void ShowFullyConfiguredClosingStructuresScenariosView() { - ForeshoreProfile foreshoreProfile1 = new TestForeshoreProfile(new Point2D(0.0, 0.0)); - ForeshoreProfile foreshoreProfile2 = new TestForeshoreProfile(new Point2D(5.0, 0.0)); + var structure1 = new TestClosingStructure(new Point2D(0.0, 0.0)); + var structure2 = new TestClosingStructure(new Point2D(5.0, 0.0)); var failureMechanism = new ClosingStructuresFailureMechanism(); @@ -163,15 +163,15 @@ Name = "Calculation 1", InputParameters = { - ForeshoreProfile = foreshoreProfile1 + Structure = structure1 } }, new StructuresCalculationScenario { Name = "Calculation 2", InputParameters = { - ForeshoreProfile = foreshoreProfile2 + Structure = structure2 }, Output = new TestStructuresOutput(0.2) } Index: Riskeer/Common/src/Riskeer.Common.Data/Structures/StructuresCalculationScenarioExtensions.cs =================================================================== diff -u --- Riskeer/Common/src/Riskeer.Common.Data/Structures/StructuresCalculationScenarioExtensions.cs (revision 0) +++ Riskeer/Common/src/Riskeer.Common.Data/Structures/StructuresCalculationScenarioExtensions.cs (revision 3b987d7e53ec6e53ce6b3200b7db1719114e2d4d) @@ -0,0 +1,65 @@ +// 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; + +namespace Riskeer.Common.Data.Structures +{ + /// + /// Defines extension methods dealing with instances. + /// + public static class StructuresCalculationScenarioExtensions + { + /// + /// Determines if the structure of a calculation is intersecting with the section reference line. + /// + /// The calculation scenario containing the structure. + /// The line segments that define the reference line. + /// true when intersecting. false otherwise. + /// Thrown when any parameter is null. + /// Thrown when contains no elements. + public static bool IsStructureIntersectionWithReferenceLineInSection(this StructuresCalculationScenario calculationScenario, + IEnumerable lineSegments) + where TStructuresInput : IStructuresCalculationInput, new() + { + if (calculationScenario == null) + { + throw new ArgumentNullException(nameof(calculationScenario)); + } + + if (lineSegments == null) + { + throw new ArgumentNullException(nameof(lineSegments)); + } + + StructureBase structure = calculationScenario.InputParameters.Structure; + if (structure == null) + { + return false; + } + + return lineSegments.Min(segment => segment.GetEuclideanDistanceToPoint(structure.Location)) <= 1; + } + } +} Index: Riskeer/Common/test/Riskeer.Common.Data.Test/Structures/StructuresCalculationScenarioExtensionsTest.cs =================================================================== diff -u --- Riskeer/Common/test/Riskeer.Common.Data.Test/Structures/StructuresCalculationScenarioExtensionsTest.cs (revision 0) +++ Riskeer/Common/test/Riskeer.Common.Data.Test/Structures/StructuresCalculationScenarioExtensionsTest.cs (revision 3b987d7e53ec6e53ce6b3200b7db1719114e2d4d) @@ -0,0 +1,159 @@ +// 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.Common.Data.Structures; +using Riskeer.Common.Data.TestUtil; + +namespace Riskeer.Common.Data.Test.Structures +{ + [TestFixture] + public class StructuresCalculationScenarioExtensionsTest + { + [Test] + public void IsStructureIntersectionWithReferenceLineInSection_CalculationScenarioNull_ThrowsArgumentNullException() + { + // Call + void Call() => StructuresCalculationScenarioExtensions.IsStructureIntersectionWithReferenceLineInSection(null, Enumerable.Empty()); + + // Assert + var exception = Assert.Throws(Call); + Assert.AreEqual("calculationScenario", exception.ParamName); + } + + [Test] + public void IsStructureIntersectionWithReferenceLineInSection_LineSegmentsNull_ThrowsArgumentNullException() + { + // Setup + var calculation = new TestStructuresCalculationScenario(); + + // Call + void Call() => calculation.IsStructureIntersectionWithReferenceLineInSection(null); + + // Assert + var exception = Assert.Throws(Call); + Assert.AreEqual("lineSegments", exception.ParamName); + } + + [Test] + public void IsStructureIntersectionWithReferenceLineInSection_CalculationWithoutStructure_ReturnsFalse() + { + // Setup + var calculation = new TestStructuresCalculationScenario(); + + // Call + bool intersects = calculation.IsStructureIntersectionWithReferenceLineInSection(Enumerable.Empty()); + + // Assert + Assert.IsFalse(intersects); + } + + [Test] + public void IsStructureIntersectionWithReferenceLineInSection_EmptySegmentCollection_ThrowsInvalidOperationException() + { + // Setup + var structure = new TestStructure(new Point2D(0.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 TestStructuresCalculationScenario + { + InputParameters = + { + Structure = structure + } + }; + + // Call + void Call() => calculation.IsStructureIntersectionWithReferenceLineInSection(Enumerable.Empty()); + + // Assert + Assert.Throws(Call); + } + + [Test] + public void IsStructureIntersectionWithReferenceLineInSection_StructureIntersectsReferenceLine_ReturnsTrue() + { + // Setup + var structure = new TestStructure(new Point2D(0.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 TestStructuresCalculationScenario + { + InputParameters = + { + Structure = structure + } + }; + + IEnumerable lineSegments = Math2D.ConvertPointsToLineSegments(referenceLine.Points); + + // Call + bool intersects = calculation.IsStructureIntersectionWithReferenceLineInSection(lineSegments); + + // Assert + Assert.IsTrue(intersects); + } + + [Test] + public void IsStructureIntersectionWithReferenceLineInSection_StructureDoesNotIntersectsReferenceLine_ReturnsFalse() + { + // Setup + var structure = new TestStructure(new Point2D(0.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 TestStructuresCalculationScenario + { + InputParameters = + { + Structure = structure + } + }; + + IEnumerable lineSegments = Math2D.ConvertPointsToLineSegments(referenceLine.Points); + + // Call + bool intersects = calculation.IsStructureIntersectionWithReferenceLineInSection(lineSegments); + + // Assert + Assert.IsFalse(intersects); + } + } +} \ No newline at end of file Index: Riskeer/GrassCoverErosionInwards/test/Riskeer.GrassCoverErosionInwards.Data.Test/GrassCoverErosionInwardsCalculationScenarioExtensionsTest.cs =================================================================== diff -u -r701f1da16352136e08728b3521077d3252ab65ee -r3b987d7e53ec6e53ce6b3200b7db1719114e2d4d --- Riskeer/GrassCoverErosionInwards/test/Riskeer.GrassCoverErosionInwards.Data.Test/GrassCoverErosionInwardsCalculationScenarioExtensionsTest.cs (.../GrassCoverErosionInwardsCalculationScenarioExtensionsTest.cs) (revision 701f1da16352136e08728b3521077d3252ab65ee) +++ Riskeer/GrassCoverErosionInwards/test/Riskeer.GrassCoverErosionInwards.Data.Test/GrassCoverErosionInwardsCalculationScenarioExtensionsTest.cs (.../GrassCoverErosionInwardsCalculationScenarioExtensionsTest.cs) (revision 3b987d7e53ec6e53ce6b3200b7db1719114e2d4d) @@ -99,7 +99,7 @@ } [Test] - public void IsDikeProfileIntersectionWithReferenceLineInSection_DikeProfileIntersectsReferenceline_ReturnsTrue() + public void IsDikeProfileIntersectionWithReferenceLineInSection_DikeProfileIntersectsReferenceLine_ReturnsTrue() { // Setup DikeProfile dikeProfile = DikeProfileTestFactory.CreateDikeProfile(new Point2D(0.0, 0.0)); @@ -128,7 +128,7 @@ } [Test] - public void IsDikeProfileIntersectionWithReferenceLineInSection_DikeProfileDoesNotIntersectsReferenceline_ReturnsFalse() + public void IsDikeProfileIntersectionWithReferenceLineInSection_DikeProfileDoesNotIntersectsReferenceLine_ReturnsFalse() { // Setup DikeProfile dikeProfile = DikeProfileTestFactory.CreateDikeProfile(new Point2D(0.0, 0.0));