Index: Core/Common/src/Core.Common.Base/Core.Common.Base.csproj =================================================================== diff -u -rdcd6469f6000957bc1604da8e92bd5ea09e43769 -rfcc49aac894f989182fb9faa487e50a585fbed03 --- Core/Common/src/Core.Common.Base/Core.Common.Base.csproj (.../Core.Common.Base.csproj) (revision dcd6469f6000957bc1604da8e92bd5ea09e43769) +++ Core/Common/src/Core.Common.Base/Core.Common.Base.csproj (.../Core.Common.Base.csproj) (revision fcc49aac894f989182fb9faa487e50a585fbed03) @@ -89,6 +89,7 @@ + Index: Core/Common/src/Core.Common.Base/Geometry/Point2D.cs =================================================================== diff -u -r06f9145d8180df7fd26eac086a3f431c181e4d64 -rfcc49aac894f989182fb9faa487e50a585fbed03 --- Core/Common/src/Core.Common.Base/Geometry/Point2D.cs (.../Point2D.cs) (revision 06f9145d8180df7fd26eac086a3f431c181e4d64) +++ Core/Common/src/Core.Common.Base/Geometry/Point2D.cs (.../Point2D.cs) (revision fcc49aac894f989182fb9faa487e50a585fbed03) @@ -3,16 +3,16 @@ // 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 +// it under the terms of the GNU Lesser 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. +// GNU Lesser General Public License for more details. // -// You should have received a copy of the GNU General Public License +// You should have received a copy of the GNU Lesser General Public License // along with this program. If not, see . // // All names, logos, and references to "Deltares" are registered trademarks of @@ -72,6 +72,23 @@ return result; } + /// + /// Gets the euclidean distance from this point to another. + /// + /// The second point. + /// A value of 0 or greater. + /// When is null. + public double GetEuclideanDistanceTo(Point2D secondPoint) + { + if (secondPoint == null) + { + throw new ArgumentNullException("secondPoint"); + } + + Vector vector = this - secondPoint; + return Math.Sqrt(vector.DotProduct(vector)); + } + public override bool Equals(object obj) { if (ReferenceEquals(null, obj)) @@ -86,15 +103,15 @@ { return false; } - return Equals((Point2D) obj); + return Equals((Point2D)obj); } public override int GetHashCode() { unchecked { var hashCode = X.GetHashCode(); - hashCode = (hashCode*397) ^ Y.GetHashCode(); + hashCode = (hashCode * 397) ^ Y.GetHashCode(); return hashCode; } } Index: Core/Common/src/Core.Common.Base/Geometry/Point3D.cs =================================================================== diff -u -r9eb91cfa000697ddfdeace89aa8f1e959fc1f7f9 -rfcc49aac894f989182fb9faa487e50a585fbed03 --- Core/Common/src/Core.Common.Base/Geometry/Point3D.cs (.../Point3D.cs) (revision 9eb91cfa000697ddfdeace89aa8f1e959fc1f7f9) +++ Core/Common/src/Core.Common.Base/Geometry/Point3D.cs (.../Point3D.cs) (revision fcc49aac894f989182fb9faa487e50a585fbed03) @@ -3,16 +3,16 @@ // 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 +// it under the terms of the GNU Lesser 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. +// GNU Lesser General Public License for more details. // -// You should have received a copy of the GNU General Public License +// You should have received a copy of the GNU Lesser General Public License // along with this program. If not, see . // // All names, logos, and references to "Deltares" are registered trademarks of @@ -70,16 +70,16 @@ { return false; } - return Equals((Point3D) obj); + return Equals((Point3D)obj); } public override int GetHashCode() { unchecked { var hashCode = X.GetHashCode(); - hashCode = (hashCode*397) ^ Y.GetHashCode(); - hashCode = (hashCode*397) ^ Z.GetHashCode(); + hashCode = (hashCode * 397) ^ Y.GetHashCode(); + hashCode = (hashCode * 397) ^ Z.GetHashCode(); return hashCode; } } Index: Core/Common/src/Core.Common.Base/Geometry/Segment2D.cs =================================================================== diff -u --- Core/Common/src/Core.Common.Base/Geometry/Segment2D.cs (revision 0) +++ Core/Common/src/Core.Common.Base/Geometry/Segment2D.cs (revision fcc49aac894f989182fb9faa487e50a585fbed03) @@ -0,0 +1,189 @@ +// Copyright (C) Stichting Deltares 2016. 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 Lesser 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 Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser 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 Core.Common.Base.Properties; + +using MathNet.Numerics.LinearAlgebra.Double; + +namespace Core.Common.Base.Geometry +{ + /// + /// This class represents lines between two . + /// + public class Segment2D + { + /// + /// Creates a new instance of , with the set to + /// and the set to . + /// + /// The first of the . + /// The second of the . + /// Thrown when either the or + /// point is null. + public Segment2D(Point2D first, Point2D second) + { + if (first == null) + { + throw new ArgumentNullException("first", Resources.Segment2D_Constructor_Segment_must_be_created_with_two_points); + } + if (second == null) + { + throw new ArgumentNullException("second", Resources.Segment2D_Constructor_Segment_must_be_created_with_two_points); + } + FirstPoint = first; + SecondPoint = second; + Length = FirstPoint.GetEuclideanDistanceTo(SecondPoint); + } + + /// + /// The first of the . + /// + public Point2D FirstPoint { get; private set; } + + /// + /// The second of the . + /// + public Point2D SecondPoint { get; private set; } + + /// + /// Gets the (euclidean) length of the segment. + /// + public double Length { get; private set; } + + /// + /// This method determines whether is contained by the + /// and x coordinates. + /// + /// The x for which to find out whether it is contained by the + /// and . + /// true if x is on or between the points' x coordinates. false otherwise. + public bool ContainsX(double x) + { + var distanceFirstPoint = FirstPoint.X - x; + var distanceSecondPoint = SecondPoint.X - x; + + var onPoint = Math.Abs(FirstPoint.X - x) < 1e-8 || Math.Abs(SecondPoint.X - x) < 1e-8; + + return onPoint || Math.Sign(distanceFirstPoint) != Math.Sign(distanceSecondPoint); + } + + /// + /// Determines whether the is vertical. + /// + /// true if the is vertical. false otherwise. + public bool IsVertical() + { + return Math.Abs(FirstPoint.X - SecondPoint.X) < 1e-8 && Math.Abs(FirstPoint.Y - SecondPoint.Y) >= 1e-8; + } + + /// + /// Gets the euclidean distance from this 2D line segment to some 2D point. + /// + /// The point to measure distance to. + /// A value of 0 or greater. + public double GetEuclideanDistanceToPoint(Point2D point) + { + if (point == null) + { + throw new ArgumentNullException("point"); + } + + Vector segmentVector = SecondPoint - FirstPoint; // Vector from FirstPoint to SecondPoint + Vector orientationVector = point - FirstPoint; // Vector from FirstPoint to 'point' + + // Situation sketch, normalized along the segment: + // A : B : C + // .....p1----p2...... + // : : + // 1. Use numerator part of vector projection to determine relative location of 'point': + double dotProductOrientationVector = segmentVector.DotProduct(orientationVector); + if (dotProductOrientationVector <= 0) + { + // 'point' falls outside the perpendicular area defined by segment, specifically: Zone A + return point.GetEuclideanDistanceTo(FirstPoint); + } + // 2. Use denominator part of vector projection to determine relative location of 'point': + double dotProdcutSegmentVector = segmentVector.DotProduct(segmentVector); + if (dotProdcutSegmentVector <= dotProductOrientationVector) + { + // 'point' falls outside the perpendicular area defined by segment, specifically: Zone C + return point.GetEuclideanDistanceTo(SecondPoint); + } + + // 'point' falls within the perpendicular area defined by the segment (zone B). + // 3. Use remainder of vector projection to determine point on segment for perpendicular line: + double projectionFactor = dotProductOrientationVector / dotProdcutSegmentVector; + double perpendicularOnSegmentX = FirstPoint.X + projectionFactor * segmentVector[0]; + double perpendicularOnSegmentY = FirstPoint.Y + projectionFactor * segmentVector[1]; + var perpendicularLineIntersectionPoint = new Point2D(perpendicularOnSegmentX, perpendicularOnSegmentY); + + return point.GetEuclideanDistanceTo(perpendicularLineIntersectionPoint); + } + + /// + /// Determines whether two segments are connected by each other's + /// and . + /// + /// The segment which may be connected to the . + /// true if the segments are connected. false otherwise. + public bool IsConnected(Segment2D segment) + { + return + FirstPoint.Equals(segment.FirstPoint) || + FirstPoint.Equals(segment.SecondPoint) || + SecondPoint.Equals(segment.FirstPoint) || + SecondPoint.Equals(segment.SecondPoint); + } + + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) + { + return false; + } + if (ReferenceEquals(this, obj)) + { + return true; + } + if (obj.GetType() != GetType()) + { + return false; + } + return Equals((Segment2D)obj); + } + + public override int GetHashCode() + { + unchecked + { + return ((FirstPoint.X + SecondPoint.X).GetHashCode() * 397) ^ (FirstPoint.Y + SecondPoint.Y).GetHashCode(); + } + } + + private bool Equals(Segment2D other) + { + return FirstPoint.Equals(other.FirstPoint) && SecondPoint.Equals(other.SecondPoint) || + FirstPoint.Equals(other.SecondPoint) && SecondPoint.Equals(other.FirstPoint); + } + } +} \ No newline at end of file Index: Core/Common/src/Core.Common.Base/Properties/Resources.Designer.cs =================================================================== diff -u -r1abce3b7d9611e826388ff49f3faf8cb1040f80c -rfcc49aac894f989182fb9faa487e50a585fbed03 --- Core/Common/src/Core.Common.Base/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 1abce3b7d9611e826388ff49f3faf8cb1040f80c) +++ Core/Common/src/Core.Common.Base/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision fcc49aac894f989182fb9faa487e50a585fbed03) @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.34209 +// Runtime Version:4.0.30319.18444 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -123,5 +123,14 @@ return ResourceManager.GetString("Project_Constructor_Default_name", resourceCulture); } } + + /// + /// Looks up a localized string similar to Voor het maken van een segment zijn twee punten nodig.. + /// + public static string Segment2D_Constructor_Segment_must_be_created_with_two_points { + get { + return ResourceManager.GetString("Segment2D_Constructor_Segment_must_be_created_with_two_points", resourceCulture); + } + } } } Index: Core/Common/src/Core.Common.Base/Properties/Resources.resx =================================================================== diff -u -r1abce3b7d9611e826388ff49f3faf8cb1040f80c -rfcc49aac894f989182fb9faa487e50a585fbed03 --- Core/Common/src/Core.Common.Base/Properties/Resources.resx (.../Resources.resx) (revision 1abce3b7d9611e826388ff49f3faf8cb1040f80c) +++ Core/Common/src/Core.Common.Base/Properties/Resources.resx (.../Resources.resx) (revision fcc49aac894f989182fb9faa487e50a585fbed03) @@ -138,4 +138,7 @@ Ringtoets Copyright (C) 2016 Stichting Deltares. Dit programma komt ZONDER ENIGE GARANTIE. Dit programma is gratis en u mag het zelf verder verspreiden en/of aanpassen overeenkomstig de GNU Lesser General Public License versie 3. + + Voor het maken van een segment zijn twee punten nodig. + \ No newline at end of file Index: Core/Common/test/Core.Common.Base.Test/Core.Common.Base.Test.csproj =================================================================== diff -u -rdcd6469f6000957bc1604da8e92bd5ea09e43769 -rfcc49aac894f989182fb9faa487e50a585fbed03 --- Core/Common/test/Core.Common.Base.Test/Core.Common.Base.Test.csproj (.../Core.Common.Base.Test.csproj) (revision dcd6469f6000957bc1604da8e92bd5ea09e43769) +++ Core/Common/test/Core.Common.Base.Test/Core.Common.Base.Test.csproj (.../Core.Common.Base.Test.csproj) (revision fcc49aac894f989182fb9faa487e50a585fbed03) @@ -62,6 +62,10 @@ pdbonly + + ..\..\..\..\packages\MathNet.Numerics.3.8.0\lib\net40\MathNet.Numerics.dll + True + ..\..\..\..\packages\NUnit.2.6.4\lib\nunit.framework.dll True @@ -75,8 +79,12 @@ 3.5 + + + + Index: Core/Common/test/Core.Common.Base.Test/Geometry/Point2DTest.cs =================================================================== diff -u --- Core/Common/test/Core.Common.Base.Test/Geometry/Point2DTest.cs (revision 0) +++ Core/Common/test/Core.Common.Base.Test/Geometry/Point2DTest.cs (revision fcc49aac894f989182fb9faa487e50a585fbed03) @@ -0,0 +1,243 @@ +// Copyright (C) Stichting Deltares 2016. 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 Core.Common.Base.Geometry; + +using MathNet.Numerics.LinearAlgebra.Double; + +using NUnit.Framework; + +namespace Core.Common.Base.Test.Geometry +{ + [TestFixture] + public class Point2DTest + { + [Test] + public void DefaultConstructor_ExpectedValues() + { + // Call + var point = new Point2D(); + + // Assert + Assert.AreEqual(0, point.X); + Assert.AreEqual(0, point.Y); + } + + [Test] + public void Constructor_WithXandY_SetPropeties() + { + // Setup + var random = new Random(22); + var x = random.NextDouble(); + var y = random.NextDouble(); + + // Call + var point = new Point2D(x, y); + + // Assert + Assert.AreEqual(x, point.X); + Assert.AreEqual(y, point.Y); + } + + [Test] + public void Equals_ToNull_ReturnsFalse() + { + // Setup + var point = new Point2D(); + + // Call + var result = point.Equals(null); + + // Assert + Assert.IsFalse(result); + } + + [Test] + public void Equals_ToOtherType_ReturnsFalse() + { + // Setup + var point = new Point2D(); + + // Call + var result = point.Equals(new Point3D(0,0,0)); + + // Assert + Assert.IsFalse(result); + } + + [Test] + public void Equals_ToItself_ReturnsTrue() + { + // Setup + var point = new Point2D(); + + // Call + var result = point.Equals(point); + + // Assert + Assert.IsTrue(result); + } + + [Test] + [TestCase(0, 0)] + [TestCase(1, 2)] + public void Equals_OtherWithSameCoordinates_ReturnsTrue(double x, double y) + { + // Setup + var point = new Point2D(x, y); + var otherPoint = new Point2D(x, y); + + // Call + var result = point.Equals(otherPoint); + + // Assert + Assert.IsTrue(result); + } + + [Test] + [TestCase(1e-8, 0)] + [TestCase(0, 1e-8)] + public void Equals_CloseToOtherPoint_ReturnsFalse(double deltaX, double deltaY) + { + // Setup + var random = new Random(22); + var x = random.NextDouble(); + var y = random.NextDouble(); + + var point = new Point2D(x, y); + var otherPoint = new Point2D(x + deltaX, y + deltaY); + + // Call + var result = point.Equals(otherPoint); + + // Assert + Assert.IsFalse(result); + } + + [Test] + public void GetHashCode_PointsAreEqual_PointsHashesEqual() + { + // Setup + var random = new Random(22); + var x = random.NextDouble(); + var y = random.NextDouble(); + + var point = new Point2D(x, y); + var otherPoint = new Point2D(x, y); + + // Call + var result = point.GetHashCode(); + var otherResult = otherPoint.GetHashCode(); + + // Assert + Assert.AreEqual(result, otherResult); + } + + [Test] + [SetCulture("nl-NL")] + public void ToString_HasCoordinatValues_NL_PrintCoordinateValuesInLocalCulture() + { + DoToString_HasCoordinateValues_PrintCoordinateValuesInLocalCulture(); + } + + [Test] + [SetCulture("en-US")] + public void ToString_HasCoordinatValues_EN_PrintCoordinateValuesInLocalCulture() + { + DoToString_HasCoordinateValues_PrintCoordinateValuesInLocalCulture(); + } + + [Test] + public void SubstractOperation_TwoDifferentPoints_Return2DVector() + { + // Setup + var point1 = new Point2D(3.0, 4.0); + var point2 = new Point2D(1.0, 1.0); + + // Call + Vector vector = point1 - point2; + + // Assert + Assert.AreEqual(2, vector.Count); + Assert.AreEqual(point1.X - point2.X, vector[0]); + Assert.AreEqual(point1.Y - point2.Y, vector[1]); + } + + [Test] + public void GetEuclideanDistanceTo_Itself_ReturnZero() + { + // Setup + var point = new Point2D(1.1, 2.2); + + // Call + double euclideanDistance = point.GetEuclideanDistanceTo(point); + + // Assert + Assert.AreEqual(0, euclideanDistance); + } + + [Test] + public void GetEuclideanDistanceTo_Null_ThrowArgumentNullException() + { + // Setup + var point = new Point2D(1.1, 2.2); + + // Call + TestDelegate call = () => point.GetEuclideanDistanceTo(null); + + // Assert + Assert.Throws(call); + } + + [Test] + public void GetEuclideanDistanceTo_DifferentPoint_ReturnEuclideanDistance() + { + // Setup + var point = new Point2D(1.2, 3.5); + var point2 = new Point2D(8.13, 21.34); + + // Call + double euclideanDistance1 = point.GetEuclideanDistanceTo(point2); + double euclideanDistance2 = point2.GetEuclideanDistanceTo(point); + + // Assert + var expectedResult = Math.Sqrt(Math.Pow(point.X - point2.X, 2) + + Math.Pow(point.Y - point2.Y, 2)); + Assert.AreEqual(expectedResult, euclideanDistance1); + Assert.AreEqual(euclideanDistance2, euclideanDistance1); + } + + private static void DoToString_HasCoordinateValues_PrintCoordinateValuesInLocalCulture() + { + // Setup + var point = new Point2D(1.1, 2.2); + + // Call + var stringRepresentation = point.ToString(); + + // Assert + var expectedText = String.Format("({0}, {1})", point.X, point.Y); + Assert.AreEqual(expectedText, stringRepresentation); + } + } +} \ No newline at end of file Index: Core/Common/test/Core.Common.Base.Test/Geometry/Point3DTest.cs =================================================================== diff -u --- Core/Common/test/Core.Common.Base.Test/Geometry/Point3DTest.cs (revision 0) +++ Core/Common/test/Core.Common.Base.Test/Geometry/Point3DTest.cs (revision fcc49aac894f989182fb9faa487e50a585fbed03) @@ -0,0 +1,158 @@ +using System; + +using Core.Common.Base.Geometry; + +using NUnit.Framework; + +namespace Core.Common.Base.Test.Geometry +{ + [TestFixture] + public class Point3DTest + { + [Test] + public void Constructor_WithParameters_ExpectedValues() + { + // Setup + var x = 1.1; + var y = 2.2; + var z = -1.1; + + // Call + var point = new Point3D(x, y, z); + + // Assert + Assert.AreEqual(1.1, point.X); + Assert.AreEqual(2.2, point.Y); + Assert.AreEqual(-1.1, point.Z); + } + + [Test] + public void Equals_ToNull_ReturnsFalse() + { + // Setup + var point = new Point3D(0,0,0); + + // Call + var result = point.Equals(null); + + // Assert + Assert.IsFalse(result); + } + + [Test] + public void Equals_ToOtherType_ReturnsFalse() + { + // Setup + var point = new Point3D(0,0,0); + + // Call + var result = point.Equals(new Point2D()); + + // Assert + Assert.IsFalse(result); + } + + [Test] + public void Equals_ToItself_ReturnsTrue() + { + // Setup + var point = new Point3D(0,0,0); + + // Call + var result = point.Equals(point); + + // Assert + Assert.IsTrue(result); + } + + [Test] + [TestCase(0,0,0)] + [TestCase(1,2,3)] + [TestCase(3.5,3.6,3.7)] + public void Equals_OtherWithSameCoordinates_ReturnsTrue(double x, double y, double z) + { + // Setup + var point = new Point3D(x, y, z); + var otherPoint = new Point3D(x, y, z); + + // Call + var result = point.Equals(otherPoint); + + // Assert + Assert.IsTrue(result); + } + + [Test] + [TestCase(1e-8, 0, 0)] + [TestCase(0, 1e-8, 0)] + [TestCase(0, 0, 1e-8)] + public void Equals_CloseToOtherPoint_ReturnsFalse(double deltaX, double deltaY, double deltaZ) + { + // Setup + var random = new Random(22); + var x = random.NextDouble(); + var y = random.NextDouble(); + var z = random.NextDouble(); + + var point = new Point3D(x, y, z); + var otherPoint = new Point3D( + x + deltaX, + y + deltaY, + z + deltaZ + ); + + // Call + var result = point.Equals(otherPoint); + + // Assert + Assert.IsFalse(result); + } + + [Test] + public void GetHashCode_PointsAreEqual_PointsHashesEqual() + { + // Setup + var random = new Random(22); + var x = random.NextDouble(); + var y = random.NextDouble(); + var z = random.NextDouble(); + + var point = new Point3D(x, y, z); + var otherPoint = new Point3D(x, y, z); + + // Call + var result = point.GetHashCode(); + var otherResult = otherPoint.GetHashCode(); + + // Assert + Assert.AreEqual(result, otherResult); + } + + [Test] + [SetCulture("nl-NL")] + public void ToString_HasCoordinatValues_NL_PrintCoordinateValuesInLocalCulture() + { + DoToString_HasCoordinateValues_PrintCoordinateValuesInLocalCulture(); + } + + [Test] + [SetCulture("en-US")] + public void ToString_HasCoordinatValues_EN_PrintCoordinateValuesInLocalCulture() + { + DoToString_HasCoordinateValues_PrintCoordinateValuesInLocalCulture(); + } + + private static void DoToString_HasCoordinateValues_PrintCoordinateValuesInLocalCulture() + { + // Setup + var point = new Point3D(1.1, 2.2, 3.3); + + // Call + var stringRepresentation = point.ToString(); + + // Assert + var expectedText = String.Format("({0}, {1}, {2})", point.X, point.Y, point.Z); + Assert.AreEqual(expectedText, stringRepresentation); + } + } +} \ No newline at end of file Index: Core/Common/test/Core.Common.Base.Test/Geometry/Segment2DTest.cs =================================================================== diff -u --- Core/Common/test/Core.Common.Base.Test/Geometry/Segment2DTest.cs (revision 0) +++ Core/Common/test/Core.Common.Base.Test/Geometry/Segment2DTest.cs (revision fcc49aac894f989182fb9faa487e50a585fbed03) @@ -0,0 +1,457 @@ +using System; + +using Core.Common.Base.Geometry; + +using NUnit.Framework; + +namespace Core.Common.Base.Test.Geometry +{ + [TestFixture] + public class Segment2DTest + { + [Test] + public void Constructor_WithTwoPoints_ReturnsSegmentWithPointsSet() + { + // Setup + var firstPoint = new Point2D(); + var secondPoint = new Point2D(); + + // Call + var segment = new Segment2D(firstPoint, secondPoint); + + // Assert + Assert.AreSame(firstPoint, segment.FirstPoint); + Assert.AreSame(secondPoint, segment.SecondPoint); + } + + [Test] + public void Constructor_WithNullFirstPoint_ThrowsArgumentNullException() + { + // Setup + var secondPoint = new Point2D(); + + // Call + TestDelegate test = () => new Segment2D(null, secondPoint); + + // Assert + var exception = Assert.Throws(test); + StringAssert.StartsWith("Voor het maken van een segment zijn twee punten nodig.", exception.Message); + } + + [Test] + public void Constructor_WithNullSecondPoint_ThrowsArgumentNullException() + { + // Setup + var firstPoint = new Point2D(); + + // Call + TestDelegate test = () => new Segment2D(firstPoint, null); + + // Assert + var exception = Assert.Throws(test); + StringAssert.StartsWith("Voor het maken van een segment zijn twee punten nodig.", exception.Message); + } + + [Test] + [TestCase(1, 2, 1.5, true)] + [TestCase(1, 2, 1 + 1e-6, true)] + [TestCase(1, 2, 2 - 1e-6, true)] + [TestCase(1, 2, 2, true)] + [TestCase(1, 2, 1, true)] + [TestCase(1, 1, 1, true)] + [TestCase(1, 2, 0, false)] + [TestCase(1, 2, 3, false)] + [TestCase(1, 2, 2 + 1e-6, false)] + [TestCase(1, 2, 1 - 1e-6, false)] + public void ContainsX_DifferentSetsOfX_ReturnsExpectedValue(double firstPointX, double secondPointX, double containedX, bool isContained) + { + // Setup + var random = new Random(22); + var firstPoint = new Point2D(firstPointX, random.NextDouble()); + var secondPoint = new Point2D(secondPointX, random.NextDouble()); + var segment = new Segment2D(firstPoint, secondPoint); + + // Call + var result = segment.ContainsX(containedX); + + // Assert + Assert.AreEqual(isContained, result); + } + + [Test] + [TestCase(1, 1, true)] + [TestCase(1, 2, false)] + [TestCase(1, 1 + 1e-6, false)] + [TestCase(1, 1 - 1e-6, false)] + [TestCase(1, 1 + 1e-9, true)] + [TestCase(1, 1 - 1e-9, true)] + public void IsVertical_DifferentSetsOfX_ReturnsExpectedValue(double firstPointX, double secondPointX, bool isVertical) + { + // Setup + var random = new Random(22); + var firstPoint = new Point2D(firstPointX, random.NextDouble()); + var secondPoint = new Point2D(secondPointX, random.NextDouble()); + var segment = new Segment2D(firstPoint, secondPoint); + + // Call + var result = segment.IsVertical(); + + // Assert + Assert.AreEqual(isVertical, result); + } + + [Test] + [TestCase(1e-9, false)] + [TestCase(1e-8 + 1e-10, true)] + [TestCase(1e-8 - 1e-10, false)] + [TestCase(1e-7, true)] + [TestCase(1, true)] + public void IsVertical_DifferencesInY_ReturnsExpectedValue(double difference, bool isVertical) + { + // Setup + var random = new Random(22); + var x = random.NextDouble(); + var y = random.NextDouble(); + var firstPoint = new Point2D(x, y); + var secondPoint = new Point2D(x, y + difference); + var segment = new Segment2D(firstPoint, secondPoint); + + // Call + var result = segment.IsVertical(); + + // Assert + Assert.AreEqual(isVertical, result); + } + + [Test] + [TestCase(1.1, 2.2, 1.1, 2.2, 0)] + [TestCase(1.2, 3.5, 8.13, 21.34, 19.138717)] + public void Length_VariousCases_ReturnExpectedLength( + double x1, double y1, + double x2, double y2, + double expectedLength) + { + // Setup + var segment = new Segment2D(new Point2D(x1, y1), new Point2D(x2, y2)); + + // Call + double length = segment.Length; + + // Assert + Assert.AreEqual(expectedLength, length, 1e-6); + } + + [Test] + public void Equals_SameSegment_ReturnsTrue() + { + // Setup + var random = new Random(22); + var x1 = random.NextDouble(); + var x2 = random.NextDouble(); + var y1 = random.NextDouble(); + var y2 = random.NextDouble(); + var point1 = new Point2D(x1, y1); + var point2 = new Point2D(x2, y2); + var segment = new Segment2D(point1, point2); + + // Assert + var isEqual = segment.Equals(segment); + + // Assert + Assert.IsTrue(isEqual); + } + + [Test] + public void Equals_WithNull_ReturnsFalse() + { + // Setup + var random = new Random(22); + var x1 = random.NextDouble(); + var x2 = random.NextDouble(); + var y1 = random.NextDouble(); + var y2 = random.NextDouble(); + var point1 = new Point2D(x1, y1); + var point2 = new Point2D(x2, y2); + var segment = new Segment2D(point1, point2); + + // Call & Assert + Assert.IsFalse(segment.Equals(null)); + } + + [Test] + public void Equals_WithOtherObjectType_ReturnsFalse() + { + // Setup + var random = new Random(22); + var segment = new Segment2D(new Point2D(random.NextDouble(), random.NextDouble()), new Point2D(random.NextDouble(), random.NextDouble())); + + // Call + var isEqual = segment.Equals(new Point2D(0.0,0.0)); + + // Assert + Assert.IsFalse(isEqual); + } + + [Test] + public void Equals_SegmentWithTwoPointsWithSameXY_ReturnsTrue() + { + // Setup + var random = new Random(22); + var x1 = random.NextDouble(); + var x2 = random.NextDouble(); + var y1 = random.NextDouble(); + var y2 = random.NextDouble(); + var point1 = new Point2D(x1, y1); + var point2 = new Point2D(x2, y2); + var segment1 = new Segment2D(point1, point2); + var segment2 = new Segment2D(point1, point2); + var segment3 = new Segment2D(point2, point1); + + // Call & Assert + Assert.IsTrue(segment1.Equals(segment2)); + Assert.IsTrue(segment1.Equals(segment3)); + } + + [Test] + public void Equals_SegmentWithTwoPointsWithDifferentXY_ReturnsFalse() + { + // Setup + var random = new Random(22); + var x1 = random.NextDouble(); + var x2 = random.NextDouble(); + var x3 = random.NextDouble(); + var x4 = random.NextDouble(); + var y1 = random.NextDouble(); + var y2 = random.NextDouble(); + var y3 = random.NextDouble(); + var y4 = random.NextDouble(); + var point1 = new Point2D(x1, y1); + var point2 = new Point2D(x2, y2); + var point3 = new Point2D(x3, y3); + var point4 = new Point2D(x4, y4); + var segment1 = new Segment2D(point1, point2); + var segment2 = new Segment2D(point3, point4); + + // Call & Assert + Assert.IsFalse(segment1.Equals(segment2)); + Assert.IsFalse(segment2.Equals(segment1)); + } + + [Test] + public void GetHashCode_EqualSegments_AreEqual() + { + // Setup + var random = new Random(22); + var x1 = random.NextDouble(); + var x2 = random.NextDouble(); + var y1 = random.NextDouble(); + var y2 = random.NextDouble(); + var point1 = new Point2D(x1, y1); + var point2 = new Point2D(x2, y2); + var segment1 = new Segment2D(point1, point2); + var segment2 = new Segment2D(point1, point2); + var segment3 = new Segment2D(point2, point1); + + // Precondition + Assert.AreEqual(segment1, segment1); + Assert.AreEqual(segment1, segment2); + Assert.AreEqual(segment1, segment3); + + // Call & Assert + Assert.AreEqual(segment1.GetHashCode(), segment1.GetHashCode()); + Assert.AreEqual(segment1.GetHashCode(), segment2.GetHashCode()); + Assert.AreEqual(segment1.GetHashCode(), segment3.GetHashCode()); + } + + [Test] + public void IsConnected_SameSegment_True() + { + // Setup + var random = new Random(22); + var x1 = random.NextDouble(); + var x2 = random.NextDouble(); + var y1 = random.NextDouble(); + var y2 = random.NextDouble(); + var point1 = new Point2D(x1, y1); + var point2 = new Point2D(x2, y2); + var segment1 = new Segment2D(point1, point2); + + // Call & Assert + Assert.IsTrue(segment1.IsConnected(segment1)); + } + + [Test] + public void IsConnected_EqualSegments_True() + { + // Setup + var random = new Random(22); + var x1 = random.NextDouble(); + var x2 = random.NextDouble(); + var y1 = random.NextDouble(); + var y2 = random.NextDouble(); + var point1 = new Point2D(x1, y1); + var point2 = new Point2D(x2, y2); + var segment1 = new Segment2D(point1, point2); + var segment2 = new Segment2D(point1, point2); + + // Call & Assert + Assert.IsTrue(segment1.IsConnected(segment2)); + Assert.IsTrue(segment2.IsConnected(segment1)); + } + + [Test] + public void IsConnected_ThreeConnectedSegments_AreAllConnected() + { + // Setup + var random = new Random(22); + var x1 = random.NextDouble(); + var x2 = random.NextDouble(); + var x3 = random.NextDouble(); + var y1 = random.NextDouble(); + var y2 = random.NextDouble(); + var y3 = random.NextDouble(); + + var point1 = new Point2D(x1, y1); + var point2 = new Point2D(x2, y2); + var point3 = new Point2D(x3, y3); + var segment1 = new Segment2D(point1, point2); + var segment2 = new Segment2D(point2, point3); + var segment3 = new Segment2D(point1, point3); + + // Call & Assert + Assert.IsTrue(segment1.IsConnected(segment2)); + Assert.IsTrue(segment1.IsConnected(segment3)); + + Assert.IsTrue(segment2.IsConnected(segment1)); + Assert.IsTrue(segment2.IsConnected(segment3)); + + Assert.IsTrue(segment3.IsConnected(segment1)); + Assert.IsTrue(segment3.IsConnected(segment2)); + } + + [Test] + public void IsConnected_TwoSeperateSegments_AreDisconnected() + { + // Setup + var random = new Random(22); + var x1 = random.NextDouble(); + var x2 = random.NextDouble(); + var x3 = random.NextDouble(); + var x4 = random.NextDouble(); + var y1 = random.NextDouble(); + var y2 = random.NextDouble(); + var y3 = random.NextDouble(); + var y4 = random.NextDouble(); + + var point1 = new Point2D(x1, y1); + var point2 = new Point2D(x2, y2); + var point3 = new Point2D(x3, y3); + var point4 = new Point2D(x4, y4); + var segment1 = new Segment2D(point1, point2); + var segment2 = new Segment2D(point3, point4); + + // Call & Assert + Assert.IsFalse(segment1.IsConnected(segment2)); + Assert.IsFalse(segment2.IsConnected(segment1)); + } + + [Test] + public void GetEuclideanDistanceToPoint_PointOnFirstPoint_ReturnZero() + { + // Setup + var segment = new Segment2D(new Point2D(1.2, 3.5), new Point2D(8.13, 21.34)); + + // Call + var euclideanDistance = segment.GetEuclideanDistanceToPoint(segment.FirstPoint); + + // Assert + Assert.AreEqual(0, euclideanDistance); + } + + [Test] + public void GetEuclideanDistanceToPoint_PointOnSecondPoint_ReturnZero() + { + // Setup + var segment = new Segment2D(new Point2D(1.2, 3.5), new Point2D(8.13, 21.34)); + + // Call + var euclideanDistance = segment.GetEuclideanDistanceToPoint(segment.SecondPoint); + + // Assert + Assert.AreEqual(0, euclideanDistance); + } + + [Test] + public void GetEuclideanDistanceToPoint_PointIsNull_ThrowArgumentNullException() + { + // Setup + var segment = new Segment2D(new Point2D(1.2, 3.5), new Point2D(8.13, 21.34)); + + // Call + TestDelegate call = () => segment.GetEuclideanDistanceToPoint(null); + + // Assert + Assert.Throws(call); + } + + [Test] + [TestCase(-2.3, 2.1)] + [TestCase(0, 1.1)] + [TestCase(3.2, -1.2)] + public void GetEuclideanDistanceToPoint_FirstPointIsClosest_ReturnExpectedDistance( + double x, double y) + { + // Setup + var point = new Point2D(x, y); + var segment = new Segment2D(new Point2D(1.1, 2.2), new Point2D(3.3, 4.4)); + + // Call + var actualDistance = segment.GetEuclideanDistanceToPoint(point); + + // Assert + var expectedDistance = point.GetEuclideanDistanceTo(segment.FirstPoint); + Assert.AreEqual(expectedDistance, actualDistance); + } + + [Test] + [TestCase(2.2, 3.3, 0)] + [TestCase(0, 3.3, 1.555634919)] + [TestCase(4.4, -1.1, 4.666904756)] + [TestCase(-2.2, 9.9, 7.778174593)] + [TestCase(11, -3.3, 10.88944443)] + [TestCase(1.5, 3.5, 0.636396103)] + [TestCase(4.5, 1, 3.252691193)] + public void GetEuclideanDistanceToPoint_LinePerpendicularToSegmentIsClosest_ReturnExpectedDistance( + double x, double y, double expectedDistance) + { + // Setup + var point = new Point2D(x, y); + var segment = new Segment2D(new Point2D(1.1, 2.2), new Point2D(3.3, 4.4)); + + // Call + var actualDistance = segment.GetEuclideanDistanceToPoint(point); + + // Assert + Assert.AreEqual(expectedDistance, actualDistance, 1e-6); + } + + [Test] + [TestCase(5.3, 4.3)] + [TestCase(6.6, 7.7)] + [TestCase(2.7, 12.6)] + public void GetEuclideanDistanceToPoint_SecondPointIsClosest_ReturnExpectedDistance( + double x, double y) + { + // Setup + var point = new Point2D(x, y); + var segment = new Segment2D(new Point2D(1.1, 2.2), new Point2D(3.3, 4.4)); + + // Call + var actualDistance = segment.GetEuclideanDistanceToPoint(point); + + // Assert + var expectedDistance = point.GetEuclideanDistanceTo(segment.SecondPoint); + Assert.AreEqual(expectedDistance, actualDistance); + } + } +} \ No newline at end of file Index: Core/Common/test/Core.Common.Base.Test/packages.config =================================================================== diff -u -reb1b14612c89bbd3d11e3be8c6571b306f2cfe8d -rfcc49aac894f989182fb9faa487e50a585fbed03 --- Core/Common/test/Core.Common.Base.Test/packages.config (.../packages.config) (revision eb1b14612c89bbd3d11e3be8c6571b306f2cfe8d) +++ Core/Common/test/Core.Common.Base.Test/packages.config (.../packages.config) (revision fcc49aac894f989182fb9faa487e50a585fbed03) @@ -1,5 +1,6 @@  + \ No newline at end of file Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/FileImporters/FailureMechanismSectionsImporter.cs =================================================================== diff -u --- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/FileImporters/FailureMechanismSectionsImporter.cs (revision 0) +++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/FileImporters/FailureMechanismSectionsImporter.cs (revision fcc49aac894f989182fb9faa487e50a585fbed03) @@ -0,0 +1,74 @@ +using System; +using System.Drawing; + +using Core.Common.Base.IO; + +using Ringtoets.Common.Forms.PresentationObjects; +using Ringtoets.Common.IO; + +using RingtoetsCommonDataResources = Ringtoets.Common.Data.Properties.Resources; +using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; +using CoreCommonBaseResources = Core.Common.Base.Properties.Resources; + +namespace Ringtoets.Integration.Plugin.FileImporters +{ + public class FailureMechanismSectionsImporter : FileImporterBase + { + public override string Name + { + get + { + return RingtoetsCommonDataResources.FailureMechanism_Sections_DisplayName; + } + } + + public override string Category + { + get + { + return RingtoetsCommonFormsResources.Ringtoets_Category; + } + } + + public override Bitmap Image + { + get + { + return RingtoetsCommonFormsResources.Sections; + } + } + + public override Type SupportedItemType + { + get + { + return typeof(FailureMechanismSectionsContext); + } + } + + public override string FileFilter + { + get + { + return string.Format("{0} shapefile (*.shp)|*.shp", Name); + } + } + + public override ProgressChangedDelegate ProgressChanged { protected get; set; } + + public override bool Import(object targetItem, string filePath) + { + var context = (FailureMechanismSectionsContext)targetItem; + using (var reader = new FailureMechanismSectionReader(filePath)) + { + var count = reader.GetFailureMechanismSectionCount(); + for (int i = 0; i < count; i++) + { + var section = reader.ReadFailureMechanismSection(); + context.ParentFailureMechanism.AddSection(section); + } + } + return true; + } + } +} \ No newline at end of file Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/FileImporters/ReferenceLineImporter.cs =================================================================== diff -u -r92c80139745549b255ace72885de2a7851e5fb74 -rfcc49aac894f989182fb9faa487e50a585fbed03 --- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/FileImporters/ReferenceLineImporter.cs (.../ReferenceLineImporter.cs) (revision 92c80139745549b255ace72885de2a7851e5fb74) +++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/FileImporters/ReferenceLineImporter.cs (.../ReferenceLineImporter.cs) (revision fcc49aac894f989182fb9faa487e50a585fbed03) @@ -34,7 +34,6 @@ using Ringtoets.Common.Data; using Ringtoets.Common.IO; -using Ringtoets.Integration.Data; using Ringtoets.Integration.Forms.PresentationObjects; using Ringtoets.Integration.Plugin.Properties; Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Ringtoets.Integration.Plugin.csproj =================================================================== diff -u -r7144ed9829e56a34e064267053216ffbcf6cff52 -rfcc49aac894f989182fb9faa487e50a585fbed03 --- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Ringtoets.Integration.Plugin.csproj (.../Ringtoets.Integration.Plugin.csproj) (revision 7144ed9829e56a34e064267053216ffbcf6cff52) +++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Ringtoets.Integration.Plugin.csproj (.../Ringtoets.Integration.Plugin.csproj) (revision fcc49aac894f989182fb9faa487e50a585fbed03) @@ -59,6 +59,7 @@ Properties\GlobalAssembly.cs + Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsGuiPlugin.cs =================================================================== diff -u -r76ace4042e4e8a92a0ba37e8e9a9373ed6cea951 -rfcc49aac894f989182fb9faa487e50a585fbed03 --- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsGuiPlugin.cs (.../RingtoetsGuiPlugin.cs) (revision 76ace4042e4e8a92a0ba37e8e9a9373ed6cea951) +++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsGuiPlugin.cs (.../RingtoetsGuiPlugin.cs) (revision fcc49aac894f989182fb9faa487e50a585fbed03) @@ -157,6 +157,9 @@ { Text = context => RingtoetsCommonDataResources.FailureMechanism_Sections_DisplayName, Image = context => RingtoetsCommonFormsResources.Sections, + ForeColor = context => context.WrappedData.Any() ? + Color.FromKnownColor(KnownColor.ControlText) : + Color.FromKnownColor(KnownColor.GrayText), ContextMenuStrip = FailureMechanismSectionsContextMenuStrip }; Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/FailureMechanismSectionsContextTreeNodeInfoTest.cs =================================================================== diff -u -r76ace4042e4e8a92a0ba37e8e9a9373ed6cea951 -rfcc49aac894f989182fb9faa487e50a585fbed03 --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/FailureMechanismSectionsContextTreeNodeInfoTest.cs (.../FailureMechanismSectionsContextTreeNodeInfoTest.cs) (revision 76ace4042e4e8a92a0ba37e8e9a9373ed6cea951) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/FailureMechanismSectionsContextTreeNodeInfoTest.cs (.../FailureMechanismSectionsContextTreeNodeInfoTest.cs) (revision fcc49aac894f989182fb9faa487e50a585fbed03) @@ -1,5 +1,7 @@ -using System.Linq; +using System.Drawing; +using System.Linq; +using Core.Common.Base.Geometry; using Core.Common.Controls.TreeView; using Core.Common.Gui; using Core.Common.Gui.ContextMenu; @@ -12,6 +14,7 @@ using Ringtoets.Common.Data; using Ringtoets.Common.Forms.PresentationObjects; using Ringtoets.Integration.Plugin; + using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; namespace Ringtoets.Integration.Forms.Test.TreeNodeInfos @@ -106,5 +109,50 @@ // Assert mocks.VerifyAll(); } + + [Test] + public void ForeColor_NoSectionsOnFailureMechanism_ReturnGrayText() + { + // Setup + var assessmentSection = mocks.Stub(); + var failureMechanism = mocks.Stub(); + failureMechanism.Stub(fm => fm.Sections).Return(Enumerable.Empty()); + mocks.ReplayAll(); + + var context = new FailureMechanismSectionsContext(failureMechanism, assessmentSection); + + // Call + Color color = info.ForeColor(context); + + // Assert + Assert.AreEqual(Color.FromKnownColor(KnownColor.GrayText), color); + mocks.VerifyAll(); + } + + [Test] + public void ForeColor_HasSectionsOnFailureMechanism_ReturnControlText() + { + // Setup + var assessmentSection = mocks.Stub(); + var failureMechanism = mocks.Stub(); + failureMechanism.Stub(fm => fm.Sections).Return(new[] + { + new FailureMechanismSection("A", new[] + { + new Point2D(3, 4), + new Point2D(5, 6) + }), + }); + mocks.ReplayAll(); + + var context = new FailureMechanismSectionsContext(failureMechanism, assessmentSection); + + // Call + Color color = info.ForeColor(context); + + // Assert + Assert.AreEqual(Color.FromKnownColor(KnownColor.ControlText), color); + mocks.VerifyAll(); + } } } \ No newline at end of file Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/FileImporters/FailureMechanismSectionsImporterTest.cs =================================================================== diff -u --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/FileImporters/FailureMechanismSectionsImporterTest.cs (revision 0) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/FileImporters/FailureMechanismSectionsImporterTest.cs (revision fcc49aac894f989182fb9faa487e50a585fbed03) @@ -0,0 +1,153 @@ +using System.Collections.Generic; +using System.Linq; + +using Core.Common.Base.Geometry; +using Core.Common.Base.IO; +using Core.Common.TestUtil; + +using NUnit.Framework; + +using Rhino.Mocks; + +using Ringtoets.Common.Data; +using Ringtoets.Common.Forms.PresentationObjects; +using Ringtoets.Integration.Forms.PresentationObjects; +using Ringtoets.Integration.Plugin.FileImporters; + +using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; + +namespace Ringtoets.Integration.Plugin.Test.FileImporters +{ + [TestFixture] + public class FailureMechanismSectionsImporterTest + { + [Test] + public void Constructor_ExpectedValues() + { + // Setup + + // Call + var importer = new FailureMechanismSectionsImporter(); + + // Assert + Assert.IsInstanceOf(importer); + Assert.AreEqual("Vakindeling", importer.Name); + Assert.AreEqual("Algemeen", importer.Category); + TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.Sections, importer.Image); + Assert.AreEqual(typeof(FailureMechanismSectionsContext), importer.SupportedItemType); + Assert.AreEqual("Vakindeling shapefile (*.shp)|*.shp", importer.FileFilter); + } + + [Test] + public void Import_ValidFileCorrespondingToReferenceLine_ImportSections() + { + // Setup + var referenceLineFilePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, "traject_1-1.shp"); + var sectionsFilePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, "traject_1-1_vakken.shp"); + + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var referenceLineContext = new ReferenceLineContext(assessmentSection); + + var referenceLineImporter = new ReferenceLineImporter(); + referenceLineImporter.Import(referenceLineContext, referenceLineFilePath); + + var importer = new FailureMechanismSectionsImporter(); + + var failureMechanism = new SimpleFailureMechanism(); + var failureMechanismSectionsContext = new FailureMechanismSectionsContext(failureMechanism, assessmentSection); + + // Call + var importSuccesful = importer.Import(failureMechanismSectionsContext, sectionsFilePath); + + // Assert + Assert.IsTrue(importSuccesful); + + FailureMechanismSection[] sections = failureMechanism.Sections.ToArray(); + Assert.AreEqual(62, sections.Length); + AssertSectionsAreValidForReferenceLine(sections, assessmentSection.ReferenceLine); + mocks.VerifyAll(); + } + + private void AssertSectionsAreValidForReferenceLine(FailureMechanismSection[] sections, ReferenceLine referenceLine) + { + Point2D[] referenceLineGeometry = referenceLine.Points.ToArray(); + + // 1. Start & End coherence: + Assert.AreEqual(referenceLineGeometry[0], sections[0].GetStart(), + "Start of the sections should correspond to the Start of the reference line."); + Assert.AreEqual(referenceLineGeometry[referenceLineGeometry.Length - 1], sections[sections.Length-1].GetLast(), + "End of the sections should correspond to the End of the reference line."); + + // 2. Total length coherence: + var totalLengthOfSections = sections.Sum(s => GetLengthOfLine(s.Points)); + var totalLengthOfReferenceLine = GetLengthOfLine(referenceLineGeometry); + Assert.AreEqual(totalLengthOfReferenceLine, totalLengthOfSections, 1e-6, + "The length of all sections should sum up to the length of the reference line."); + + // 3. Section Start and End coherence + IEnumerable allStartAndEndPoints = sections.Select(s => s.GetStart()).Concat(sections.Select(s => s.GetLast())); + foreach (Point2D point in allStartAndEndPoints) + { + Assert.Less(GetDistanceToReferenceLine(point, referenceLine), 1e-6, + "All start- and end points should be on the reference line."); + } + + // 4. Section Start and End points coherence + FailureMechanismSection sectionTowardsEnd = null; + foreach (FailureMechanismSection section in sections) + { + FailureMechanismSection sectionTowardsStart = sectionTowardsEnd; + sectionTowardsEnd = section; + + if (sectionTowardsStart != null) + { + Assert.AreEqual(sectionTowardsStart.GetLast(), sectionTowardsEnd.GetStart(), + "All sections should be connected and in order of connectedness."); + } + } + } + + private double GetDistanceToReferenceLine(Point2D point, ReferenceLine referenceLine) + { + return GetLineSegments(referenceLine.Points) + .Select(segment => segment.GetEuclideanDistanceToPoint(point)) + .Min(); + } + + private double GetLengthOfLine(IEnumerable linePoints) + { + return GetLineSegments(linePoints).Sum(segment => segment.Length); + } + + private IEnumerable GetLineSegments(IEnumerable linePoints) + { + Point2D firstPoint = null; + foreach (Point2D linePoint in linePoints) + { + Point2D secondPoint = firstPoint; + firstPoint = linePoint; + + if (secondPoint != null) + { + yield return new Segment2D(firstPoint, secondPoint); + } + } + } + + private class SimpleFailureMechanism : BaseFailureMechanism + { + public SimpleFailureMechanism() : base("Stubbed name") {} + + public override IEnumerable CalculationItems + { + get + { + throw new System.NotImplementedException(); + } + } + } + } +} \ No newline at end of file Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Ringtoets.Integration.Plugin.Test.csproj =================================================================== diff -u -r2ad324afda61327592af1226a9d8d3de01b614be -rfcc49aac894f989182fb9faa487e50a585fbed03 --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Ringtoets.Integration.Plugin.Test.csproj (.../Ringtoets.Integration.Plugin.Test.csproj) (revision 2ad324afda61327592af1226a9d8d3de01b614be) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Ringtoets.Integration.Plugin.Test.csproj (.../Ringtoets.Integration.Plugin.Test.csproj) (revision fcc49aac894f989182fb9faa487e50a585fbed03) @@ -69,6 +69,7 @@ + Index: Ringtoets/Piping/src/Ringtoets.Piping.Data/Properties/Resources.Designer.cs =================================================================== diff -u -r82c08997cab1058c739a21c9339e4fef59ee58ff -rfcc49aac894f989182fb9faa487e50a585fbed03 --- Ringtoets/Piping/src/Ringtoets.Piping.Data/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 82c08997cab1058c739a21c9339e4fef59ee58ff) +++ Ringtoets/Piping/src/Ringtoets.Piping.Data/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision fcc49aac894f989182fb9faa487e50a585fbed03) @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.34209 +// Runtime Version:4.0.30319.18444 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -297,15 +297,6 @@ } /// - /// Looks up a localized string similar to Voor het maken van een segment zijn twee punten nodig.. - /// - public static string Segment2D_Constructor_Segment_must_be_created_with_two_points { - get { - return ResourceManager.GetString("Segment2D_Constructor_Segment_must_be_created_with_two_points", resourceCulture); - } - } - - /// /// Looks up a localized string similar to Standaard afwijking (σ) moet groter zijn dan 0.. /// public static string StandardDeviation_Should_be_greater_than_zero { Index: Ringtoets/Piping/src/Ringtoets.Piping.Data/Properties/Resources.resx =================================================================== diff -u -r82c08997cab1058c739a21c9339e4fef59ee58ff -rfcc49aac894f989182fb9faa487e50a585fbed03 --- Ringtoets/Piping/src/Ringtoets.Piping.Data/Properties/Resources.resx (.../Resources.resx) (revision 82c08997cab1058c739a21c9339e4fef59ee58ff) +++ Ringtoets/Piping/src/Ringtoets.Piping.Data/Properties/Resources.resx (.../Resources.resx) (revision fcc49aac894f989182fb9faa487e50a585fbed03) @@ -129,9 +129,6 @@ Een kansverdeling moet opgegeven zijn om op basis van die data een rekenwaarde te bepalen. - - Voor het maken van een segment zijn twee punten nodig. - Kans moet in het bereik van [0, 1] opgegeven worden. Index: Ringtoets/Piping/src/Ringtoets.Piping.Data/Ringtoets.Piping.Data.csproj =================================================================== diff -u -r428346aca4810ed68d8778943246f581cb1a4386 -rfcc49aac894f989182fb9faa487e50a585fbed03 --- Ringtoets/Piping/src/Ringtoets.Piping.Data/Ringtoets.Piping.Data.csproj (.../Ringtoets.Piping.Data.csproj) (revision 428346aca4810ed68d8778943246f581cb1a4386) +++ Ringtoets/Piping/src/Ringtoets.Piping.Data/Ringtoets.Piping.Data.csproj (.../Ringtoets.Piping.Data.csproj) (revision fcc49aac894f989182fb9faa487e50a585fbed03) @@ -79,7 +79,6 @@ True Resources.resx - Fisheye: Tag fcc49aac894f989182fb9faa487e50a585fbed03 refers to a dead (removed) revision in file `Ringtoets/Piping/src/Ringtoets.Piping.Data/Segment2D.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/Builders/SoilLayer2D.cs =================================================================== diff -u -ra3c8c0cb4384de51a18d77cc7bea487f97ba21e1 -rfcc49aac894f989182fb9faa487e50a585fbed03 --- Ringtoets/Piping/src/Ringtoets.Piping.IO/Builders/SoilLayer2D.cs (.../SoilLayer2D.cs) (revision a3c8c0cb4384de51a18d77cc7bea487f97ba21e1) +++ Ringtoets/Piping/src/Ringtoets.Piping.IO/Builders/SoilLayer2D.cs (.../SoilLayer2D.cs) (revision fcc49aac894f989182fb9faa487e50a585fbed03) @@ -24,6 +24,8 @@ using System.Collections.ObjectModel; using System.Linq; +using Core.Common.Base.Geometry; + using Ringtoets.Piping.Data; using Ringtoets.Piping.Data.Calculation; using Ringtoets.Piping.IO.Properties; Fisheye: Tag fcc49aac894f989182fb9faa487e50a585fbed03 refers to a dead (removed) revision in file `Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/Point2DTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag fcc49aac894f989182fb9faa487e50a585fbed03 refers to a dead (removed) revision in file `Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/Point3DTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/Ringtoets.Piping.Data.Test.csproj =================================================================== diff -u -r428346aca4810ed68d8778943246f581cb1a4386 -rfcc49aac894f989182fb9faa487e50a585fbed03 --- Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/Ringtoets.Piping.Data.Test.csproj (.../Ringtoets.Piping.Data.Test.csproj) (revision 428346aca4810ed68d8778943246f581cb1a4386) +++ Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/Ringtoets.Piping.Data.Test.csproj (.../Ringtoets.Piping.Data.Test.csproj) (revision fcc49aac894f989182fb9faa487e50a585fbed03) @@ -68,7 +68,6 @@ - @@ -77,9 +76,7 @@ - - Fisheye: Tag fcc49aac894f989182fb9faa487e50a585fbed03 refers to a dead (removed) revision in file `Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/Segment2DTest.cs'. Fisheye: No comparison available. Pass `N' to diff?