Ticket #10636: polytest.cc

File polytest.cc, 1.8 KB (added by "Patrick J. LoPresti" <lopresti@…>, 8 years ago)

Simple test case demonstrating get_trapezoids failure

Line 
1#include <boost/polygon/polygon.hpp>
2
3#include <iostream>
4
5namespace bp = boost::polygon;
6
7typedef bp::polygon_set_data<int> PolygonSet;
8typedef bp::polygon_data<PolygonSet::coordinate_type> Polygon;
9typedef bp::polygon_with_holes_data<PolygonSet::coordinate_type> PolygonWithHoles;
10typedef bp::polygon_traits<Polygon>::point_type Point;
11
12std::ostream &
13operator<<(std::ostream &os, const Point &pt)
14{
15 return os << "(" << bp::x(pt) << " " << bp::y(pt) << ")";
16}
17
18std::ostream &
19operator<<(std::ostream &os, const Polygon &poly)
20{
21 os << "polygon ";
22 for (Polygon::iterator_type p = poly.begin() ; p != poly.end() ; ++p)
23 os << " " << *p;
24 return os;
25}
26
27std::ostream &
28operator<<(std::ostream &os, const PolygonSet &ps)
29{
30 std::vector<Polygon> temp;
31 ps.get(temp);
32 os << "polygonset ";
33 for (std::vector<Polygon>::const_iterator p = temp.begin()
34 ; p != temp.end() ; ++p)
35 os << " " << *p;
36 return os;
37}
38
39int
40main(int argc, char *argv[])
41{
42 using namespace bp::operators;
43
44 const Point points[] = {
45 Point(2,0),
46 Point(4,0),
47 Point(4,3),
48 Point(0,3),
49 Point(0,0),
50 Point(2,0),
51 Point(2,1),
52 Point(1,1),
53 Point(1,2),
54 Point(3,2),
55 Point(3,1),
56 Point(2,1),
57 Point(2,0)
58 };
59
60 Polygon poly1;
61 bp::set_points(poly1, &points[0],
62 &points[sizeof(points)/sizeof(points[0])]);
63 std::cout << "poly1 = " << poly1 << "\n";
64
65 PolygonSet ps;
66 ps.insert(poly1);
67 std::cout << "ps = " << ps << "\n";
68
69 std::vector<Polygon> traps;
70
71 // Note: bp::VERTICAL works fine
72 get_trapezoids(traps, ps, bp::HORIZONTAL);
73 std::cout << "Output: (" << traps.size() << ")\n";
74 for (std::vector<Polygon>::const_iterator p = traps.begin()
75 ; p != traps.end() ; ++p)
76 std::cout << *p << "\n";
77}