| 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 |
no test coverage detected