testPolygonClass.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /**
  2. * @file testPolygonClass.cpp
  3. * @brief test function of polygon class
  4. * @author Sven Sickert
  5. * @date 07/10/2015
  6. */
  7. #include "vislearning/cbaselib/Polygon.h"
  8. using namespace OBJREC;
  9. int main ( int argc, char **argv )
  10. {
  11. Polygon * poly1 = new Polygon ();
  12. Polygon * poly2 = new Polygon(*poly1);
  13. delete poly2;
  14. NICE::CoordT<int> coord( 10, 10);
  15. poly1->push( coord );
  16. poly1->push( 20, 20 );
  17. poly1->push( 10, 20 );
  18. poly1->setID( 42 );
  19. const PointsList* ptsList = poly1->points();
  20. poly1->pop();
  21. poly1->push ( 20, 10 );
  22. for ( PointsList::const_iterator it = ptsList->begin();
  23. it != ptsList->end(); ++it )
  24. std::cout << it->x << " " << it->y << std::endl;
  25. NICE::CoordT<int> test1( 18, 15 );
  26. std::cout << "Point (" << test1.x << "," << test1.y << ") in polygon?"
  27. << std::endl;
  28. if ( poly1->insidePolygon( test1) )
  29. std::cout << "true" << std::endl;
  30. else
  31. std::cout << "false" << std::endl;
  32. NICE::CoordT<int> test2( 5, 5 );
  33. std::cout << "Point (" << test2.x << "," << test2.y << ") in polygon?"
  34. << std::endl;
  35. if ( poly1->insidePolygon( test2) )
  36. std::cout << "true" << std::endl;
  37. else
  38. std::cout << "false" << std::endl;
  39. NICE::CoordT<int> test3( 10, 10 );
  40. std::cout << "Point (" << test3.x << "," << test3.y << ") in polygon?"
  41. << std::endl;
  42. if ( poly1->insidePolygon( test3) )
  43. std::cout << "true" << std::endl;
  44. else
  45. std::cout << "false" << std::endl;
  46. delete poly1;
  47. }