Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Data/SoilProfileUnderSurfaceLineFactory.cs =================================================================== diff -u -rd47809e3a8fadff2be5b10056b79b16dc27eeca2 -r376649a985f9523e6ecac956b3abd39ed1a64369 --- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Data/SoilProfileUnderSurfaceLineFactory.cs (.../SoilProfileUnderSurfaceLineFactory.cs) (revision d47809e3a8fadff2be5b10056b79b16dc27eeca2) +++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Data/SoilProfileUnderSurfaceLineFactory.cs (.../SoilProfileUnderSurfaceLineFactory.cs) (revision 376649a985f9523e6ecac956b3abd39ed1a64369) @@ -29,8 +29,18 @@ namespace Ringtoets.MacroStabilityInwards.Data { - public class SoilProfileUnderSurfaceLineFactory + /// + /// Class for constructing soil profiles for which the geometry of the layers lay under a surface line. + /// + public static class SoilProfileUnderSurfaceLineFactory { + /// + /// Creates a new . + /// + /// The soil profile containing layers under the . + /// The surface line for which determines the top of the . + /// A new containing geometries from the + /// under the . public static SoilProfileUnderSurfaceLine Create(MacroStabilityInwardsSoilProfile1D soilProfile, RingtoetsMacroStabilityInwardsSurfaceLine surfaceLine) { if (soilProfile == null) @@ -49,6 +59,33 @@ return GeometriesToIntersections(layerGeometries, surfaceLineGeometry); } + /// + /// Creates a new . + /// + /// The soil profile containing layers. + /// A new containing geometries from the + /// . + public static SoilProfileUnderSurfaceLine Create(MacroStabilityInwardsSoilProfile2D soilProfile) + { + if (soilProfile == null) + { + throw new ArgumentNullException(nameof(soilProfile)); + } + + IList layersUnderSurfaceLine = new List(); + + foreach (var layer in soilProfile.Layers) + { + layersUnderSurfaceLine.Add(new SoilLayerUnderSurfaceLine(RingToPoints(layer.OuterRing), layer.Holes.Select(RingToPoints), layer.Properties)); + } + return new SoilProfileUnderSurfaceLine(layersUnderSurfaceLine); + } + + private static Point2D[] RingToPoints(Ring ring) + { + return ring.Points.ToArray(); + } + private static SoilProfileUnderSurfaceLine GeometriesToIntersections(IEnumerable layerGeometries, IEnumerable surfaceLineGeometry) { var collection = new Collection(); @@ -132,23 +169,30 @@ public class SoilLayerUnderSurfaceLine { - public SoilLayerUnderSurfaceLine(Point2D[] outerLoop, SoilLayerProperties properties) + public SoilLayerUnderSurfaceLine(Point2D[] outerRing, SoilLayerProperties properties) + : this(outerRing, Enumerable.Empty(), properties) {} + + public SoilLayerUnderSurfaceLine(Point2D[] outerRing, IEnumerable holes, SoilLayerProperties properties) { - if (outerLoop == null) + if (outerRing == null) { - throw new ArgumentNullException(nameof(outerLoop)); + throw new ArgumentNullException(nameof(outerRing)); } + if (holes == null) + { + throw new ArgumentNullException(nameof(holes)); + } if (properties == null) { throw new ArgumentNullException(nameof(properties)); } - OuterLoop = outerLoop; - InnerLoops = Enumerable.Empty(); + OuterRing = outerRing; + Holes = holes; Properties = properties; } - public Point2D[] OuterLoop { get; } - public IEnumerable InnerLoops { get; } + public Point2D[] OuterRing { get; } + public IEnumerable Holes { get; } public SoilLayerProperties Properties { get; } } } \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Primitives/MacroStabilityInwardsSoilLayer2D.cs =================================================================== diff -u -rec27d9f02dc27c2829ed45788fae7d5923d63d3d -r376649a985f9523e6ecac956b3abd39ed1a64369 --- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Primitives/MacroStabilityInwardsSoilLayer2D.cs (.../MacroStabilityInwardsSoilLayer2D.cs) (revision ec27d9f02dc27c2829ed45788fae7d5923d63d3d) +++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Primitives/MacroStabilityInwardsSoilLayer2D.cs (.../MacroStabilityInwardsSoilLayer2D.cs) (revision 376649a985f9523e6ecac956b3abd39ed1a64369) @@ -19,10 +19,7 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. -using System; -using System.Drawing; using System.Linq; -using Core.Common.Base.Geometry; namespace Ringtoets.MacroStabilityInwards.Primitives { Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Primitives/MacroStabilityInwardsSoilProfile1D.cs =================================================================== diff -u -rec27d9f02dc27c2829ed45788fae7d5923d63d3d -r376649a985f9523e6ecac956b3abd39ed1a64369 --- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Primitives/MacroStabilityInwardsSoilProfile1D.cs (.../MacroStabilityInwardsSoilProfile1D.cs) (revision ec27d9f02dc27c2829ed45788fae7d5923d63d3d) +++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Primitives/MacroStabilityInwardsSoilProfile1D.cs (.../MacroStabilityInwardsSoilProfile1D.cs) (revision 376649a985f9523e6ecac956b3abd39ed1a64369) @@ -32,9 +32,11 @@ public class MacroStabilityInwardsSoilProfile1D : ISoilProfile { private MacroStabilityInwardsSoilLayer1D[] layers; + private string name; /// - /// Creates a new instance ofL , with the given , and . + /// Creates a new instance ofL , with the given , + /// and . /// A new collection is created for and used in the . /// /// The name of the profile. @@ -44,7 +46,8 @@ /// to build this instance. /// Identifier of the profile. /// Thrown when contains no layers. - /// Thrown when is null. + /// Thrown when or + /// is null. public MacroStabilityInwardsSoilProfile1D(string name, double bottom, IEnumerable layers, SoilProfileType sourceProfileType, long soilProfileId) { Name = name; @@ -67,7 +70,21 @@ /// /// Gets the name of . /// - public string Name { get; } + public string Name + { + get + { + return name; + } + private set + { + if (value == null) + { + throw new ArgumentNullException(nameof(value)); + } + name = value; + } + } /// /// Gets an ordered (by , descending) of Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Primitives/MacroStabilityInwardsSoilProfile2D.cs =================================================================== diff -u -rec27d9f02dc27c2829ed45788fae7d5923d63d3d -r376649a985f9523e6ecac956b3abd39ed1a64369 --- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Primitives/MacroStabilityInwardsSoilProfile2D.cs (.../MacroStabilityInwardsSoilProfile2D.cs) (revision ec27d9f02dc27c2829ed45788fae7d5923d63d3d) +++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Primitives/MacroStabilityInwardsSoilProfile2D.cs (.../MacroStabilityInwardsSoilProfile2D.cs) (revision 376649a985f9523e6ecac956b3abd39ed1a64369) @@ -32,9 +32,11 @@ public class MacroStabilityInwardsSoilProfile2D : ISoilProfile { private MacroStabilityInwardsSoilLayer2D[] layers; + private string name; /// - /// Creates a new instance ofL , with the given and . + /// Creates a new instance ofL , with the given + /// and . /// A new collection is created for and used in the . /// /// The name of the profile. @@ -43,7 +45,8 @@ /// to build this instance. /// Identifier of the profile. /// Thrown when contains no layers. - /// Thrown when is null. + /// Thrown when or + /// is null. public MacroStabilityInwardsSoilProfile2D(string name, IEnumerable layers, SoilProfileType sourceProfileType, long soilProfileId) { Name = name; @@ -60,7 +63,21 @@ /// /// Gets the name of . /// - public string Name { get; } + public string Name + { + get + { + return name; + } + private set + { + if (value == null) + { + throw new ArgumentNullException(nameof(value)); + } + name = value; + } + } /// /// Gets an of for Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Primitives/Ring.cs =================================================================== diff -u -r669e99259a7cc575b5df2be2c0ea7105d9edcbcf -r376649a985f9523e6ecac956b3abd39ed1a64369 --- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Primitives/Ring.cs (.../Ring.cs) (revision 669e99259a7cc575b5df2be2c0ea7105d9edcbcf) +++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Primitives/Ring.cs (.../Ring.cs) (revision 376649a985f9523e6ecac956b3abd39ed1a64369) @@ -21,7 +21,6 @@ using System; using System.Collections.Generic; -using System.Collections.Specialized; using System.Linq; using Core.Common.Base.Geometry; @@ -83,10 +82,9 @@ } /// - /// Validates the points collection and trims the last point from the collection - /// if it is equal to the first. + /// Validates the points collection. /// - /// The points to validate and trim if required. + /// The points to validate. /// Thrown when points is null. /// Thrown when points contains less than 2 unique points. private void ValidateAndTrimPoints(IEnumerable points) Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Data.Test/SoilProfileUnderSurfaceLineFactory.cs =================================================================== diff -u -rd47809e3a8fadff2be5b10056b79b16dc27eeca2 -r376649a985f9523e6ecac956b3abd39ed1a64369 --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Data.Test/SoilProfileUnderSurfaceLineFactory.cs (.../SoilProfileUnderSurfaceLineFactory.cs) (revision d47809e3a8fadff2be5b10056b79b16dc27eeca2) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Data.Test/SoilProfileUnderSurfaceLineFactory.cs (.../SoilProfileUnderSurfaceLineFactory.cs) (revision 376649a985f9523e6ecac956b3abd39ed1a64369) @@ -20,8 +20,10 @@ // All rights reserved. using System; +using System.Collections.Generic; using System.Linq; using Core.Common.Base.Geometry; +using Core.Common.TestUtil; using NUnit.Framework; using Ringtoets.MacroStabilityInwards.Primitives; @@ -31,7 +33,7 @@ public class SoilProfileUnderSurfaceLineFactoryTest { [Test] - public void Create_SoilProfileNull_ThrowArgumentNullException() + public void Create_SoilProfile1DNull_ThrowArgumentNullException() { // Setup var surfaceLine = new RingtoetsMacroStabilityInwardsSurfaceLine(); @@ -62,6 +64,17 @@ } [Test] + public void Create_SoilProfile2DNull_ThrowArgumentNullException() + { + // Call + TestDelegate test = () => SoilProfileUnderSurfaceLineFactory.Create(null); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("soilProfile", exception.ParamName); + } + + [Test] public void Create_SurfaceLineOnTopOrAboveSoilLayer_ReturnsSoilLayerPointsAsRectangle() { // Setup @@ -89,7 +102,7 @@ new Point2D(2, 2), new Point2D(0, 2), new Point2D(0, 3.2) - }, areas.LayersUnderSurfaceLine.ElementAt(0).OuterLoop); + }, areas.LayersUnderSurfaceLine.ElementAt(0).OuterRing); } [Test] @@ -148,7 +161,7 @@ new Point2D(2, bottom), new Point2D(0, bottom), new Point2D(0, top) - }, areas.LayersUnderSurfaceLine.ElementAt(0).OuterLoop); + }, areas.LayersUnderSurfaceLine.ElementAt(0).OuterRing); } [Test] @@ -186,7 +199,7 @@ new Point2D(2, bottom), new Point2D(0, bottom), new Point2D(0, top) - }, areas.LayersUnderSurfaceLine.ElementAt(0).OuterLoop); + }, areas.LayersUnderSurfaceLine.ElementAt(0).OuterRing); } [Test] @@ -221,7 +234,7 @@ new Point2D(2, top), new Point2D(2, bottom), new Point2D(0, bottom) - }, areas.LayersUnderSurfaceLine.ElementAt(0).OuterLoop); + }, areas.LayersUnderSurfaceLine.ElementAt(0).OuterRing); } [Test] @@ -256,7 +269,7 @@ new Point2D(2, bottom), new Point2D(0, bottom), new Point2D(0, top) - }, areas.LayersUnderSurfaceLine.ElementAt(0).OuterLoop); + }, areas.LayersUnderSurfaceLine.ElementAt(0).OuterRing); } [Test] @@ -289,14 +302,68 @@ new Point2D(3, bottom), new Point2D(0, bottom), new Point2D(0, top) - }, areas.LayersUnderSurfaceLine.ElementAt(0).OuterLoop); + }, areas.LayersUnderSurfaceLine.ElementAt(0).OuterRing); CollectionAssert.AreEqual(new[] { new Point2D(5, bottom), new Point2D(7, top), new Point2D(8, top), new Point2D(8, bottom) - }, areas.LayersUnderSurfaceLine.ElementAt(1).OuterLoop); + }, areas.LayersUnderSurfaceLine.ElementAt(1).OuterRing); } + + [Test] + public void Create_SoilProfile2DWithOuterRingAndHoles_ReturnsEqualGeometries() + { + // Setup + Ring outerRingA = CreateRing(21); + Ring outerRingB = CreateRing(12); + var holesA = new[] + { + CreateRing(4), + CreateRing(7) + }; + var holesB = new[] + { + CreateRing(4), + CreateRing(7), + CreateRing(2) + }; + IEnumerable layers = new[] + { + new MacroStabilityInwardsSoilLayer2D(outerRingA, holesA), + new MacroStabilityInwardsSoilLayer2D(outerRingB, holesB) + }; + var profile = new MacroStabilityInwardsSoilProfile2D("name", layers, SoilProfileType.SoilProfile2D, 0); + + // Call + SoilProfileUnderSurfaceLine profileUnderSurfaceLine = SoilProfileUnderSurfaceLineFactory.Create(profile); + + // Assert + Assert.AreEqual(2, profileUnderSurfaceLine.LayersUnderSurfaceLine.Count()); + CollectionAssert.AreEqual(new [] { outerRingA.Points, outerRingB.Points }, profileUnderSurfaceLine.LayersUnderSurfaceLine.Select(layer => layer.OuterRing)); + CollectionAssert.AreEqual(new [] { holesA.Select(h => h.Points), holesB.Select(h => h.Points) }, profileUnderSurfaceLine.LayersUnderSurfaceLine.Select(layer => layer.Holes)); + } + + private static Ring CreateRing(int seed) + { + var random = new Random(seed); + int x1 = random.Next(); + int y1 = random.Next(); + int x2 = x1; + int y2 = y1 + random.Next(); + int x3 = x2 + random.Next(); + int y3 = y2; + double x4 = x1 + (x3 - x1) * random.NextDouble(); + int y4 = y1; + + return new Ring(new[] + { + new Point2D(x1, y1), + new Point2D(x2, y2), + new Point2D(x3, y3), + new Point2D(x4, y4) + }); + } } } \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Primitives.Test/MacroStabilityInwardsSoilProfile1DTest.cs =================================================================== diff -u -rec27d9f02dc27c2829ed45788fae7d5923d63d3d -r376649a985f9523e6ecac956b3abd39ed1a64369 --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Primitives.Test/MacroStabilityInwardsSoilProfile1DTest.cs (.../MacroStabilityInwardsSoilProfile1DTest.cs) (revision ec27d9f02dc27c2829ed45788fae7d5923d63d3d) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Primitives.Test/MacroStabilityInwardsSoilProfile1DTest.cs (.../MacroStabilityInwardsSoilProfile1DTest.cs) (revision 376649a985f9523e6ecac956b3abd39ed1a64369) @@ -62,7 +62,7 @@ } [Test] - public void Constructor_WithNameBottomLayersEmpty_ThrowsArgumentException() + public void Constructor_LayersEmpty_ThrowsArgumentException() { // Call TestDelegate test = () => new MacroStabilityInwardsSoilProfile1D(string.Empty, double.NaN, new Collection(), SoilProfileType.SoilProfile1D, 0); @@ -72,10 +72,21 @@ TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); } + [Test] - public void Constructor_WithNameBottomLayersNull_ThrowsArgumentNullException() + public void Constructor_NameNull_ThrowsArgumentNullException() { // Call + TestDelegate test = () => new MacroStabilityInwardsSoilProfile2D(null, new Collection(), SoilProfileType.SoilProfile2D, 0); + + // Assert + Assert.Throws(test); + } + + [Test] + public void Constructor_LayersNull_ThrowsArgumentNullException() + { + // Call TestDelegate test = () => new MacroStabilityInwardsSoilProfile1D(string.Empty, double.NaN, null, SoilProfileType.SoilProfile1D, 0); // Assert @@ -172,22 +183,6 @@ } [Test] - public void ToString_WithNullName_ReturnsStringEmpty() - { - // Setup - var profile = new MacroStabilityInwardsSoilProfile1D(null, 0.0, new[] - { - new MacroStabilityInwardsSoilLayer1D(0.0) - }, SoilProfileType.SoilProfile1D, 0); - - // Call - string text = profile.ToString(); - - // Assert - Assert.IsEmpty(text); - } - - [Test] [TestCase("")] [TestCase("some name")] public void ToString_WithName_ReturnsName(string name) Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Primitives.Test/MacroStabilityInwardsSoilProfile2DTest.cs =================================================================== diff -u -rec27d9f02dc27c2829ed45788fae7d5923d63d3d -r376649a985f9523e6ecac956b3abd39ed1a64369 --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Primitives.Test/MacroStabilityInwardsSoilProfile2DTest.cs (.../MacroStabilityInwardsSoilProfile2DTest.cs) (revision ec27d9f02dc27c2829ed45788fae7d5923d63d3d) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Primitives.Test/MacroStabilityInwardsSoilProfile2DTest.cs (.../MacroStabilityInwardsSoilProfile2DTest.cs) (revision 376649a985f9523e6ecac956b3abd39ed1a64369) @@ -36,7 +36,7 @@ [Test] [TestCase(SoilProfileType.SoilProfile1D)] [TestCase(SoilProfileType.SoilProfile2D)] - public void Constructor_WithNameLayersAndAquifer_ReturnsInstanceWithPropsAndEquivalentLayerCollection(SoilProfileType type) + public void Constructor_WithNameAndLayers_ReturnsInstanceWithPropsAndEquivalentLayerCollection(SoilProfileType type) { // Setup const string name = "Profile"; @@ -58,7 +58,7 @@ } [Test] - public void Constructor_WithNameBottomLayersEmpty_ThrowsArgumentException() + public void Constructor_LayersEmpty_ThrowsArgumentException() { // Call TestDelegate test = () => new MacroStabilityInwardsSoilProfile2D(string.Empty, new Collection(), SoilProfileType.SoilProfile2D, 0); @@ -69,30 +69,24 @@ } [Test] - public void Constructor_WithNameBottomLayersNull_ThrowsArgumentNullException() + public void Constructor_NameNull_ThrowsArgumentNullException() { // Call - TestDelegate test = () => new MacroStabilityInwardsSoilProfile2D(string.Empty, null, SoilProfileType.SoilProfile2D, 0); + TestDelegate test = () => new MacroStabilityInwardsSoilProfile2D(null, new Collection(), SoilProfileType.SoilProfile2D, 0); // Assert - const string expectedMessage = "Geen lagen gevonden voor de ondergrondschematisatie."; - TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); + Assert.Throws(test); } [Test] - public void ToString_WithNullName_ReturnsStringEmpty() + public void Constructor_LayersNull_ThrowsArgumentNullException() { - // Setup - var profile = new MacroStabilityInwardsSoilProfile2D(null, new[] - { - CreateRandomLayer(2) - }, SoilProfileType.SoilProfile2D, 0); - // Call - string text = profile.ToString(); + TestDelegate test = () => new MacroStabilityInwardsSoilProfile2D(string.Empty, null, SoilProfileType.SoilProfile2D, 0); // Assert - Assert.IsEmpty(text); + const string expectedMessage = "Geen lagen gevonden voor de ondergrondschematisatie."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); } [Test]