“二进制表达式的无效操作数”当使用 Boost.Geometry 时?

发布于 2024-12-09 07:06:25 字数 1716 浏览 1 评论 0原文

当我尝试增强几何差异函数时,我收到一个很长的编译器错误,而具有相同接口和可能相关实现工作的并集和交集:

bg::unique_(OldPolygon, Node->Polygon, NodePolygon); // compiles
bg::intersection(OldPolygon, Node->Polygon, NodePolygon); // compiles
bg::difference(OldPolygon, Node->Polygon, NodePolygon); // dies

第一个错误是:

boost/range/size.hpp:32:13: error: invalid operands to
    binary expression ('
         boost::reverse_iterator<
             __gnu_cxx::__normal_iterator<
                 const GraphPoint *,
                 std::vector<
                     GraphPoint,
                     std::allocator<GraphPoint>
                 >
             >
         >' and 'int')
            BOOST_ASSERT( (boost::end(rng) - boost::begin(rng)) >= 0 &&
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

似乎由于某种原因,迭代器差异返回反向迭代器而不是距离。 ..

类型声明为:

namespace bg = boost::geometry;

struct GraphPoint
{
    int x, y;
    GraphPoint(int x, int y) : x(x), y(y) { }
    GraphPoint() : x(0), y(0) { }
    GraphPoint(const GraphPoint &other) : x(other.x), y(other.y) { }

    bool operator ==(const GraphPoint &other) const
    {
        return x == other.x && y == other.y;
    }
};

BOOST_GEOMETRY_REGISTER_POINT_2D(GraphPoint, int, bg::cs::cartesian, x, y)

typedef bg::model::polygon<GraphPoint> Polygon;
typedef Polygon::ring_type Ring;
typedef bg::model::multi_polygon<Polygon> MultiPolygon;

MultiPolygon OldPolygon;
struct Node
{
    Polygon Polygon;
}
MultiPolygon NodePolygon;

完整的错误位于此处,以防有人喜欢挖掘。
我怎样才能编译这个?

I get a long compiler error when I try boost geometry difference function, while the union and intersection that have same interface and probably related implementation work:

bg::unique_(OldPolygon, Node->Polygon, NodePolygon); // compiles
bg::intersection(OldPolygon, Node->Polygon, NodePolygon); // compiles
bg::difference(OldPolygon, Node->Polygon, NodePolygon); // dies

The first error is:

boost/range/size.hpp:32:13: error: invalid operands to
    binary expression ('
         boost::reverse_iterator<
             __gnu_cxx::__normal_iterator<
                 const GraphPoint *,
                 std::vector<
                     GraphPoint,
                     std::allocator<GraphPoint>
                 >
             >
         >' and 'int')
            BOOST_ASSERT( (boost::end(rng) - boost::begin(rng)) >= 0 &&
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

It seems for some reason the iterator difference is returning reverse iterator instead of distance...

The types are declared as:

namespace bg = boost::geometry;

struct GraphPoint
{
    int x, y;
    GraphPoint(int x, int y) : x(x), y(y) { }
    GraphPoint() : x(0), y(0) { }
    GraphPoint(const GraphPoint &other) : x(other.x), y(other.y) { }

    bool operator ==(const GraphPoint &other) const
    {
        return x == other.x && y == other.y;
    }
};

BOOST_GEOMETRY_REGISTER_POINT_2D(GraphPoint, int, bg::cs::cartesian, x, y)

typedef bg::model::polygon<GraphPoint> Polygon;
typedef Polygon::ring_type Ring;
typedef bg::model::multi_polygon<Polygon> MultiPolygon;

MultiPolygon OldPolygon;
struct Node
{
    Polygon Polygon;
}
MultiPolygon NodePolygon;

The full error is in here incase anyone likes to dig.
How can I make this compile?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

七度光 2024-12-16 07:06:25

我根据您的示例成功编译了一个示例:

  • VS2005 SP1 (Vista x64)
  • boost 1.48.0(刚刚下载)

我必须修改 Node 结构,这是生成的代码:

#include <boost/geometry/geometry.hpp> 
#include <boost/geometry/geometries/register/point.hpp>
#include <boost/geometry/geometries/register/ring.hpp>
#include <boost/geometry/geometries/geometries.hpp>
#include <boost/geometry/multi/geometries/multi_polygon.hpp> // boost 1_48_0
//#include <boost/geometry/multi/geometries/multi_geometries.hpp> // if boost comes from SVN

namespace bg = boost::geometry;

struct GraphPoint
{
    int x, y;
    GraphPoint(int x, int y) : x(x), y(y) { }
    GraphPoint() : x(0), y(0) { }
    GraphPoint(const GraphPoint &other) : x(other.x), y(other.y) { }

    bool operator ==(const GraphPoint &other) const
    {
        return x == other.x && y == other.y;
    }
};

BOOST_GEOMETRY_REGISTER_POINT_2D(GraphPoint, int, bg::cs::cartesian, x, y)

typedef bg::model::polygon<GraphPoint> Polygon;
typedef Polygon::ring_type Ring;
typedef bg::model::multi_polygon<Polygon> MultiPolygon;

MultiPolygon OldPolygon;
MultiPolygon NodePolygon;

struct Node
{
    Polygon p;
} node;

int main(int argc, char* argv[])
{
    bg::unique(OldPolygon); // only one parameter
    bg::intersection(OldPolygon, node.p, NodePolygon);
    bg::difference(OldPolygon, node.p, NodePolygon);

    return 0;
}

我收到两个警告(警告 C4244:'=':从 'double' 到 'int' 的转换,可能会丢失数据)但它可以编译。

I successfully compiled an example based on your example with:

  • VS2005 SP1 (Vista x64)
  • boost 1.48.0 (just downloaded)

I had to modify the Node structure, this is the resulting code:

#include <boost/geometry/geometry.hpp> 
#include <boost/geometry/geometries/register/point.hpp>
#include <boost/geometry/geometries/register/ring.hpp>
#include <boost/geometry/geometries/geometries.hpp>
#include <boost/geometry/multi/geometries/multi_polygon.hpp> // boost 1_48_0
//#include <boost/geometry/multi/geometries/multi_geometries.hpp> // if boost comes from SVN

namespace bg = boost::geometry;

struct GraphPoint
{
    int x, y;
    GraphPoint(int x, int y) : x(x), y(y) { }
    GraphPoint() : x(0), y(0) { }
    GraphPoint(const GraphPoint &other) : x(other.x), y(other.y) { }

    bool operator ==(const GraphPoint &other) const
    {
        return x == other.x && y == other.y;
    }
};

BOOST_GEOMETRY_REGISTER_POINT_2D(GraphPoint, int, bg::cs::cartesian, x, y)

typedef bg::model::polygon<GraphPoint> Polygon;
typedef Polygon::ring_type Ring;
typedef bg::model::multi_polygon<Polygon> MultiPolygon;

MultiPolygon OldPolygon;
MultiPolygon NodePolygon;

struct Node
{
    Polygon p;
} node;

int main(int argc, char* argv[])
{
    bg::unique(OldPolygon); // only one parameter
    bg::intersection(OldPolygon, node.p, NodePolygon);
    bg::difference(OldPolygon, node.p, NodePolygon);

    return 0;
}

I get two warnings (warning C4244: '=' : conversion from 'double' to 'int', possible loss of data) but it compiles.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文