2
我无法使用Boost.Polygon中的get_rectangles(output_container_type& output, const T& polygon_set)
方法将曼哈顿(直线)多边形切片为矩形。它似乎不适用于自相交多边形,例如下面的多边形。使用Boost.Polygon切片曼哈顿多边形
这里是我的尝试:
#include <iostream>
#include <boost/polygon/polygon.hpp>
#include <vector>
namespace gtl = boost::polygon;
using namespace boost::polygon::operators;
int main() {
typedef gtl::polygon_90_with_holes_data<int> Polygon;
typedef gtl::polygon_traits<Polygon>::point_type Point;
Point pts[] = {gtl::construct<Point>(0, 0), // See the image
gtl::construct<Point>(0, 10),
gtl::construct<Point>(30, 10),
gtl::construct<Point>(30, 20),
gtl::construct<Point>(10, 20),
gtl::construct<Point>(10, 0)};
Polygon poly;
gtl::set_points(poly, pts, pts+6);
std::vector< gtl::rectangle_data<int> > rects;
get_rectangles(rects, poly);
std::cout << rects.size() << " rectangle: \n";
for(std::vector<gtl::rectangle_data<int> >::iterator it = rects.begin(); it !=
rects.end(); ++it) {
// Print out the corner coordinates
std::cout << "x1: "<< gtl::xl(*it) << ", x2: " << gtl::xh(*it)
<< ", y1: "<< gtl::yl(*it) << ", y2: " << gtl::yh(*it) << std::endl;
}
return 0;
}
而这里的输出:
1 rectangle:
x1: 10, x2: 30, y1: 10, y2: 20
此方法处理为一个不相交的多边形,但在这里它只能产生一个矩形,不是两个。 This似乎表明我正在尝试做的事情应该是可能的。我做错了什么,或者这是可能的?