简体   繁体   English

Boost Geometry 版本 1.80.0 中使用自定义点类型时出现编译错误

[英]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.01.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.

相关问题 错误 - 自定义数据类型作为带有 boost::geometry 的有效负载 - Error - Custom Data Type as payload with boost::geometry 在坐标类型上模拟我的类并使用Boost Geometry库时出现编译错误 - Compilation error when templating my class on coordinate type and using Boost Geometry library 访问boost :: geometry多边形中的点数据时出错 - Error accessing point data in boost::geometry polygon 如何使用boost :: geometry :: rtree和glm :: vec3作为自定义点类型? - How to use boost::geometry::rtree with glm::vec3 as a custom point type? 如何在增强几何中调整自定义多边形类型 - How to adapt a custom polygon type in boost geometry 使用boost :: geometry :: append时,ID字段在定制点类中间歇性丢失 - ID field intermittently lost in custom point class when using boost::geometry::append 使用boost :: spirit的代码中歧义类型的编译错误 - Compilation error on ambiguous type in code using boost::spirit 模板点类型的boost :: geometry :: model :: segment构造函数? - boost::geometry::model::segment constructor for template point type? 通过切换到更高的Boost版本1.6.1来编译错误 - Compilation error by switching to higher Boost Version 1.6.1 使用boost :: future .then()的编译错误 - Compilation error on using boost::future .then()
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM