Boost Geometry and exact point types

北城余情 提交于 2019-12-04 11:56:33

Boost Geometry is getting confused by the proxy types returned from expression templates, where it is expecting the concrete numeric results: documentation

The Multiprecision library comes in two distinct parts:

  • An expression-template-enabled front-end number that handles all the operator overloading, expression evaluation optimization, and code reduction.
  • A selection of back-ends that implement the actual arithmetic operations, and need conform only to the reduced interface requirements of the front-end.

The meta-programming grinds to a halt there.

Fortunately, you can simply use the mpq_rational modified to disable expressions templates:

typedef bm::number<bm::gmp_rational, bm::et_off> my_rational;

This will compile without problems.


Coliru chokes on it, but here it is: http://coliru.stacked-crooked.com/a/232d98bfbb430468

#include <vector>

#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp> 
#include <boost/geometry/geometries/segment.hpp>
#include <boost/geometry/algorithms/intersection.hpp>

#include <boost/multiprecision/gmp.hpp>
#include <boost/multiprecision/number.hpp>

namespace bg = boost::geometry;
namespace bm = boost::multiprecision;

typedef bm::number<bm::gmp_rational, bm::et_off> my_rational;
typedef bg::model::d2::point_xy<my_rational > point;
typedef boost::geometry::model::segment<point> segment;

int main(void)
{
    point a(0,0);
    point b(1,0);
    point c(1,1);
    point d(0,1);

    segment s1(a,c);
    segment s2(b,d);

    std::vector<point> ip;
    bg::intersection(s1, s2, ip); // Doesn't compile

    return 0;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!