促进几何体操作符
boost.Geometry operators
我想在boost中使用运算符。几何体而不是多重值、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);
}
官方的Boost Geometry文档没有指示任何算术运算符(请检查字母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}
也不会。
导致问题的操作数顺序示例
multiply_value
或multiply_point
导致问题的示例
相关文章:
- 无法将结构注册为增强几何体3D点
- 提升几何体:C++并集多个多边形
- 提升几何体:assertion_failed错误C++
- 如何从 Skia 路径几何体中获取网格?
- 向 vulkan 管道添加额外的 UBO 会停止所有几何体渲染
- 为什么map有操作符[],set没有
- 如何从保存的几何体中获取屏幕编号?
- 我可以将C 17 Capture lambda ConstexPR转换操作符的结果用作函数指针模板非类型参数吗?
- 纹理未应用于 2D 几何体
- 提升几何体intersection_inserter<polygon_2d>不起作用
- c++新操作符通过libstdc++占用大量内存(67MB)
- 如何从 .IV 文件为渲染的几何体应用状态集
- 复制/移动操作符是否可以安全地用于实现复制/移动分配操作符
- 几何体着色器计算的线在摄影机移动时消失
- 提升::精神::因果报应使用有条件的替代操作符(|)
- 促进几何体操作符
- 如果操作符delete没有实现,为什么不编译它
- 在使用放置新操作符时,我真的需要担心对齐问题吗
- 未能使用增强::几何体::模型::多边形
- 我怎样才能让getline操作符工作