fork(2) download
  1. #include <octave/oct.h>
  2. #include <vector>
  3. #include <boost/geometry.hpp>
  4. #include <boost/geometry/geometries/polygon.hpp>
  5. #include <boost/geometry/geometries/adapted/boost_polygon.hpp>
  6.  
  7. using namespace boost::geometry;
  8. typedef boost::polygon::polygon_data<int> polygon;
  9. typedef boost::polygon::polygon_traits<polygon>::point_type point;
  10.  
  11. DEFUN_DLD (ispolycw, args, ,
  12. "Check if polygon points are clockwise")
  13. {
  14. /*
  15.   TODO: Check if args are valid first
  16.   */
  17.  
  18. if(args(0).length()<=2)
  19. {
  20. return octave_value_list (octave_value(true));
  21. }
  22.  
  23. std::vector<point> pts;
  24. for(int j=0;j<args(0).length();j++)
  25. {
  26. point p=boost::polygon::construct<point>(args(0).fast_elem_extract(j).float_value()
  27. ,args(1).fast_elem_extract(j).float_value());
  28. pts.push_back(p);
  29. }
  30.  
  31. if(pts[0]!=pts[pts.size()-1])
  32. {
  33. pts.push_back(pts[0]);
  34. }
  35.  
  36. polygon poly;
  37. boost::polygon::set_points(poly, pts.begin(), pts.end());
  38. bool iscw=boost::geometry::area(poly)>0?1:0;
  39.  
  40. return octave_value_list (octave_value(iscw));
  41.  
  42.  
  43. /*
  44.   *
  45.   *Test1: Clockwise Polygon
  46.   *>> ispolycw([0 1 2],[0 3 0])
  47.   *ans = 1
  48.   *
  49.   *
  50.   *Test2: A CounterClockwise Polygon
  51.   *>> ispolycw([0 2 1],[0 0 3])
  52.   *ans = 0
  53.   *
  54.   *
  55.   *Test3: A Polygon of less than three vertices
  56.   *>> ispolycw([0 1],[0 3])
  57.   *ans = 1
  58.   *
  59.   */
  60.  
  61. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:24: fatal error: octave/oct.h: No such file or directory
compilation terminated.
stdout
Standard output is empty