Explorar o código

Test line intersects circle.

Sam Jaffe %!s(int64=6) %!d(string=hai) anos
pai
achega
ec566ee5b3
Modificáronse 1 ficheiros con 35 adicións e 5 borrados
  1. 35 5
      math/test/common_test.cxx

+ 35 - 5
math/test/common_test.cxx

@@ -141,32 +141,62 @@ TEST_F(LineQuadTest, OutsideByAnInch) {
 
 INSTANTIATE_TEST_CASE_P(Intersects, LineQuadTest, ValuesIn(line_ends));
 
-TEST(CircleTest, IntersectsSelf) {
+TEST(CircleTest, CircleIntersectsSelf) {
   circle const c1{{{0, 0}}, 1};
   circle const c2{{{0, 0}}, 1};
   EXPECT_TRUE(math::intersects(c1, c2));
 }
 
-TEST(CircleTest, IntersectsAtOnePoint) {
+TEST(CircleTest, CircleIntersectsAtOnePoint) {
   circle const c1{{{0, 0}}, 1};
   circle const c2{{{0, 2}}, 1};
   EXPECT_TRUE(math::intersects(c1, c2));
 }
 
-TEST(CircleTest, IntersectsWithChord) {
+TEST(CircleTest, CircleIntersectsWithChord) {
   circle const c1{{{0, 0}}, 0.5};
   circle const c2{{{0, 1}}, 0.5};
   EXPECT_TRUE(math::intersects(c1, c2));
 }
 
-TEST(CircleTest, ContainedWithin) {
+TEST(CircleTest, CircleContainedWithin) {
   circle const c1{{{0, 0}}, 2};
   circle const c2{{{0, 1}}, 0.5};
   EXPECT_TRUE(math::intersects(c1, c2));
 }
 
-TEST(CircleTest, Outside) {
+TEST(CircleTest, CircleOutsideDoesNotIntersect) {
   circle const c1{{{0, 0}}, 1};
   circle const c2{{{1.5, 1.5}}, 1};
   EXPECT_FALSE(math::intersects(c1, c2));
 }
+
+TEST(CircleTest, LineIntersectsFromWithin) {
+  circle const c1{{{0, 0}}, 1};
+  line const ln{{{0.5, 0.5}}, {{1, 1}}};
+  EXPECT_TRUE(math::intersects(c1, ln));
+}
+
+TEST(CircleTest, LineIntersectsOnEdge) {
+  circle const c1{{{0, 0}}, 1};
+  line const ln{{{-1, 1}}, {{1, 1}}};
+  EXPECT_TRUE(math::intersects(c1, ln));
+}
+
+TEST(CircleTest, LineIntersectsWhenContained) {
+  circle const c1{{{0, 0}}, 1};
+  line const ln{{{0.5, 0.5}}, {{-0.5, -0.5}}};
+  EXPECT_TRUE(math::intersects(c1, ln));
+}
+
+TEST(CircleTest, ChordLineIntersects) {
+  circle const c1{{{0, 0}}, 1};
+  line const ln{{{1, 1}}, {{-1, 0.5}}};
+  EXPECT_TRUE(math::intersects(c1, ln));
+}
+
+TEST(CircleTest, OutsideLineDoesntIntersect) {
+  circle const c1{{{0, 0}}, 1};
+  line const ln{{{1, 1}}, {{0, 1.5}}};
+  EXPECT_FALSE(math::intersects(c1, ln));
+}