Boost.Geometry convert

convert()は、Geometryコンセプトを満たす型の間で、他の型に変換する関数です。
第1引数の図形を、第2引数の型に変換します。


以下は、boxをpolygonに変換する処理:

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

namespace bg = boost::geometry;

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

    const box a(point(0, 0), point(3, 3));
    polygon b;

    bg::convert(a, b);

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

point_xyを、Point ConceptにアダプトされたFusion Sequenceに変換する処理:

#include <iostream>
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/adapted/boost_fusion.hpp>
#include <boost/fusion/include/vector.hpp>
#include <boost/fusion/include/io.hpp>

namespace bg = boost::geometry;

typedef boost::fusion::vector<double, double> vector;
BOOST_GEOMETRY_REGISTER_BOOST_FUSION_CS(cs::certesian)

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

    const point p(3, 3);
    vector vec;

    bg::convert(p, vec);

    std::cout << vec << std::endl;
}
(3 3)


参照:
convert algorithm