4

Boost Geometry交差関数の次のテスト関数を書きました

typedef boost::geometry::model::polygon<boost::tuple<int, int> > Polygon;

void test_boost_intersection() {
  Polygon green, blue;
  boost::geometry::read_wkt("POLYGON((0 0,0 9,9 9,9 0,0 0))", green);
  boost::geometry::read_wkt("POLYGON((2 2,2 9,9 9,9 2,2 2))", blue);
  std::deque<Polygon> output;
  boost::geometry::intersection(green, blue, output);
  BOOST_FOREACH(Polygon const& p, output)
  {
    std::cout << boost::geometry::dsv(p) << std::endl;
  }
};

私は出力結果を次のように期待していました:

(((2, 2), (2, 9), (9, 9), (9, 2), (2, 2)))

しかし、私は得ました:

((((1, 9), (9, 9), (9, 2), (2, 2), (1, 9))))

Boost1.54を使用しています。

最初のポリゴンを変更すると、交差は正しく機能します。

編集:ポリゴンのタイプをに変更したとき

boost::geometry::model::polygon<boost::geometry::model::d2::point_xy<double> >

正しく動作するようになりました。では、以前のタイプを常に使用することはできませんか?

4

1 に答える 1

4

correctアルゴリズムの前提条件を満たすには、ポリゴンを入力する必要があります: Live On Coliruプリント

(((2, 9), (9, 9), (9, 2), (2, 2), (2, 9)))
#include <boost/tuple/tuple.hpp>
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/geometry/geometries/adapted/boost_tuple.hpp>
#include <boost/foreach.hpp>
typedef boost::geometry::model::polygon<boost::tuple<int, int> > Polygon;

BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)

void test_boost_intersection() {
    Polygon green, blue;
    boost::geometry::read_wkt("POLYGON((0 0,0 9,9 9,9 0,0 0))", green);
    boost::geometry::read_wkt("POLYGON((2 2,2 9,9 9,9 2,2 2))", blue);
    boost::geometry::correct(green);
    boost::geometry::correct(blue);
    std::deque<Polygon> output;
    boost::geometry::intersection(green, blue, output);
    BOOST_FOREACH(Polygon const& p, output)
    {
        std::cout << boost::geometry::dsv(p) << std::endl;
    }
}

int main()
{
    test_boost_intersection();
}
于 2014-05-28T12:38:59.960 に答える