我想在boost.Geometry中使用操作符,而不是multiply_value、add_point、dot_product .。我必须自己来定义这些东西吗?
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point.hpp>
namespace bg = boost::geometry;
using Point = bg::model::point<double, 3, bg::cs::cartesian>;
using namespace bg;
void test()
{
const double z{2.0};
const Point a{1.0,2.0,-1.0};
// this doesn't compile:
// const Point b{z*a};
// const Point c{a+b};
// instead I have to do this:
Point b{a};
multiply_value(b, z);
Point c{5.0,1.0,0.0};
add_point(c, b);
}发布于 2015-03-25 10:46:51
官方的升压几何没有指示任何算术运算符(检查字母O)。
理论上,您应该能够自己定义一个包装器,但请记住,有两种添加或乘的方法:multiply_point和multiply_value。
template<typename Point1, typename Point2>
void multiply_point(Point1 & p1, Point2 const & p2)和
template<typename Point>
void multiply_value(Point & p, typename detail::param< Point >::type value)但是参数的类型可以由编译器互换,这意味着它不知道如果这两个函数的名称相同,它将不知道选择哪一个。
这意味着必须选择在进行乘法时执行的操作,以及必须选择操作数的顺序,这样编译器就不会有歧义。
下面是一个如何做到这一点的示例,以便Point b{z * a}编译:
// For multiply value
template<typename Point>
Point operator*(const Point & p, typename detail::param< Point >::type value) {
Point result{p};
multiply_value(result, value);
return result;
}请注意,Point b{a * z}不会使用此解决方案进行编译,Point c{a * b}也不会编译。
引起问题的操作数顺序示例
引起问题
https://stackoverflow.com/questions/29250200
复制相似问题