Index: Core/Common/src/Core.Common.Base/Geometry/Math2D.cs
===================================================================
diff -u -r84c39f809b6fda9caf5115ed1af9f65487915f12 -re2719484be4a10aecf59be5a999943bb01688ec0
--- Core/Common/src/Core.Common.Base/Geometry/Math2D.cs (.../Math2D.cs) (revision 84c39f809b6fda9caf5115ed1af9f65487915f12)
+++ Core/Common/src/Core.Common.Base/Geometry/Math2D.cs (.../Math2D.cs) (revision e2719484be4a10aecf59be5a999943bb01688ec0)
@@ -106,11 +106,29 @@
/// Taken from: https://www.topcoder.com/community/data-science/data-science-tutorials/geometry-concepts-line-intersection-and-its-applications/
/// Based on https://en.wikipedia.org/wiki/Line%E2%80%93line_intersection
///
+ /// Thrown when , ,
+ /// or is null.
/// Thrown when equals or
/// equals , which makes it impossible to determine
/// a line through the points.
public static Point2D LineIntersectionWithLine(Point2D line1Point1, Point2D line1Point2, Point2D line2Point1, Point2D line2Point2)
{
+ if (line1Point1 == null)
+ {
+ throw new ArgumentNullException("line1Point1");
+ }
+ if (line1Point2 == null)
+ {
+ throw new ArgumentNullException("line1Point2");
+ }
+ if (line2Point1 == null)
+ {
+ throw new ArgumentNullException("line2Point1");
+ }
+ if (line2Point2 == null)
+ {
+ throw new ArgumentNullException("line2Point2");
+ }
if (line1Point1.Equals(line1Point2) || line2Point1.Equals(line2Point2))
{
throw new ArgumentException(Resources.Math2D_LineIntersectionWithLine_Line_points_are_equal);
@@ -143,6 +161,14 @@
/// True when the points are equal. False otherwise.
public static bool AreEqualPoints(Point2D point1, Point2D point2)
{
+ if (point1 == null)
+ {
+ throw new ArgumentNullException("point1");
+ }
+ if (point2 == null)
+ {
+ throw new ArgumentNullException("point2");
+ }
return Math.Abs(point1.X - point2.X) < epsilonForComparisons && Math.Abs(point1.Y - point2.Y) < epsilonForComparisons;
}
@@ -158,6 +184,11 @@
/// Segments which have length=0 or which are vertical, will not return an intersection point.
public static IEnumerable SegmentsIntersectionWithVerticalLine(IEnumerable segments, double verticalLineX)
{
+ if (segments == null)
+ {
+ throw new ArgumentNullException("segments");
+ }
+
var intersectionPointY = new Collection();
foreach (Segment2D segment in segments.Where(s => s.ContainsX(verticalLineX)))
@@ -180,6 +211,11 @@
/// The sum of the distances between consecutive points.
public static double Length(IEnumerable points)
{
+ if (points == null)
+ {
+ throw new ArgumentNullException("points");
+ }
+
double length = 0;
Point2D previousPoint = null;
@@ -205,6 +241,15 @@
/// based on method intersect2D_2Segments.
public static Segment2DIntersectSegment2DResult GetIntersectionBetweenSegments(Segment2D segment1, Segment2D segment2)
{
+ if (segment1 == null)
+ {
+ throw new ArgumentNullException("segment1");
+ }
+ if (segment2 == null)
+ {
+ throw new ArgumentNullException("segment2");
+ }
+
Vector u = segment1.SecondPoint - segment1.FirstPoint;
Vector v = segment2.SecondPoint - segment2.FirstPoint;
Vector w = segment1.FirstPoint - segment2.FirstPoint;
@@ -258,6 +303,11 @@
/// A new at the interpolated point.
public static Point2D GetInterpolatedPointAtFraction(Segment2D lineSegment, double fraction)
{
+ if (lineSegment == null)
+ {
+ throw new ArgumentNullException("lineSegment");
+ }
+
if (double.IsNaN(fraction)|| fraction < 0.0 || fraction > 1.0)
{
throw new ArgumentOutOfRangeException("fraction", "Fraction needs to be defined in range [0.0, 1.0] in order to reliably interpolate.");
Index: Core/Common/src/Core.Common.Base/IO/FileImporterBase.cs
===================================================================
diff -u -r3d84064b23186da3fb11f19ff0d07f41e1209bbb -re2719484be4a10aecf59be5a999943bb01688ec0
--- Core/Common/src/Core.Common.Base/IO/FileImporterBase.cs (.../FileImporterBase.cs) (revision 3d84064b23186da3fb11f19ff0d07f41e1209bbb)
+++ Core/Common/src/Core.Common.Base/IO/FileImporterBase.cs (.../FileImporterBase.cs) (revision e2719484be4a10aecf59be5a999943bb01688ec0)
@@ -37,11 +37,11 @@
public abstract class FileImporterBase : IFileImporter
{
///
- /// Indicates if a cancel request has been made. When true, no changes should be
- /// made to the data model unless the importer is already in progress of changing
- /// the data model.
+ /// Gets or sets value indicating if a cancel request has been made. When true, no
+ /// changes should be made to the data model unless the importer is already in progress
+ /// of changing the data model.
///
- protected bool Canceled;
+ protected bool Canceled { get; set; }
public abstract string Name { get; }
public abstract string Category { get; }
@@ -51,7 +51,7 @@
public virtual bool CanImportOn(object targetItem)
{
- return targetItem.GetType().Implements();
+ return targetItem != null && targetItem.GetType().Implements();
}
public abstract bool Import(object targetItem, string filePath);
Index: Core/Common/test/Core.Common.Base.Test/Geometry/Math2DTest.cs
===================================================================
diff -u -re3f9dffa91a0def0b6e6bc7dfabef74cc64745c5 -re2719484be4a10aecf59be5a999943bb01688ec0
--- Core/Common/test/Core.Common.Base.Test/Geometry/Math2DTest.cs (.../Math2DTest.cs) (revision e3f9dffa91a0def0b6e6bc7dfabef74cc64745c5)
+++ Core/Common/test/Core.Common.Base.Test/Geometry/Math2DTest.cs (.../Math2DTest.cs) (revision e2719484be4a10aecf59be5a999943bb01688ec0)
@@ -140,6 +140,32 @@
#endregion
[Test]
+ [TestCase(0, "line1Point1")]
+ [TestCase(1, "line1Point2")]
+ [TestCase(2, "line2Point1")]
+ [TestCase(3, "line2Point2")]
+ public void LineIntersectionWithLine_APointIsNull_ThrowsArgumentNullException(int nullIndex, string expectedParameter)
+ {
+ // Setup
+ var points = new[]
+ {
+ new Point2D(0, 0),
+ new Point2D(1, 0),
+ new Point2D(0, -1),
+ new Point2D(1, 2)
+ };
+
+ points[nullIndex] = null;
+
+ // Call
+ TestDelegate test = () => Math2D.LineIntersectionWithLine(points[0], points[1], points[2], points[3]);
+
+ // Assert
+ var paramName = Assert.Throws(test).ParamName;
+ Assert.AreEqual(expectedParameter, paramName);
+ }
+
+ [Test]
[TestCaseSource("IntersectingSegments")]
public void LineIntersectionWithLine_DifferentLineSegmentsWithIntersections_ReturnsPoint(Point2D[] points, string testname = "")
{
@@ -203,6 +229,17 @@
}
[Test]
+ public void SegmentsIntersectionWithVerticalLine_SegmentsIsNull_ThrowsArgumentNullException()
+ {
+ // Call
+ TestDelegate test = () => Math2D.SegmentsIntersectionWithVerticalLine(null, 0.0);
+
+ // Assert
+ var paramName = Assert.Throws(test).ParamName;
+ Assert.AreEqual("segments", paramName);
+ }
+
+ [Test]
[TestCase(2.5, new [] {3.3})]
[TestCase(1.1, new double[0])]
[TestCase(5.5, new double[0])]
@@ -407,7 +444,30 @@
}, lineSplits[3], doubleToleranceComparer);
}
+
[Test]
+ [TestCase(0, "segment1")]
+ [TestCase(1, "segment2")]
+ public void GetIntersectionBetweenSegments_ASegmentIsNull_ThrowsArgumentNullException(int nullIndex, string expectedParameter)
+ {
+ // Setup
+ var segments = new[]
+ {
+ new Segment2D(new Point2D(0,0), new Point2D(0,1)),
+ new Segment2D(new Point2D(0,0), new Point2D(0,1))
+ };
+
+ segments[nullIndex] = null;
+
+ // Call
+ TestDelegate test = () => Math2D.GetIntersectionBetweenSegments(segments[0], segments[1]);
+
+ // Assert
+ var paramName = Assert.Throws(test).ParamName;
+ Assert.AreEqual(expectedParameter, paramName);
+ }
+
+ [Test]
[TestCase(1234.56789)]
[TestCase(1e-6)]
[TestCase(-1e-6)]
@@ -983,6 +1043,28 @@
}
[Test]
+ [TestCase(0, "point1")]
+ [TestCase(1, "point2")]
+ public void AreEqualPoints_APointIsNull_ThrowsArgumentNullException(int nullIndex, string expectedParameter)
+ {
+ // Setup
+ var points = new[]
+ {
+ new Point2D(0, 0),
+ new Point2D(1, 0),
+ };
+
+ points[nullIndex] = null;
+
+ // Call
+ TestDelegate test = () => Math2D.AreEqualPoints(points[0], points[1]);
+
+ // Assert
+ var paramName = Assert.Throws(test).ParamName;
+ Assert.AreEqual(expectedParameter, paramName);
+ }
+
+ [Test]
public void AreEqualPoints_PointsEqual_ReturnsTrue()
{
// Call
@@ -1003,6 +1085,17 @@
}
[Test]
+ public void Length_NullPoints_ThrowsArgumentNullException()
+ {
+ // Call
+ TestDelegate test = () => Math2D.Length(null);
+
+ // Assert
+ var paramName = Assert.Throws(test).ParamName;
+ Assert.AreEqual("points", paramName);
+ }
+
+ [Test]
public void Length_EmptyCollection_ReturnsZero()
{
// Setup
@@ -1085,6 +1178,17 @@
}
[Test]
+ public void GetInterpolatedPointAtFraction_LineSegmentIsNull_ThrowsArgumentNullException()
+ {
+ // Call
+ TestDelegate test = () => Math2D.GetInterpolatedPointAtFraction(null, 0.0);
+
+ // Assert
+ var paramName = Assert.Throws(test).ParamName;
+ Assert.AreEqual("lineSegment", paramName);
+ }
+
+ [Test]
public void GetInterpolatedPoint_WithinLine_InterpolatesBetweenPoints()
{
// Setup
Index: Core/Common/test/Core.Common.Base.Test/IO/FileImporterBaseTest.cs
===================================================================
diff -u -r3d84064b23186da3fb11f19ff0d07f41e1209bbb -re2719484be4a10aecf59be5a999943bb01688ec0
--- Core/Common/test/Core.Common.Base.Test/IO/FileImporterBaseTest.cs (.../FileImporterBaseTest.cs) (revision 3d84064b23186da3fb11f19ff0d07f41e1209bbb)
+++ Core/Common/test/Core.Common.Base.Test/IO/FileImporterBaseTest.cs (.../FileImporterBaseTest.cs) (revision e2719484be4a10aecf59be5a999943bb01688ec0)
@@ -47,6 +47,19 @@
}
[Test]
+ public void CanImportOn_ObjectIsNull_ReturnFalse()
+ {
+ // Setup
+ var importer = new SimpleFileImporter();
+
+ // Call
+ var canImportOn = importer.CanImportOn(null);
+
+ // Assert
+ Assert.IsFalse(canImportOn);
+ }
+
+ [Test]
public void CanImportOn_ObjectIsOfCorrectType_ReturnTrue()
{
// Setup