|
1 | 1 | using System; |
| 2 | +using System.Collections.Generic; |
2 | 3 | using System.Linq; |
3 | 4 | using MathNet.Spatial.Euclidean; |
4 | 5 | using NUnit.Framework; |
@@ -61,29 +62,37 @@ public void CircleFromThreePointsArgumentException() |
61 | 62 | } |
62 | 63 |
|
63 | 64 | //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" )] |
68 | 65 | [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")] |
69 | 70 | //parallel to the Y-axis |
70 | 71 | [TestCase("0,0", 1, "-10,-10", "-10,+10", "empty")] |
71 | 72 | [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")] |
73 | 74 | [TestCase("0,0", 1, "+1,-10", "+1,+10", "+1,0")] |
74 | 75 | [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) |
76 | 83 | { |
77 | 84 | var circle = new Circle2D(Point2D.Parse(sc), radius); |
78 | 85 | var line = new Line2D(Point2D.Parse(sps), Point2D.Parse(spe)); |
79 | 86 |
|
80 | 87 | var actual = circle.IntersectWith(line); |
81 | 88 |
|
82 | 89 | 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 | + } |
87 | 96 | } |
88 | 97 |
|
89 | 98 | //segment contains the all intersections(same to the cases of circle and line) |
|
0 commit comments