使用Boost Geometry注册QRectF

时间:2015-08-05 12:59:21

标签: c++ qt boost boost-geometry

我想将QRectF注册为带有Boost.Geometry的model::boxBOOST_GEOMETRY_REGISTER_BOX的文档声明我应该提供两个参数:'最小角(应该是公共成员或方法)'和'最大角(应该是公共成员或方法)'作为宏的最后两个参数。但是,在使用QRectF进行此操作时,我收到以下错误:

error: reference to non-static member function must be called; did you mean to call it with no arguments?
BOOST_GEOMETRY_REGISTER_BOX(QRectF, QPointF, topLeft, bottomRight);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~

看来这些参数必须是公共成员。似乎没有一个宏可以指定相当于BOOST_GEOMETRY_REGISTER_POINT_2D_GET_SET的getter和setter方法。

我按如下方式调用宏:

#include <boost/geometry/geometries/box.hpp>
#include <boost/geometry/geometries/register/box.hpp>
#include <boost/geometry/geometries/register/point.hpp>
#include <QRectF>
BOOST_GEOMETRY_REGISTER_POINT_2D_GET_SET(QPointF, qreal, cs::cartesian, x, y, setX, setY);
BOOST_GEOMETRY_REGISTER_BOX(QRectF, QPointF, topLeft, bottomRight);

有没有办法解决这个问题?我可以通过将数据复制到model::box实例中来解决这个问题,但我希望可以使用BOOST_GEOMETRY_REGISTER_BOX_GET_SET这样的东西,以便我可以避免复制并直接使用QRectF

1 个答案:

答案 0 :(得分:3)

昨天有人发布了正确答案但在我接受之前将其删除了。无论如何,解决方案是使用:

BOOST_GEOMETRY_REGISTER_BOX(QRectF, QPointF, topLeft(), bottomRight());

好像你看一下BOOST_GEOMETRY_REGISTER_BOX(Box, Point, MinCorner, MaxCorner)的实现,它使用如下参数:

typedef typename coordinate_type<Point>::type ct; \
static inline ct get(Box const& b) \
{ return geometry::get<D>(b. MinCorner);  } \

替换时会变成:

typedef typename coordinate_type<QPointF>::type ct; \
static inline ct get(QRectF const& b) \
{ return geometry::get<D>(b. topLeft());  } \