1

ジオメトリの差分関数をブーストしようとすると、長いコンパイラエラーが発生しますが、同じインターフェイスとおそらく関連する実装を持つ和集合と共通部分は機能します。

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;

誰かが掘るのが好きな場合に備えて、完全なエラーはここにあります。
どうすればこれをコンパイルできますか?

4

1 に答える 1

0

私はあなたの例に基づいて例を正常にコンパイルしました:

  • VS2005 SP1 (ビスタ x64)
  • ブースト 1.48.0 (ダウンロードしたばかり)

ノード構造を変更する必要がありました。これが結果のコードです。

#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;
}

2 つの警告 ( warning C4244: '=' : conversion from 'double' to 'int', possible loss of data) が表示されますが、コンパイルされます。

于 2011-11-16T15:12:48.633 に答える