|
1 | | -using System; |
| 1 | +using System; |
| 2 | +using System.Linq; |
2 | 3 | using MathNet.Spatial.Euclidean; |
3 | 4 | using NUnit.Framework; |
4 | 5 |
|
@@ -58,5 +59,125 @@ public void CircleFromThreePointsArgumentException() |
58 | 59 |
|
59 | 60 | Assert.Throws<ArgumentException>(() => { Circle2D.FromPoints(p1, p2, p3); }); |
60 | 61 | } |
| 62 | + |
| 63 | + //parallel to the X-axis |
| 64 | + [TestCase("0,0", 1, "-10,-10", "+10,-10", null)] |
| 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 | + [TestCase("0,0", 1, "-10,+10", "+10,+10", null)] |
| 69 | + //parallel to the Y-axis |
| 70 | + [TestCase("0,0", 1, "-10,-10", "-10,+10", null)] |
| 71 | + [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, "+1,-10", "+1,+10", "+1,0")] |
| 74 | + [TestCase("0,0", 1, "+10,-10", "+10,+10", null)] |
| 75 | + //general cases |
| 76 | + [TestCase("0,0", 1, "-10,+10", "+10,+10", null)] |
| 77 | + [TestCase("0,0", 1, "-1.414213562373095,0", "0,+1.414213562373095", "-0.707,0.707")] |
| 78 | + [TestCase("0,0", 1, "-10,-10", "+10,+10", "+0.707,+0.707;-0.707,-0.707")] |
| 79 | + [TestCase("0,0", 1, "0,-1.41421356", "+1.41421356,0", "+0.707,-0.707")] |
| 80 | + [TestCase("0,0", 1, "0,-10", "+10,0", null)] |
| 81 | + public void CircleIntersectWithLine2D(string sc, double radius, string sps, string spe, string intersections) |
| 82 | + { |
| 83 | + var circle = new Circle2D(Point2D.Parse(sc), radius); |
| 84 | + var line = new Line2D(Point2D.Parse(sps), Point2D.Parse(spe)); |
| 85 | + |
| 86 | + var actual = circle.IntersectWith(line); |
| 87 | + |
| 88 | + var expected = parseToPointsArray(intersections); |
| 89 | + for (int i = 0; i < Math.Min(actual.Length, expected.Length); i++) |
| 90 | + { |
| 91 | + var a = actual[i]; |
| 92 | + var e = expected[i]; |
| 93 | + AssertGeometry.AreEqual(a, e, 1e-3); //needs to fix for the default tolerance |
| 94 | + } |
| 95 | + } |
| 96 | + //parallel to X-axis |
| 97 | + ////segment contains the all intersections(same to the cases of circle and line) |
| 98 | + [TestCase("0,0", 1, "-10,+10", "+10,+10", null)] |
| 99 | + [TestCase("0,0", 1, "-10,+1", "+10,+1", "0,+1")] |
| 100 | + [TestCase("0,0", 1, "-10,0", "+10,0", "+1,0;-1,0")] |
| 101 | + [TestCase("0,0", 1, "-10,-1", "+10,-1", "0,-1")] |
| 102 | + [TestCase("0,0", 1, "-10,-10", "+10,-10", null)] |
| 103 | + ////segments cross the circle's contour just 1 time |
| 104 | + [TestCase("0,0", 1, "+0,+10", "+10,+10", null)] |
| 105 | + [TestCase("0,0", 1, "+0,+1", "+10,+1", "0,1")] |
| 106 | + [TestCase("0,0", 1, "+0,+0", "+10,+0", "1,0")] |
| 107 | + [TestCase("0,0", 1, "+0,-1", "+10,-1", "0,-1")] |
| 108 | + [TestCase("0,0", 1, "+0,-10", "+10,-10", null)] |
| 109 | + ////segment contains no intersections(px of the startingPoint is too big to intersect with the circle) |
| 110 | + [TestCase("0,0", 1, "+10,+10", "+100,+10", null)] |
| 111 | + [TestCase("0,0", 1, "+10,+1", "+100,+1", null)] |
| 112 | + [TestCase("0,0", 1, "+10,+0", "+100,0", null)] |
| 113 | + [TestCase("0,0", 1, "+10,-1", "+100,-1", null)] |
| 114 | + [TestCase("0,0", 1, "+10,-10", "+100,-10", null)] |
| 115 | + //parallel to Y-axis |
| 116 | + ////segment contains the all intersections(same to the cases of circle and line) |
| 117 | + [TestCase("0,0", 1, "-10,-10", "-10,+10", null)] |
| 118 | + [TestCase("0,0", 1, "-1,-10", "-1,+10", "-1,0")] |
| 119 | + [TestCase("0,0", 1, "+0,-10", "+0,+10", "0,+1;0,-1")] |
| 120 | + [TestCase("0,0", 1, "+1,-10", "+1,+10", "+1,0")] |
| 121 | + [TestCase("0,0", 1, "+10,-10", "+10,+10", null)] |
| 122 | + ////segments cross the circle's contour just 1 time |
| 123 | + [TestCase("0,0", 1, "+10,0", "+10,+10", null)] |
| 124 | + [TestCase("0,0", 1, "+1,0", "+1,+10", "+1,0")] |
| 125 | + [TestCase("0,0", 1, "+0,0", "+0,+10", "0,+1")] |
| 126 | + [TestCase("0,0", 1, "-1,0", "-1,+10", "-1,0")] |
| 127 | + [TestCase("0,0", 1, "-10,0", "-10,+10", null)] |
| 128 | + ////segment contains no intersections(py of the startingPoint is too big to intersect with the circle) |
| 129 | + [TestCase("0,0", 1, "+10,+10", "+10,+100", null)] |
| 130 | + [TestCase("0,0", 1, "+1,+10", "+1,+100", null)] |
| 131 | + [TestCase("0,0", 1, "+0,+10", "+0,+100", null)] |
| 132 | + [TestCase("0,0", 1, "-1,+10", "-1,+100", null)] |
| 133 | + [TestCase("0,0", 1, "-10,+10", "-10,+100", null)] |
| 134 | + //general cases |
| 135 | + ////segment contains the all intersections(same to the cases of circle and line) |
| 136 | + [TestCase("0,0", 1, "-10,+10", "+10,+10", null)] |
| 137 | + [TestCase("0,0", 1, "-1.414213562373095,0", "0,+1.414213562373095", "-0.707,0.707")] |
| 138 | + [TestCase("0,0", 1, "-10,-10", "+10,+10", "+0.707,+0.707;-0.707,-0.707")] |
| 139 | + [TestCase("0,0", 1, "0,-1.41421356", "+1.41421356,0", "+0.707,-0.707")] |
| 140 | + [TestCase("0,0", 1, "0,-10", "+10,0", null)] |
| 141 | + ////segments cross the circle's contour just 1 time |
| 142 | + [TestCase("0,0", 1, "+10,0", "+10,+10", null)] |
| 143 | + [TestCase("0,0", 1, "+1,0", "+1,+10", "+1,0")] |
| 144 | + [TestCase("0,0", 1, "+0,0", "+0,+10", "0,+1")] |
| 145 | + [TestCase("0,0", 1, "-1,0", "-1,+10", "-1,0")] |
| 146 | + [TestCase("0,0", 1, "-10,0", "-10,+10", null)] |
| 147 | + ////segment contains no intersections(py of the startingPoint is too big to intersect with the circle) |
| 148 | + [TestCase("0,0", 1, "+10,+10", "+10,+100", null)] |
| 149 | + [TestCase("0,0", 1, "+1,+10", "+1,+100", null)] |
| 150 | + [TestCase("0,0", 1, "+0,+10", "+0,+100", null)] |
| 151 | + [TestCase("0,0", 1, "-1,+10", "-1,+100", null)] |
| 152 | + [TestCase("0,0", 1, "-10,+10", "-10,+100", null)] |
| 153 | + public void CircleIntersectWithLineSegment2D(string sCenter, double radius, string sStart, string sEnd, string intersections) |
| 154 | + { |
| 155 | + var circle = new Circle2D(Point2D.Parse(sCenter), radius); |
| 156 | + var segment = new LineSegment2D(Point2D.Parse(sStart), Point2D.Parse(sEnd)); |
| 157 | + |
| 158 | + var actual = circle.IntersectWith(segment); |
| 159 | + |
| 160 | + var expected = parseToPointsArray(intersections); |
| 161 | + for (int i = 0; i < Math.Min(actual.Length, expected.Length); i++) |
| 162 | + { |
| 163 | + var a = actual[i]; |
| 164 | + var e = expected[i]; |
| 165 | + AssertGeometry.AreEqual(a, e, 1e-3); //FIXME! |
| 166 | + } |
| 167 | + } |
| 168 | + |
| 169 | + private Point2D[] parseToPointsArray(string input) |
| 170 | + { |
| 171 | + if (input == null) |
| 172 | + { |
| 173 | + return new Point2D[] { }; |
| 174 | + } |
| 175 | + |
| 176 | + var result = input.Split(';') |
| 177 | + .Select(s => Point2D.Parse(s)) |
| 178 | + .ToArray(); |
| 179 | + |
| 180 | + return result; |
| 181 | + } |
61 | 182 | } |
62 | 183 | } |
0 commit comments