Skip to content

Commit 6b8c3db

Browse files
committed
test: add testcases for Intersection of Circle2D with LIneSegment2D
- parallel to X-axis - parallel to Y-axis - general cases (eg. x-y+c=0) test: rename method's name
1 parent 3d3748b commit 6b8c3db

1 file changed

Lines changed: 50 additions & 7 deletions

File tree

src/Spatial.Tests/Euclidean/Circle2DTests.cs

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,34 +94,77 @@ public void CircleIntersectWithLine2D(string sc, double radius, string sps, stri
9494
AssertGeometry.AreEqual(a, e, 1e-3); //needs to fix for the default tolerance
9595
}
9696
}
97-
98-
//segment contains the all intersections(same to the cases of circle and line)
97+
//parallel to X-axis
98+
////segment contains the all intersections(same to the cases of circle and line)
9999
[TestCase("0,0", 1, "-10,+10", "+10,+10", "empty")]
100100
[TestCase("0,0", 1, "-10,+1", "+10,+1", "0,+1")]
101-
[TestCase("0,0", 1, "-10,0", "+10,0", "-1,0;+1,0")]
101+
[TestCase("0,0", 1, "-10,0", "+10,0", "+1,0;-1,0")]
102102
[TestCase("0,0", 1, "-10,-1", "+10,-1", "0,-1")]
103103
[TestCase("0,0", 1, "-10,-10", "+10,-10", "empty")]
104-
//segments cross the circle's contour just 1 time
104+
////segments cross the circle's contour just 1 time
105105
[TestCase("0,0", 1, "+0,+10", "+10,+10", "empty")]
106106
[TestCase("0,0", 1, "+0,+1", "+10,+1", "0,1")]
107107
[TestCase("0,0", 1, "+0,0", "+10,0", "1,0")]
108108
[TestCase("0,0", 1, "+0,-1", "+10,-1", "0,-1")]
109109
[TestCase("0,0", 1, "+0,-10", "+10,-10", "empty")]
110-
//segment contains no intersections(px of the startingPoint is too big to intersect with the circle)
110+
////segment contains no intersections(px of the startingPoint is too big to intersect with the circle)
111111
[TestCase("0,0", 1, "+10,+10", "+100,+10", "empty")]
112112
[TestCase("0,0", 1, "+10,+01", "+100,+1", "empty")]
113113
[TestCase("0,0", 1, "+10,+00", "+100,0", "empty")]
114114
[TestCase("0,0", 1, "+10,-01", "+100,-1", "empty")]
115115
[TestCase("0,0", 1, "+10,-10", "+100,-10", "empty")]
116-
public void CircleIntersectWithLineSegment2D_NumberOfIntersections(string sCenter, double radius, string sStart, string sEnd, string expectedIntersectionsAsString)
116+
//parallel to Y-axis
117+
////segment contains the all intersections(same to the cases of circle and line)
118+
[TestCase("0,0", 1, "-10,-10", "-10,+10", "empty")]
119+
[TestCase("0,0", 1, "-1,-10", "-1,+10", "-1,0")]
120+
[TestCase("0,0", 1, "0,-10", "0,+10", "0,+1;0,-1")]
121+
[TestCase("0,0", 1, "+1,-10", "+1,+10", "+1,0")]
122+
[TestCase("0,0", 1, "+10,-10", "+10,+10", "EMPTY")]
123+
////segments cross the circle's contour just 1 time
124+
[TestCase("0,0", 1, "+10,0", "+10,+10", "empty")]
125+
[TestCase("0,0", 1, "+1,0", "+1,+10", "+1,0")]
126+
[TestCase("0,0", 1, "0,0", "0,+10", "0,+1")]
127+
[TestCase("0,0", 1, "-1,0", "-1,+10", "-1,0")]
128+
[TestCase("0,0", 1, "-10,0", "-10,+10", "empty")]
129+
////segment contains no intersections(py of the startingPoint is too big to intersect with the circle)
130+
[TestCase("0,0", 1, "+10,+10", "+10,+100", "empty")]
131+
[TestCase("0,0", 1, "+01,+10", "+1,+100", "empty")]
132+
[TestCase("0,0", 1, "+00,+10", "0,+100", "empty")]
133+
[TestCase("0,0", 1, "-01,+10", "-1,+100", "empty")]
134+
[TestCase("0,0", 1, "-10,+10", "-10,+100", "empty")]
135+
//general cases
136+
////segment contains the all intersections(same to the cases of circle and line)
137+
[TestCase("0,0", 1, "-10,+10", "+10,+10", "empty")]
138+
[TestCase("0,0", 1, "-1.414213562373095,0", "0,+1.414213562373095", "-0.707,0.707")]
139+
[TestCase("0,0", 1, "-10,-10", "+10,+10", "+0.707,+0.707;-0.707,-0.707")]
140+
[TestCase("0,0", 1, "0,-1.41421356", "+1.41421356,0", "+0.707,-0.707")]
141+
[TestCase("0,0", 1, "0,-10", "+10,0", "empty")]
142+
////segments cross the circle's contour just 1 time
143+
[TestCase("0,0", 1, "+10,0", "+10,+10", "empty")]
144+
[TestCase("0,0", 1, "+1,0", "+1,+10", "+1,0")]
145+
[TestCase("0,0", 1, "0,0", "0,+10", "0,+1")]
146+
[TestCase("0,0", 1, "-1,0", "-1,+10", "-1,0")]
147+
[TestCase("0,0", 1, "-10,0", "-10,+10", "empty")]
148+
////segment contains no intersections(py of the startingPoint is too big to intersect with the circle)
149+
[TestCase("0,0", 1, "+10,+10", "+10,+100", "empty")]
150+
[TestCase("0,0", 1, "+01,+10", "+1,+100", "empty")]
151+
[TestCase("0,0", 1, "+00,+10", "0,+100", "empty")]
152+
[TestCase("0,0", 1, "-01,+10", "-1,+100", "empty")]
153+
[TestCase("0,0", 1, "-10,+10", "-10,+100", "empty")]
154+
public void CircleIntersectWithLineSegment2D(string sCenter, double radius, string sStart, string sEnd, string expectedIntersectionsAsString)
117155
{
118156
var circle = new Circle2D(Point2D.Parse(sCenter), radius);
119157
var segment = new LineSegment2D(Point2D.Parse(sStart), Point2D.Parse(sEnd));
120158

121159
var actual = circle.IntersectWith(segment);
122160

123161
var expected = parseToPointsArray(expectedIntersectionsAsString);
124-
CollectionAssert.AreEquivalent(expected, actual);
162+
for (int i = 0; i < Math.Min(actual.Length, expected.Length); i++)
163+
{
164+
var a = actual[i];
165+
var e = expected[i];
166+
AssertGeometry.AreEqual(a, e, 1e-3); //needs to fix for the default tolerance
167+
}
125168
}
126169

127170
private Point2D[] parseToPointsArray(string input)

0 commit comments

Comments
 (0)