2011-10-11 67 views
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; 

完整的錯誤是在here任何人都喜歡挖。
我該如何編譯?

回答

0

我成功編譯基於與您的例子爲例:

  • VS2005 SP1(Vista 64位)
  • 升壓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; 
} 

我得到兩個警告(warning C4244: '=' : conversion from 'double' to 'int', possible loss of data),但它編譯。