[英]Boost Geometry compilation error in version 1.80.0 using custom point type
I'm using Boost 1.80.0
.我正在使用
Boost 1.80.0
。
I would like to use boost geometries with a custom point type.我想使用具有自定义点类型的增强几何。
To do that I register my custom point into boost::geometry.为此,我将自定义点注册到 boost::geometry 中。
I am then lock when I want to use boost::geometry::within()
function.当我想使用
boost::geometry::within()
函数时,我会被锁定。
I got a compilation error that I do not understand well.我遇到了一个我不太了解的编译错误。
See some errors:看到一些错误:
boost/1.80/include/boost/geometry/algorithms/detail/relate/boundary_checker.hpp:99:38: error: no matching function for call to ‘std::vector<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, std::allocator<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> > >::push_back(const point&)’
/usr/include/c++/10/bits/predefined_ops.h:194:23: error: no match for call to ‘(boost::geometry::less<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, -1, boost::geometry::cartesian_tag>) (boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>&, const point&)’
But, if I compile with a previous Boost version (for example Boost 1.79.0
) it compiles fine.但是,如果我使用以前的 Boost 版本(例如
Boost 1.79.0
)进行编译,它可以正常编译。
Edit : It appears to be a boost::geometry regression, and not a misuse from my part.编辑:这似乎是一个 boost::geometry 回归,而不是我的滥用。
As I am not familiar with boost::geometry
and Boost does not mention any change for boost::geometry
from version 1.79.0
to 1.80.0
, I assume I am missing something with my comprehension of using boost type with custom points.由于我不熟悉
boost::geometry
并且Boost 没有提到boost::geometry
从版本1.79.0
到1.80.0
的任何变化,我假设我对使用带有自定义点的 boost 类型的理解遗漏了一些东西。
Code sample:代码示例:
#include <iostream>
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/register/point.hpp>
struct point {
double x, y;
point(double x = 0, double y = 0) : x(x), y(y) {}
};
BOOST_GEOMETRY_REGISTER_POINT_2D(point, double, boost::geometry::cs::cartesian, x, y);
using line = boost::geometry::model::linestring<point>;
using multiline = boost::geometry::model::multi_linestring<line>;
using polygon = boost::geometry::model::polygon<point>;
int main(int argc, char** argv) {
multiline inMultiline;
polygon inPoly;
bool isWithin = boost::geometry::within(inMultiline, inPoly); // error
return EXIT_SUCCESS;
}
Note 1: within() " Supported Geometries " table state that it is correct to use it with multi_linestring and polygon.注意 1:within() “ Supported Geometries ”表声明将它与 multi_linestring 和多边形一起使用是正确的。
Note 2: Remplacing my custom point by using point = boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>
works fine in this sample.注 2:
using point = boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>
替换我的自定义点在此示例中效果很好。
Edit: As It seems that come from a bug from boost:geometry I edited the title for newcomers.编辑:因为它似乎来自 boost:geometry 的错误,所以我为新手编辑了标题。
So I dove into the code/message and noticed that inside the algorithm an equal_range
call is used comparing between a helper geometry (built with helper_geometry<>
) and yours.因此,我深入研究代码/消息并注意到在算法内部使用了一个
equal_range
调用来比较辅助几何体(使用helper_geometry<>
构建)和您的几何体。 It ends up calling a comparator with incompatible point types:它最终会调用具有不兼容点类型的比较器:
using mutable_point_type = bg::helper_geometry<MyPoint, double>::type;
bg::less<mutable_point_type, -1, bg::cartesian_tag> cmp;
mutable_point_type a;
MyPoint b;
cmp(a, b);
This gives the same error message, because the less<>
implementation doesn't accept generic point types.这会给出相同的错误消息,因为
less<>
实现不接受通用点类型。 It looks as though that's an implementation issue, because there exists a bg::less<void, 2, void>
implementation that does correctly apply the default comparison-strategy for heterogenous point types:看起来这是一个实现问题,因为存在一个
bg::less<void, 2, void>
实现,它正确地应用了异构点类型的默认比较策略:
template <int Dimension>
struct less<void, Dimension, void>
{
typedef bool result_type;
template <typename Point1, typename Point2>
inline bool operator()(Point1 const& left, Point2 const& right) const
{
typedef typename strategy::compare::services::default_strategy
<
strategy::compare::less,
Point1, Point2,
Dimension
>::type strategy_type;
return strategy_type::apply(left, right);
}
};
However, pathching the relevant line in boost/geometry/algorithms/detail/relate/boundary_checker.hpp:160 to use it:但是,在boost/geometry/algorithms/detail/relate/boundary_checker.hpp:160中找到相关行以使用它:
@@ -157,7 +157,7 @@ public:
template <typename Point>
bool is_endpoint_boundary(Point const& pt) const
{
- using less_type = geometry::less<mutable_point_type, -1, typename Strategy::cs_tag>;
+ using less_type = geometry::less<void, -1, void>;
auto const multi_count = boost::size(m_geometry);
reveals more places where boundary_checker
assumes identical point types: line 99 attempts to push a MyPoint
into vector<>
of "helper" points ( mutable_point_type
):揭示了
boundary_checker
假定相同点类型的更多位置:第 99 行尝试将MyPoint
推入vector<>
的“辅助”点 ( mutable_point_type
):
boundary_points.push_back(front_pt);
Consequently I could get your code to compile only by patching the implementation ( L:148 ) to use your point type as the helper point type as well.因此,我只能通过修补实现 ( L:148 ) 以将您的点类型也用作辅助点类型来编译您的代码。
@@ -145,7 +145,7 @@ template <typename Geometry, typename Strategy>
class boundary_checker<Geometry, Strategy, multi_linestring_tag>
{
using point_type = typename point_type<Geometry>::type;
- using mutable_point_type = typename helper_geometry<point_type>::type;
+ using mutable_point_type = point_type;
This only works for cases where the point type is mutable, of course, so it won't be a good general-purpose fix.当然,这只适用于点类型可变的情况,因此它不是一个好的通用修复。
I'd file an issue about this with the library devs: https://github.com/boostorg/geometry/issues?q=is%3Aissue+boundary_checker - it looks like it wasn't previously reported there.我会向图书馆开发人员提交关于此的问题: https ://github.com/boostorg/geometry/issues?q=is%3Aissue+boundary_checker - 看起来以前没有在那里报告过。
This is fixed in Boost 1.81.0
.这在 Boost
1.81.0
中得到修复。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.