| 25 | logger dlog("test.geometry"); |
| 26 | |
| 27 | void geometry_test ( |
| 28 | ) |
| 29 | /*! |
| 30 | ensures |
| 31 | - runs tests on the geometry stuff compliance with the specs |
| 32 | !*/ |
| 33 | { |
| 34 | print_spinner(); |
| 35 | |
| 36 | point p1; |
| 37 | point p2(2,3); |
| 38 | |
| 39 | DLIB_TEST(p1.x() == 0); |
| 40 | DLIB_TEST(p1.y() == 0); |
| 41 | DLIB_TEST(p2.x() == 2); |
| 42 | DLIB_TEST(p2.y() == 3); |
| 43 | |
| 44 | DLIB_TEST((-p2).x() == -2); |
| 45 | DLIB_TEST((-p2).y() == -3); |
| 46 | |
| 47 | |
| 48 | p2 += p2; |
| 49 | DLIB_TEST(p2.x() == 4); |
| 50 | DLIB_TEST(p2.y() == 6); |
| 51 | |
| 52 | dlib::vector<double> v1 = point(1,0); |
| 53 | dlib::vector<double> v2(0,0,1); |
| 54 | |
| 55 | p1 = v2.cross(v1); |
| 56 | DLIB_TEST(p1 == point(0,1)); |
| 57 | DLIB_TEST(p1 != point(1,1)); |
| 58 | DLIB_TEST(p1 != point(1,0)); |
| 59 | |
| 60 | p1 = point(2,3); |
| 61 | rectangle rect1 = p1; |
| 62 | DLIB_TEST(rect1.width() == 1); |
| 63 | DLIB_TEST(rect1.height() == 1); |
| 64 | p2 = point(1,1); |
| 65 | |
| 66 | rect1 += p2; |
| 67 | DLIB_TEST(rect1.left() == 1); |
| 68 | DLIB_TEST(rect1.top() == 1); |
| 69 | DLIB_TEST(rect1.right() == 2); |
| 70 | DLIB_TEST(rect1.bottom() == 3); |
| 71 | |
| 72 | DLIB_TEST(rect1.width() == 2); |
| 73 | DLIB_TEST(rect1.height() == 3); |
| 74 | |
| 75 | // test the iostream << and >> operators (via string_cast and cast_to_string) |
| 76 | DLIB_TEST(string_cast<point>(" (1, 2 )") == point(1,2)); |
| 77 | DLIB_TEST(string_cast<point>(" ( -1, 2 )") == point(-1,2)); |
| 78 | DLIB_TEST(string_cast<rectangle>(" [(1, 2 )(3,4)]") == rectangle(1,2,3,4)); |
| 79 | DLIB_TEST(string_cast<dlib::vector<double> >(" (1, 2 , 3.5)") == dlib::vector<double>(1,2,3.5)); |
| 80 | |
| 81 | DLIB_TEST(string_cast<rectangle>(cast_to_string(rect1)) == rect1); |
| 82 | DLIB_TEST(string_cast<point>(cast_to_string(p1)) == p1); |
| 83 | DLIB_TEST(string_cast<dlib::vector<double> >(cast_to_string(v1)) == v1); |
| 84 |
no test coverage detected