MCPcopy Create free account
hub / github.com/davisking/dlib / test_polygon

Function test_polygon

dlib/test/geometry.cpp:922–951  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

920// ----------------------------------------------------------------------------------------
921
922 void test_polygon()
923 {
924 print_spinner();
925 /* Let's define this triangle
926 * 0 . . . . . . . . . . .
927 * 1 . . . . . . . . .
928 * 2 . . . . . . .
929 * 3 . . . . .
930 * 4 . . .
931 * 5 .
932 * 0 1 2 3 4 5 6 7 8 9 10
933 */
934
935 const polygon triangle({{0, 0}, {5, 5}, {10, 0}});
936 DLIB_TEST(triangle.area() == 25);
937
938 const rectangle rect = triangle.get_rect();
939 std::vector<double> left_boundary;
940 std::vector<double> right_boundary;
941 triangle.get_left_and_right_bounds(rect.top(), rect.bottom(), left_boundary, right_boundary);
942
943 DLIB_TEST(left_boundary.size() == right_boundary.size());
944
945 const long top = rect.top();
946 const long bottom = rect.bottom();
947 for (long y = top, i = 0; y <= bottom; ++y, ++i)
948 DLIB_TEST(left_boundary[y - top] == i);
949 for (long y = top, i = 10; y <= bottom; ++y, --i)
950 DLIB_TEST(right_boundary[y - top] == i);
951 }
952
953// ----------------------------------------------------------------------------------------
954

Callers 1

perform_testMethod · 0.85

Calls 7

print_spinnerFunction · 0.85
areaMethod · 0.45
get_rectMethod · 0.45
topMethod · 0.45
bottomMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected