Index: Core/Common/test/Core.Common.TestUtil/Point2DComparerWithTolerance.cs =================================================================== diff -u -r67284323e2785c651633d9c52049ba12a9c70e6a -re0472e1b583bd29a675a1dff5ff95e0ffdd0bb82 --- Core/Common/test/Core.Common.TestUtil/Point2DComparerWithTolerance.cs (.../Point2DComparerWithTolerance.cs) (revision 67284323e2785c651633d9c52049ba12a9c70e6a) +++ Core/Common/test/Core.Common.TestUtil/Point2DComparerWithTolerance.cs (.../Point2DComparerWithTolerance.cs) (revision e0472e1b583bd29a675a1dff5ff95e0ffdd0bb82) @@ -27,7 +27,7 @@ { /// /// This class compares the distance of two instances to determine - /// if there are equal to each other or not. This class shouldn't be used to sort point + /// whether they're equal to each other or not. This class shouldn't be used to sort point /// instances. /// public class Point2DComparerWithTolerance : IComparer, IComparer Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.KernelWrapper/Creators/MacroStabilityInwardsSoilProfileCreator.cs =================================================================== diff -u --- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.KernelWrapper/Creators/MacroStabilityInwardsSoilProfileCreator.cs (revision 0) +++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.KernelWrapper/Creators/MacroStabilityInwardsSoilProfileCreator.cs (revision e0472e1b583bd29a675a1dff5ff95e0ffdd0bb82) @@ -0,0 +1,155 @@ +// Copyright (C) Stichting Deltares 2017. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets 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 Deltares.WTIStability.Data.Geo; +using Ringtoets.MacroStabilityInwards.Primitives; + +namespace Ringtoets.MacroStabilityInwards.KernelWrapper.Creators +{ + /// + /// Creates instances which are required by the . + /// + internal static class MacroStabilityInwardsSoilProfileCreator + { + private static GeometryData geometryData; + + /// + /// Creates a with the given + /// which can be used in the . + /// + /// The data to use in the . + /// A new with the . + /// Thrown when is null. + public static SoilProfile2D Create(IDictionary layersWithSoils) + { + if (layersWithSoils == null) + { + throw new ArgumentNullException(nameof(layersWithSoils)); + } + + geometryData = new GeometryData(); + + var profile = new SoilProfile2D(); + + foreach (KeyValuePair layerWithSoil in layersWithSoils) + { + profile.Surfaces.Add(new SoilLayer2D + { + IsAquifer = layerWithSoil.Key.Properties.IsAquifer, + Soil = layerWithSoil.Value, + GeometrySurface = CreateGeometrySurface(layerWithSoil.Key) + }); + } + + profile.Geometry = geometryData; + + return profile; + } + + private static GeometrySurface CreateGeometrySurface(MacroStabilityInwardsSoilLayerUnderSurfaceLine layer) + { + var outerLoop = new GeometryLoop(); + GeometryCurve[] curves = ToCurveList(layer.OuterRing); + + geometryData.Curves.AddRange(curves); + outerLoop.CurveList.AddRange(curves); + + geometryData.Loops.Add(outerLoop); + + var innerloops = new List(); + foreach (Core.Common.Base.Geometry.Point2D[] layerHole in layer.Holes) + { + GeometryCurve[] holeCurves = ToCurveList(layerHole); + geometryData.Curves.AddRange(holeCurves); + innerloops.Add(CurvesToLoop(holeCurves)); + } + + geometryData.Loops.AddRange(innerloops); + + var surface = new GeometrySurface + { + OuterLoop = outerLoop + }; + surface.InnerLoops.AddRange(innerloops); + + geometryData.Surfaces.Add(surface); + + return surface; + } + + private static GeometryLoop CurvesToLoop(GeometryCurve[] curves) + { + var loop = new GeometryLoop(); + loop.CurveList.AddRange(curves); + return loop; + } + + private static GeometryCurve[] ToCurveList(Core.Common.Base.Geometry.Point2D[] points) + { + var geometryPoints = (List)geometryData.Points; + + var curves = new List(); + + var firstPoint = new Point2D(points[0].X, points[0].Y); + Point2D lastPoint = null; + + for (var i = 0; i < points.Length - 1; i++) + { + Point2D headPoint; + + if (i == 0) + { + headPoint = firstPoint; + geometryPoints.Add(headPoint); + } + else + { + headPoint = lastPoint; + } + + var endPoint = new Point2D(points[i + 1].X, points[i + 1].Y); + + geometryPoints.Add(endPoint); + + curves.Add(new GeometryCurve + { + HeadPoint = headPoint, + EndPoint = endPoint, + }); + + lastPoint = endPoint; + } + + if (lastPoint != null && (Math.Abs(lastPoint.X - firstPoint.X) > 1e-6 || Math.Abs(lastPoint.Z - firstPoint.Z) > 1e-6)) + { + curves.Add(new GeometryCurve + { + HeadPoint = lastPoint, + EndPoint = firstPoint + }); + } + + return curves.ToArray(); + } + } +} \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.KernelWrapper/MacroStabilityInwardsCalculator.cs =================================================================== diff -u -r0ecc2eb11789b230484e87fd6109bc61dc8d9b2d -re0472e1b583bd29a675a1dff5ff95e0ffdd0bb82 --- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.KernelWrapper/MacroStabilityInwardsCalculator.cs (.../MacroStabilityInwardsCalculator.cs) (revision 0ecc2eb11789b230484e87fd6109bc61dc8d9b2d) +++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.KernelWrapper/MacroStabilityInwardsCalculator.cs (.../MacroStabilityInwardsCalculator.cs) (revision e0472e1b583bd29a675a1dff5ff95e0ffdd0bb82) @@ -87,114 +87,19 @@ IUpliftVanCalculator calculator = factory.CreateUpliftVanCalculator(); Soil[] soils = MacroStabilityInwardsSoilCreator.Create(input.SoilProfile); calculator.SoilModel = MacroStabilityInwardsSoilModelCreator.Create(soils); - GeometrySurface[] surfaces = CreateSurfaces(input.SoilProfile); - calculator.SoilProfile = CreateSoilProfile(input.SoilProfile.LayersUnderSurfaceLine.ToArray(), soils, surfaces); - return calculator; - } - private GeometrySurface[] CreateSurfaces(MacroStabilityInwardsSoilProfileUnderSurfaceLine soilProfile) - { - geometryData = new GeometryData(); + Dictionary layersWithSoils = + input.SoilProfile.LayersUnderSurfaceLine + .Zip(soils, (layer, soil) => new + { + layer, soil + }) + .ToDictionary(x => x.layer, x => x.soil); - var surfaces = new List(); - foreach (MacroStabilityInwardsSoilLayerUnderSurfaceLine layer in soilProfile.LayersUnderSurfaceLine) - { - var outerLoop = new GeometryLoop(); - GeometryCurve[] curves = ToCurveList(layer.OuterRing); - - geometryData.Curves.AddRange(curves); - - outerLoop.CurveList.AddRange(curves); - - geometryData.Loops.Add(outerLoop); - - IEnumerable innerloops = layer.Holes.Select(h => - { - GeometryCurve[] geometryCurves = ToCurveList(h); - geometryData.Curves.AddRange(geometryCurves); - return geometryCurves; - }).Select(CurvesToLoop); - - geometryData.Loops.AddRange(innerloops); - - var surface = new GeometrySurface - { - OuterLoop = outerLoop - }; - surface.InnerLoops.AddRange(innerloops); - - surfaces.Add(surface); - } - - geometryData.Surfaces.AddRange(surfaces); - - return surfaces.ToArray(); + calculator.SoilProfile = MacroStabilityInwardsSoilProfileCreator.Create(layersWithSoils); + return calculator; } - private static GeometryLoop CurvesToLoop(GeometryCurve[] curves) - { - var loop = new GeometryLoop(); - loop.CurveList.AddRange(curves); - return loop; - } - - private GeometryCurve[] ToCurveList(Core.Common.Base.Geometry.Point2D[] points) - { - var geometryPoints = (List) geometryData.Points; - - var curves = new List(); - - var firstPoint = new Point2D(points[0].X, points[0].Y); - Point2D lastPoint = null; - - for (int i = 0; i < points.Length-1; i++) - { - Point2D headPoint = i == 0 - ? firstPoint - : new Point2D(points[i].X, points[i].Y); - - var endPoint = new Point2D(points[i+1].X, points[i+1].Y); - - geometryPoints.Add(headPoint); - geometryPoints.Add(endPoint); - - curves.Add(new GeometryCurve - { - HeadPoint = headPoint, - EndPoint = endPoint, - }); - - lastPoint = endPoint; - } - - curves.Add(new GeometryCurve - { - HeadPoint = lastPoint, - EndPoint = firstPoint - }); - - return curves.ToArray(); - } - - private SoilProfile2D CreateSoilProfile(IList layers, IList soils, IList surfaces) - { - var profile = new SoilProfile2D(); - - for (int i = 0; i < layers.Count; i++) - { - profile.Surfaces.Add(new SoilLayer2D - { - IsAquifer = layers[i].Properties.IsAquifer, - Soil = soils[i], - GeometrySurface = surfaces[i] - }); - } - - profile.Geometry = geometryData; - - return profile; - } - /// /// Returns a list of validation messages. The validation messages are based on the values of the /// which was provided to this and are determined by the kernel. Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.KernelWrapper/Ringtoets.MacroStabilityInwards.KernelWrapper.csproj =================================================================== diff -u -r0ecc2eb11789b230484e87fd6109bc61dc8d9b2d -re0472e1b583bd29a675a1dff5ff95e0ffdd0bb82 --- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.KernelWrapper/Ringtoets.MacroStabilityInwards.KernelWrapper.csproj (.../Ringtoets.MacroStabilityInwards.KernelWrapper.csproj) (revision 0ecc2eb11789b230484e87fd6109bc61dc8d9b2d) +++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.KernelWrapper/Ringtoets.MacroStabilityInwards.KernelWrapper.csproj (.../Ringtoets.MacroStabilityInwards.KernelWrapper.csproj) (revision e0472e1b583bd29a675a1dff5ff95e0ffdd0bb82) @@ -43,6 +43,7 @@ Properties\GlobalAssembly.cs + Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test/Creators/MacroStabilityInwardsSoilProfileCreatorTest.cs =================================================================== diff -u --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test/Creators/MacroStabilityInwardsSoilProfileCreatorTest.cs (revision 0) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test/Creators/MacroStabilityInwardsSoilProfileCreatorTest.cs (revision e0472e1b583bd29a675a1dff5ff95e0ffdd0bb82) @@ -0,0 +1,181 @@ +// Copyright (C) Stichting Deltares 2017. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets 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 Deltares.WTIStability.Data.Geo; +using NUnit.Framework; +using Ringtoets.MacroStabilityInwards.KernelWrapper.Creators; +using Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil; +using Ringtoets.MacroStabilityInwards.Primitives; +using Point2D = Core.Common.Base.Geometry.Point2D; +using WTIStabilityPoint2D = Deltares.WTIStability.Data.Geo.Point2D; + +namespace Ringtoets.MacroStabilityInwards.KernelWrapper.Test.Creators +{ + [TestFixture] + public class MacroStabilityInwardsSoilProfileCreatorTest + { + [Test] + public void Create_DictionaryNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => MacroStabilityInwardsSoilProfileCreator.Create(null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("layersWithSoils", exception.ParamName); + } + + [Test] + public void Create_WithAllData_ReturnSoilProfile2D() + { + // Setup + var outerRing = new[] + { + new Point2D(0, 0), + new Point2D(10, 10), + new Point2D(9, 9) + }; + var holes = new[] + { + new[] + { + new Point2D(2, 2), + new Point2D(4, 4), + new Point2D(2.5, 2.5) + }, + new[] + { + new Point2D(3, 3), + new Point2D(5, 5), + new Point2D(3, 3) + } + }; + + var layer = new MacroStabilityInwardsSoilLayerUnderSurfaceLine( + outerRing, holes, + new MacroStabilityInwardsSoilLayerPropertiesUnderSurfaceLine( + new MacroStabilityInwardsSoilLayerPropertiesUnderSurfaceLine.ConstructionProperties + { + IsAquifer = true + })); + + var soil = new Soil(); + + // Call + SoilProfile2D profile = MacroStabilityInwardsSoilProfileCreator.Create(new Dictionary + { + { + layer, soil + } + }); + + // Assert + Assert.AreEqual(1, profile.Surfaces.Count); + SoilLayer2D surface = profile.Surfaces.First(); + Assert.AreSame(soil, surface.Soil); + Assert.AreEqual(layer.Properties.IsAquifer, surface.IsAquifer); + + var point1 = new WTIStabilityPoint2D(0, 0); + var point2 = new WTIStabilityPoint2D(10, 10); + var point3 = new WTIStabilityPoint2D(9, 9); + var point4 = new WTIStabilityPoint2D(2, 2); + var point5 = new WTIStabilityPoint2D(4, 4); + var point6 = new WTIStabilityPoint2D(2.5, 2.5); + var point7 = new WTIStabilityPoint2D(3, 3); + var point8 = new WTIStabilityPoint2D(5, 5); + var point9 = new WTIStabilityPoint2D(3, 3); + var outerLoopCurve1 = new GeometryCurve(point1, point2); + var outerLoopCurve2 = new GeometryCurve(point2, point3); + var outerLoopCurve3 = new GeometryCurve(point3, point1); + var innerLoop1Curve1 = new GeometryCurve(point4, point5); + var innerLoop1Curve2 = new GeometryCurve(point5, point6); + var innerLoop1Curve3 = new GeometryCurve(point6, point4); + var innerLoop2Curve1 = new GeometryCurve(point7, point8); + var innerLoop2Curve2 = new GeometryCurve(point8, point9); + var expectedOuterLoop = new GeometryLoop + { + CurveList = + { + outerLoopCurve1, + outerLoopCurve2, + outerLoopCurve3 + } + }; + var expectedInnerLoop1 = new GeometryLoop + { + CurveList = + { + innerLoop1Curve1, + innerLoop1Curve2, + innerLoop1Curve3 + } + }; + var expectedInnerLoop2 = new GeometryLoop + { + CurveList = + { + innerLoop2Curve1, + innerLoop2Curve2 + } + }; + + CollectionAssert.AreEqual(new[] + { + point1, + point2, + point3, + point4, + point5, + point6, + point7, + point8, + point9 + }, profile.Geometry.Points, new WTIStabilityPoint2DComparer()); + CollectionAssert.AreEqual(new[] + { + outerLoopCurve1, + outerLoopCurve2, + outerLoopCurve3, + innerLoop1Curve1, + innerLoop1Curve2, + innerLoop1Curve3, + innerLoop2Curve1, + innerLoop2Curve2 + }, profile.Geometry.Curves, new WTIStabilityGeometryCurveComparer()); + CollectionAssert.AreEqual(new[] + { + expectedOuterLoop, + expectedInnerLoop1, + expectedInnerLoop2 + }, profile.Geometry.Loops, new WTIStabilityGeometryLoopComparer()); + + CollectionAssert.AreEqual(expectedOuterLoop.CurveList, surface.GeometrySurface.OuterLoop.CurveList, new WTIStabilityGeometryCurveComparer()); + CollectionAssert.AreEqual(new[] + { + expectedInnerLoop1, + expectedInnerLoop2 + }, surface.GeometrySurface.InnerLoops, new WTIStabilityGeometryLoopComparer()); + } + } +} \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test.csproj =================================================================== diff -u -r0ecc2eb11789b230484e87fd6109bc61dc8d9b2d -re0472e1b583bd29a675a1dff5ff95e0ffdd0bb82 --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test.csproj (.../Ringtoets.MacroStabilityInwards.KernelWrapper.Test.csproj) (revision 0ecc2eb11789b230484e87fd6109bc61dc8d9b2d) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test.csproj (.../Ringtoets.MacroStabilityInwards.KernelWrapper.Test.csproj) (revision e0472e1b583bd29a675a1dff5ff95e0ffdd0bb82) @@ -60,6 +60,7 @@ Properties\GlobalAssembly.cs + Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil.Test/Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil.Test.csproj =================================================================== diff -u -r4304327f96a967967877c287ed20f85d51255b41 -re0472e1b583bd29a675a1dff5ff95e0ffdd0bb82 --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil.Test/Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil.Test.csproj (.../Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil.Test.csproj) (revision 4304327f96a967967877c287ed20f85d51255b41) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil.Test/Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil.Test.csproj (.../Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil.Test.csproj) (revision e0472e1b583bd29a675a1dff5ff95e0ffdd0bb82) @@ -43,6 +43,9 @@ + + ..\..\..\..\lib\Plugins\Wti\WTIStability.dll + @@ -53,6 +56,9 @@ + + + Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil.Test/WTIStabilityGeometryCurveComparerTest.cs =================================================================== diff -u --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil.Test/WTIStabilityGeometryCurveComparerTest.cs (revision 0) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil.Test/WTIStabilityGeometryCurveComparerTest.cs (revision e0472e1b583bd29a675a1dff5ff95e0ffdd0bb82) @@ -0,0 +1,75 @@ +// Copyright (C) Stichting Deltares 2017. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets 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 Deltares.WTIStability.Data.Geo; +using NUnit.Framework; + +namespace Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil.Test +{ + [TestFixture] + public class WTIStabilityGeometryCurveComparerTest + { + [Test] + public void Compare_SameInstance_ReturnZero() + { + // Setup + var curve = new GeometryCurve(new Point2D(1.1, 2.2), new Point2D(3.3, 4.4)); + + // Call + int result = new WTIStabilityGeometryCurveComparer().Compare(curve, curve); + + // Assert + Assert.AreEqual(0, result); + } + + [Test] + public void Compare_EqualCoordinates_ReturnZero() + { + // Setup + const double x1 = 1.1; + const double y1 = 2.2; + const double x2 = 3.3; + const double y2 = 4.4; + var curve1 = new GeometryCurve(new Point2D(x1, y1), new Point2D(x2, y2)); + var curve2 = new GeometryCurve(new Point2D(x1, y1), new Point2D(x2, y2)); + + // Call + int result = new WTIStabilityGeometryCurveComparer().Compare(curve1, curve2); + + // Assert + Assert.AreEqual(0, result); + } + + [Test] + public void Compare_DifferentCoordinates_ReturnOne() + { + // Setup + var curve1 = new GeometryCurve(new Point2D(0, 0), new Point2D(1, 1)); + var curve2 = new GeometryCurve(new Point2D(2, 2), new Point2D(3, 3)); + + // Call + int result = new WTIStabilityGeometryCurveComparer().Compare(curve1, curve2); + + // Assert + Assert.AreEqual(1, result); + } + } +} \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil.Test/WTIStabilityGeometryLoopComparerTest.cs =================================================================== diff -u --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil.Test/WTIStabilityGeometryLoopComparerTest.cs (revision 0) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil.Test/WTIStabilityGeometryLoopComparerTest.cs (revision e0472e1b583bd29a675a1dff5ff95e0ffdd0bb82) @@ -0,0 +1,127 @@ +// Copyright (C) Stichting Deltares 2017. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets 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 Deltares.WTIStability.Data.Geo; +using NUnit.Framework; + +namespace Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil.Test +{ + [TestFixture] + public class WTIStabilityGeometryLoopComparerTest + { + [Test] + public void Compare_SameInstance_ReturnZero() + { + // Setup + var loop = new GeometryLoop(); + + // Call + int result = new WTIStabilityGeometryLoopComparer().Compare(loop, loop); + + // Assert + Assert.AreEqual(0, result); + } + + [Test] + public void Compare_SameCurveInstance_ReturnZero() + { + // Setup + var curve = new GeometryCurve(new Point2D(1.1, 2.2), new Point2D(3.3, 4.4)); + var loop1 = new GeometryLoop + { + CurveList = + { + curve + } + }; + var loop2 = new GeometryLoop + { + CurveList = + { + curve + } + }; + + // Call + int result = new WTIStabilityGeometryLoopComparer().Compare(loop1, loop2); + + // Assert + Assert.AreEqual(0, result); + } + + [Test] + public void Compare_EqualCoordinates_ReturnZero() + { + // Setup + const double x1 = 1.1; + const double y1 = 2.2; + const double x2 = 3.3; + const double y2 = 4.4; + var loop1 = new GeometryLoop + { + CurveList = + { + new GeometryCurve(new Point2D(x1, y1), new Point2D(x2, y2)) + } + }; + var loop2 = new GeometryLoop + { + CurveList = + { + new GeometryCurve(new Point2D(x1, y1), new Point2D(x2, y2)) + } + }; + + // Call + int result = new WTIStabilityGeometryLoopComparer().Compare(loop1, loop2); + + // Assert + Assert.AreEqual(0, result); + } + + [Test] + public void Compare_DifferentCoordinates_ReturnOne() + { + // Setup + + var loop1 = new GeometryLoop + { + CurveList = + { + new GeometryCurve(new Point2D(0, 0), new Point2D(1, 1)) + } + }; + var loop2 = new GeometryLoop + { + CurveList = + { + new GeometryCurve(new Point2D(2, 2), new Point2D(3, 3)) + } + }; + + // Call + int result = new WTIStabilityGeometryLoopComparer().Compare(loop1, loop2); + + // Assert + Assert.AreEqual(1, result); + } + } +} \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil.Test/WTIStabilityPoint2DComparerTest.cs =================================================================== diff -u --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil.Test/WTIStabilityPoint2DComparerTest.cs (revision 0) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil.Test/WTIStabilityPoint2DComparerTest.cs (revision e0472e1b583bd29a675a1dff5ff95e0ffdd0bb82) @@ -0,0 +1,73 @@ +// Copyright (C) Stichting Deltares 2017. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets 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 Deltares.WTIStability.Data.Geo; +using NUnit.Framework; + +namespace Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil.Test +{ + [TestFixture] + public class WTIStabilityPoint2DComparerTest + { + [Test] + public void Compare_SameInstance_ReturnZero() + { + // Setup + var point = new Point2D(1.1, 2.2); + + // Call + int result = new WTIStabilityPoint2DComparer().Compare(point, point); + + // Assert + Assert.AreEqual(0, result); + } + + [Test] + public void Compare_EqualCoordinates_ReturnZero() + { + // Setup + const double x = 1.1; + const double y = 2.2; + var point1 = new Point2D(x, y); + var point2 = new Point2D(x, y); + + // Call + int result = new WTIStabilityPoint2DComparer().Compare(point1, point2); + + // Assert + Assert.AreEqual(0, result); + } + + [Test] + public void Compare_DifferentCoordinates_ReturnOne() + { + // Setup + var point1 = new Point2D(0, 0); + var point2 = new Point2D(1, 1); + + // Call + int result = new WTIStabilityPoint2DComparer().Compare(point1, point2); + + // Assert + Assert.AreEqual(1, result); + } + } +} \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil/Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil.csproj =================================================================== diff -u -re53ef4c278a378cb5b3973dc939a19896f94b1cc -re0472e1b583bd29a675a1dff5ff95e0ffdd0bb82 --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil/Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil.csproj (.../Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil.csproj) (revision e53ef4c278a378cb5b3973dc939a19896f94b1cc) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil/Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil.csproj (.../Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil.csproj) (revision e0472e1b583bd29a675a1dff5ff95e0ffdd0bb82) @@ -58,6 +58,9 @@ + + + Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil/WTIStabilityGeometryCurveComparer.cs =================================================================== diff -u --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil/WTIStabilityGeometryCurveComparer.cs (revision 0) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil/WTIStabilityGeometryCurveComparer.cs (revision e0472e1b583bd29a675a1dff5ff95e0ffdd0bb82) @@ -0,0 +1,49 @@ +// Copyright (C) Stichting Deltares 2017. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets 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.Collections; +using System.Collections.Generic; +using Deltares.WTIStability.Data.Geo; + +namespace Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil +{ + /// + /// This class compares the coordinates of the + /// of two instances to determine whether + /// they're equal to each other or not. + /// + public class WTIStabilityGeometryCurveComparer : IComparer, IComparer + { + private readonly WTIStabilityPoint2DComparer pointComparer = new WTIStabilityPoint2DComparer(); + + public int Compare(object x, object y) + { + return Compare(x as GeometryCurve, y as GeometryCurve); + } + + public int Compare(GeometryCurve x, GeometryCurve y) + { + return pointComparer.Compare(x.HeadPoint, y.HeadPoint) == 0 + && pointComparer.Compare(x.EndPoint, y.EndPoint) == 0 + ? 0 : 1; + } + } +} \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil/WTIStabilityGeometryLoopComparer.cs =================================================================== diff -u --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil/WTIStabilityGeometryLoopComparer.cs (revision 0) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil/WTIStabilityGeometryLoopComparer.cs (revision e0472e1b583bd29a675a1dff5ff95e0ffdd0bb82) @@ -0,0 +1,49 @@ +// Copyright (C) Stichting Deltares 2017. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets 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.Collections; +using System.Collections.Generic; +using System.Linq; +using Deltares.WTIStability.Data.Geo; + +namespace Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil +{ + /// + /// This class compares the coordinates of the + /// of all instances of the + /// instances to determine whether they're equal to each other or not. + /// + public class WTIStabilityGeometryLoopComparer : IComparer, IComparer + { + private readonly WTIStabilityGeometryCurveComparer curveComparer = new WTIStabilityGeometryCurveComparer(); + public int Compare(object x, object y) + { + return Compare(x as GeometryLoop, y as GeometryLoop); + } + + public int Compare(GeometryLoop x, GeometryLoop y) + { + return x.CurveList.Where((curve, index) => + curveComparer.Compare(curve, y.CurveList[index]) == 1).Any() + ? 1 : 0; + } + } +} \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil/WTIStabilityPoint2DComparer.cs =================================================================== diff -u --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil/WTIStabilityPoint2DComparer.cs (revision 0) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil/WTIStabilityPoint2DComparer.cs (revision e0472e1b583bd29a675a1dff5ff95e0ffdd0bb82) @@ -0,0 +1,44 @@ +// Copyright (C) Stichting Deltares 2017. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets 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.Collections; +using System.Collections.Generic; +using Deltares.WTIStability.Data.Geo; + +namespace Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil +{ + /// + /// This class compares the coordinates of two + /// instances to determine whether they're equal to each other or not. + /// + public class WTIStabilityPoint2DComparer : IComparer, IComparer + { + public int Compare(object x, object y) + { + return Compare(x as Point2D, y as Point2D); + } + + public int Compare(Point2D p0, Point2D p1) + { + return p0.LocationEquals(p1) ? 0 : 1; + } + } +} \ No newline at end of file