TestChangeCoord.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #include <math.h>
  2. #ifdef HAS_OPENCV3
  3. #include <opencv2/core.hpp> //Any OPENCV3 code
  4. #else
  5. #include <opencv2/core/core.hpp> //Any Opencv2 code
  6. #endif
  7. using namespace cv;
  8. #include <cxxtest/TestSuite.h>
  9. #include "geometry.h"
  10. class TestChangeCoord : public CxxTest::TestSuite
  11. {
  12. public:
  13. void testOrigin(void)
  14. {
  15. Point origin = Point(1,2);
  16. //the angle here is actually irrelevant
  17. Point p = map_point(M_PI/2, origin, origin);
  18. TS_ASSERT_EQUALS(p.x, 0);
  19. TS_ASSERT_EQUALS(p.y, 0);
  20. }
  21. void testOnlyTranslation(void)
  22. {
  23. Point origin = Point(1,2);
  24. Point p = map_point(0, origin, Point(0,0));
  25. TS_ASSERT_EQUALS(p.x, -1);
  26. TS_ASSERT_EQUALS(p.y, -2);
  27. }
  28. void testOnlyRotationOrigin(void)
  29. {
  30. Point origin = Point(0,0);
  31. Point p = map_point(M_PI, origin, origin);
  32. TS_ASSERT_EQUALS(p.x, 0);
  33. TS_ASSERT_EQUALS(p.y, 0);
  34. }
  35. void testOnlyRotation180(void)
  36. {
  37. Point origin = Point(0,0);
  38. Point p = map_point(M_PI, origin, Point(1,2));
  39. TS_ASSERT_EQUALS(p.x, -1);
  40. TS_ASSERT_EQUALS(p.y, -2);
  41. }
  42. void testOnlyRotation90(void)
  43. {
  44. Point origin = Point(0,0);
  45. Point p = map_point(M_PI/2, origin, Point(1,2));
  46. TS_ASSERT_EQUALS(p.x, 2);
  47. TS_ASSERT_EQUALS(p.y, -1);
  48. }
  49. void testOnlyRotation30(void)
  50. {
  51. Point origin = Point(0,0);
  52. Point p = map_point(M_PI/6, origin, Point(200,0));
  53. TS_ASSERT_EQUALS(p.y, -100);
  54. TS_ASSERT_LESS_THAN(p.x, 180); //0.866*2 ~= 1.73
  55. TS_ASSERT_LESS_THAN(170, p.x); //0.866*2 ~= 1.73
  56. }
  57. };
  58. class TestChangeBack : public CxxTest::TestSuite
  59. {
  60. public:
  61. void testOrigin(void)
  62. {
  63. Point origin = Point(1,2);
  64. Point p = unmap_point(M_PI/2, origin, Point(0,0));
  65. TS_ASSERT_EQUALS(p.x, 1);
  66. TS_ASSERT_EQUALS(p.y, 2);
  67. }
  68. void testOnlyTranslation(void)
  69. {
  70. Point origin = Point(1,2);
  71. Point p = unmap_point(0, origin, Point(-1,-2));
  72. TS_ASSERT_EQUALS(p.x, 0);
  73. TS_ASSERT_EQUALS(p.y, 0);
  74. }
  75. void testOnlyRotationOrigin(void)
  76. {
  77. Point origin = Point(0,0);
  78. Point p = unmap_point(M_PI, origin, origin);
  79. TS_ASSERT_EQUALS(p.x, 0);
  80. TS_ASSERT_EQUALS(p.y, 0);
  81. }
  82. void testOnlyRotation180(void)
  83. {
  84. Point origin = Point(0,0);
  85. Point p = unmap_point(M_PI, origin, Point(1,2));
  86. TS_ASSERT_EQUALS(p.x, -1);
  87. TS_ASSERT_EQUALS(p.y, -2);
  88. }
  89. void testOnlyRotation90(void)
  90. {
  91. Point origin = Point(0,0);
  92. Point p = unmap_point(M_PI/2, origin, Point(-2,1));
  93. TS_ASSERT_EQUALS(p.x, -1);
  94. TS_ASSERT_EQUALS(p.y, -2);
  95. }
  96. void testOnlyRotation30(void)
  97. {
  98. Point origin = Point(0,0);
  99. Point p = unmap_point(M_PI/6, origin, Point(200,0));
  100. TS_ASSERT_LESS_THAN(p.x, 175); //0.866*2 ~= 1.73
  101. TS_ASSERT_LESS_THAN(170, p.x); //0.866*2 ~= 1.73
  102. TS_ASSERT_EQUALS(100, p.y);
  103. }
  104. };
  105. class TestCoordSystem : public CxxTest::TestSuite
  106. {
  107. public:
  108. void testCreate(void)
  109. {
  110. auto cs = CoordinateSystem(Point(100,200), Point(200,300));
  111. TS_ASSERT_EQUALS(cs.map(Point(300,400)).y, 0);
  112. TS_ASSERT_EQUALS(cs.map(Point(200,100)).x, 0); //moving orthogonally
  113. }
  114. void testInverse(void)
  115. {
  116. CoordinateSystem(Point(200,300), Point(100,200));
  117. }
  118. };