Boost.Geometry correct

correct()は、向きが逆だったり、終了点が足りなかったりする図形を修正してくれるアルゴリズムです。
図形の参照を引数として渡します。

#include <iostream>
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/assign/list_of.hpp>

namespace bg = boost::geometry;

int main()
{
    typedef bg::model::d2::point_xy<double> point;
    typedef bg::model::polygon<point> polygon;

    polygon poly;
    bg::exterior_ring(poly) = boost::assign::list_of<point>
        (0, 0)
        (3, 3)
        (0, 3)
        ;

    bg::correct(poly);

    std::cout << bg::dsv(poly) << std::endl;
}
(((0, 0), (0, 3), (3, 3), (0, 0)))

参照:

correct algorithm