Skip to content

Commit 3d3748b

Browse files
committed
test: add testcases parallel to Y-axis and general cases
1 parent 451a87d commit 3d3748b

1 file changed

Lines changed: 19 additions & 10 deletions

File tree

src/Spatial.Tests/Euclidean/Circle2DTests.cs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Linq;
34
using MathNet.Spatial.Euclidean;
45
using NUnit.Framework;
@@ -61,29 +62,37 @@ public void CircleFromThreePointsArgumentException()
6162
}
6263

6364
//parallel to the X-axis
64-
[TestCase("0,0", 1, "-10,+10", "+10,+10", "empty")]
65-
[TestCase("0,0", 1, "-10,+1", "+10,+1", "0,+1")]
66-
[TestCase("0,0", 1, "-10,0", "+10,0", "-1,0;+1,0")]
67-
[TestCase("0,0", 1, "-10,-1", "+10,-1", "0,-1" )]
6865
[TestCase("0,0", 1, "-10,-10", "+10,-10", "empty")]
66+
[TestCase("0,0", 1, "-10,-1", "+10,-1", "0,-1")]
67+
[TestCase("0,0", 1, "-10,0", "+10,0", "+1,0;-1,0")]
68+
[TestCase("0,0", 1, "-10,+1", "+10,+1", "0,+1")]
69+
[TestCase("0,0", 1, "-10,+10", "+10,+10", "empty")]
6970
//parallel to the Y-axis
7071
[TestCase("0,0", 1, "-10,-10", "-10,+10", "empty")]
7172
[TestCase("0,0", 1, "-1,-10", "-1,+10", "-1,0")]
72-
[TestCase("0,0", 1, "0,-10", "0,+10", "0,-1;0,+1")]
73+
[TestCase("0,0", 1, "0,-10", "0,+10", "0,+1;0,-1")]
7374
[TestCase("0,0", 1, "+1,-10", "+1,+10", "+1,0")]
7475
[TestCase("0,0", 1, "+10,-10", "+10,+10", "empty")]
75-
public void CircleIntersectWithLine2D_NumberOfIntersections(string sc, double radius, string sps, string spe, string expectedIntersectionsAsString)
76+
//general cases
77+
[TestCase("0,0", 1, "-10,+10", "+10,+10", "empty")]
78+
[TestCase("0,0", 1, "-1.414213562373095,0", "0,+1.414213562373095", "-0.707,0.707")]
79+
[TestCase("0,0", 1, "-10,-10", "+10,+10", "+0.707,+0.707;-0.707,-0.707")]
80+
[TestCase("0,0", 1, "0,-1.41421356", "+1.41421356,0", "+0.707,-0.707")]
81+
[TestCase("0,0", 1, "0,-10", "+10,0", "empty")]
82+
public void CircleIntersectWithLine2D(string sc, double radius, string sps, string spe, string expectedIntersectionsAsString)
7683
{
7784
var circle = new Circle2D(Point2D.Parse(sc), radius);
7885
var line = new Line2D(Point2D.Parse(sps), Point2D.Parse(spe));
7986

8087
var actual = circle.IntersectWith(line);
8188

8289
var expected = parseToPointsArray(expectedIntersectionsAsString);
83-
CollectionAssert.AreEquivalent(expected, actual);
84-
//TODO: the intersection should be on the circle
85-
Assert.That(actual.All(p => Math.Abs(circle.Center.DistanceTo(p) - circle.Radius) < 1e-6), Is.EqualTo(true), "distance between center and intersection");
86-
//TODO: the intersection should be on the line
90+
for (int i = 0; i < Math.Min(actual.Length, expected.Length); i++)
91+
{
92+
var a = actual[i];
93+
var e = expected[i];
94+
AssertGeometry.AreEqual(a, e, 1e-3); //needs to fix for the default tolerance
95+
}
8796
}
8897

8998
//segment contains the all intersections(same to the cases of circle and line)

0 commit comments

Comments
 (0)