TestRect.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #include "TestRect.h"
  2. #include "core/image/RectT.h"
  3. using namespace std;
  4. using namespace NICE;
  5. CPPUNIT_TEST_SUITE_REGISTRATION( TestRect );
  6. void TestRect::setUp() {
  7. }
  8. void TestRect::tearDown() {
  9. }
  10. void TestRect::testRect () {
  11. // test rect from 2 coordinates
  12. {
  13. Rect r(Coord(10,15) , Coord(35,30));
  14. CPPUNIT_ASSERT_EQUAL(10, r.left);
  15. CPPUNIT_ASSERT_EQUAL(15, r.top);
  16. CPPUNIT_ASSERT_EQUAL(35, r.right());
  17. CPPUNIT_ASSERT_EQUAL(30, r.bottom());
  18. CPPUNIT_ASSERT_EQUAL(25, r.width);
  19. CPPUNIT_ASSERT_EQUAL(15, r.height);
  20. Rect r2(Coord(35,30), Coord(10,15));
  21. CPPUNIT_ASSERT_EQUAL(true, r==r2);
  22. }
  23. }
  24. void TestRect::testCenter () {
  25. Rect rect(5,10, 30,20);
  26. Coord center = rect.center();
  27. CPPUNIT_ASSERT_EQUAL(20, center.x);
  28. CPPUNIT_ASSERT_EQUAL(20, center.y);
  29. }
  30. void TestRect::testArea() {
  31. Rect rect(4,4, 10,15);
  32. CPPUNIT_ASSERT_EQUAL(150, static_cast<Ipp32s>(rect.area()));
  33. }
  34. void TestRect::testIntersect() {
  35. Rect r1,r2,ir;
  36. // horizontal missmatch
  37. r1 = Rect(10, 10, 10,10);
  38. r2 = Rect(50, 10, 10,10);
  39. CPPUNIT_ASSERT_EQUAL(false, r1.intersect(r2,ir));
  40. // vertical missmatch
  41. r1 = Rect(10, 10, 10,10);
  42. r2 = Rect(10, 50, 10,10);
  43. CPPUNIT_ASSERT_EQUAL(false, r1.intersect(r2,ir));
  44. // horizontal and vertical missmatch
  45. r1 = Rect(10, 10, 10,10);
  46. r2 = Rect(50, 50, 10,10);
  47. CPPUNIT_ASSERT_EQUAL(false, r1.intersect(r2,ir));
  48. // identical rectangles
  49. r1 = Rect(10, 10, 10,10);
  50. r2 = Rect(10, 10, 10,10);
  51. CPPUNIT_ASSERT_EQUAL(true, r1.intersect(r2,ir));
  52. CPPUNIT_ASSERT_EQUAL(10, ir.left);
  53. CPPUNIT_ASSERT_EQUAL(10, ir.top);
  54. CPPUNIT_ASSERT_EQUAL(10, ir.width);
  55. CPPUNIT_ASSERT_EQUAL(10, ir.height);
  56. // horizontal adjacent rectangles
  57. r1 = Rect(10, 10, 10,10);
  58. r2 = Rect(12, 1, 10,10);
  59. CPPUNIT_ASSERT_EQUAL(true, r1.intersect(r2,ir));
  60. CPPUNIT_ASSERT_EQUAL(12, ir.left);
  61. CPPUNIT_ASSERT_EQUAL(10, ir.top);
  62. CPPUNIT_ASSERT_EQUAL( 8, ir.width);
  63. CPPUNIT_ASSERT_EQUAL( 1, ir.height);
  64. // vertical adjacent rectangles
  65. r1 = Rect( 1, 10, 10,10);
  66. r2 = Rect(10, 12, 10,10);
  67. CPPUNIT_ASSERT_EQUAL(true, r1.intersect(r2,ir));
  68. CPPUNIT_ASSERT_EQUAL(10, ir.left);
  69. CPPUNIT_ASSERT_EQUAL(12, ir.top);
  70. CPPUNIT_ASSERT_EQUAL( 1, ir.width);
  71. CPPUNIT_ASSERT_EQUAL( 8, ir.height);
  72. // general intersection
  73. r1 = Rect(10, 10, 10,10);
  74. r2 = Rect(15, 15, 10,10);
  75. CPPUNIT_ASSERT_EQUAL(true, r1.intersect(r2,ir));
  76. CPPUNIT_ASSERT_EQUAL(15, ir.left);
  77. CPPUNIT_ASSERT_EQUAL(15, ir.top);
  78. CPPUNIT_ASSERT_EQUAL( 5, ir.width);
  79. CPPUNIT_ASSERT_EQUAL( 5, ir.height);
  80. }