boost :: geometry :: union_()带有一个可选的“ strategy”参数,该参数被描述为“满足Union_ Strategy概念的任何类型”。我有兴趣研究是否存在可以帮助我解决特定问题的现有策略。这是一些代码:
using point_t = boost::geometry::model::d2::point_xy<double>;
using polygon_t = boost::geometry::model::polygon<point_t>;
using mpolygon_t = boost::geometry::model::multi_polygon<polygon_t>;
polygon_t obstacle1{{{-2, 7},
{2, 7},
{2, 3},
{-2, 3},
{-2, 7}}};
mpolygon_t consolidated;
for (auto const& obstacle : obstacles) {
if (boost::geometry::overlaps(obstacle, consolidated)) {
mpolygon_t temp;
boost::geometry::union_(obstacle, consolidated, temp);
consolidated = std::move(temp);
} else {
consolidated.push_back(obstacle);
}
}
polygon_t obstacle2{{{-2.8284271247461903, 5},
{0, 7.82842712474619},
{2.8284271247461903, 5},
{0, 2.1715728752538097},
{-2.8284271247461903, 5}}};
polygon_t obstacle3{{{0.75, 3.0},
{0.75, 2.4215728752538097},
{0.2, 2.4215728752538097},
{0.75, 3.0}}};
mpolygon_t obstacles{obstacle1, obstacle2, obstacle3};
mpolygon_t consolidated;
for (auto const& obstacle : obstacles) {
if (boost::geometry::overlaps(obstacle, consolidated)) {
mpolygon_t temp;
boost::geometry::union_(obstacle, consolidated, temp);
consolidated = std::move(temp);
} else {
consolidated.push_back(obstacle);
}
}
我希望obstacle2
和obstacle3
的并集产生的顶点与obstacle2
的适当边共线。我发现它们的距离大约是1e-7,这比我预期的要大得多(毕竟,基本坐标类型是double
。
那么,有没有我可以提供的策略来减少我看到的错误?