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
この方法は、交差していない多角形に対して機能しましたが、ここでは 2 つではなく 1 つの長方形しか生成しません。これは、私がやろうとしていることが可能であることを示しているようです。私は何を間違っていますか、またはこれは可能ですか?