2016-12-06 62 views
1

當多邊形是一個軸對齊框「POLYGON((0 0,1 0,1 1,0 1))」時,那麼union_()將不會給出正確的結果,只是空輸出。實際上,任何多邊形的union_()都不應該是空的。爲什麼boost :: geometry :: union_不能給出軸對齊框的結果?

但是,如果將多邊形的綠色從軸對齊框更改爲「POLYGON((2 1.3,2.4 1.7,2.8 1.8))」,則會出現有意義的輸出(非空)。

這是一個boost union_()的bug嗎?

非常感謝

int main() 
{ 
    typedef boost::geometry::model::polygon<boost::geometry::model::d2::point_xy<double> > polygon; 

    polygon green, blue; 

    boost::geometry::read_wkt(
     "POLYGON((0 0,1 0,1 1,0 1))", 
     green); 

    boost::geometry::read_wkt(
     "POLYGON((2 1.3,2.4 1.7,2.8 1.8))", 
     blue); 

    std::deque<polygon> output; 
    boost::geometry::union_(green, blue, output); 

    int i = 0; 
    std::cout << "green && blue:" << std::endl; 
    BOOST_FOREACH(polygon const& p, output) 
    { 
     std::cout << i++ << ": " << boost::geometry::area(p) << std::endl; 
    } 

    return 0; 
} 
+0

看來我得到了答案。但我必須驗證它。只需爲每個多邊形調用boost :: geometry :: correct()即可。然後boost將給uion_()和intersection()賦予正確的結果。等一下。讓我測試它。 –

回答

1

有關於它的simmilar問題。該算法需要一些先決條件。 1)多邊形必須是順時針的。 2)多邊形具有閉合性,即最後一點恰好與第一點重合。

因此,要糾正有問題的多邊形數據中的問題,請調用boost :: geometry :: correct()以使數據符合規則。算法將接受多邊形並給出正確的結果。

Why boost::geometry::intersection does not work correct?