1

我在Debian 9上开发了一个应用程序,并通过命令安装了boost-1.62.0sudo apt-get install。我在打电话时发现了一个奇怪的行为boost::geometry::with_in(polygon, ring)。多边形与环相交,但不与 in 相交。代码如下:

#include <iostream>
#include <boost/geometry/algorithms/intersection.hpp>
#include <boost/version.hpp>
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/ring.hpp>
#include <boost/geometry/geometries/polygon.hpp>

using namespace std;
using namespace boost;
using namespace boost::geometry;

int main()
{
    using Point = boost::geometry::model::d2::point_xy<double>;
    using Polygon = boost::geometry::model::polygon<Point>;
    using Ring = boost::geometry::model::ring<Point>;

    Ring outer;
    append(outer, Point(-6.46720129179205, 15.61591992211971));
    append(outer, Point(-3.617204647384145, 15.61591992211971));
    append(outer, Point(-3.617204647384145, 7.615919922119708));
    append(outer, Point(-6.46720129179205, 7.615919922119708));
    append(outer, Point(-6.46720129179205, 15.61591992211971));

    Polygon polygon;
    polygon.outer() = outer;
    correct(polygon);

    Ring ring;
    append(ring, Point(-3.542202969588097, 7.615919922119709));
    append(ring, Point(-3.542202969588097, 6.81591992211971));
    append(ring, Point(-3.542202969588097, 6.015919922119708));
    append(ring, Point(-3.542202969588097, 5.215919922119708));
    append(ring, Point(-3.542202969588097, 4.415919922119708));
    append(ring, Point(-3.542202969588097, 3.615919922119708));
    append(ring, Point(-3.542202969588097, 2.815919922119709));
    append(ring, Point(-3.542202969588097, 2.015919922119709));
    append(ring, Point(-3.542202969588097, 1.215919922119709));
    append(ring, Point(-3.542202969588097, 0.4159199221197081));
    append(ring, Point(-3.542202969588097, -0.3840800778802915));
    append(ring, Point(-6.542202969588097, -0.3840800778802916));
    append(ring, Point(-6.542202969588097, 0.415919922119708));
    append(ring, Point(-6.542202969588097, 1.215919922119709));
    append(ring, Point(-6.542202969588097, 2.015919922119709));
    append(ring, Point(-6.542202969588097, 2.815919922119709));
    append(ring, Point(-6.542202969588097, 3.615919922119708));
    append(ring, Point(-6.542202969588096, 4.41591992211971));
    append(ring, Point(-6.542202969588097, 5.215919922119709));
    append(ring, Point(-6.542202969588097, 6.015919922119709));
    append(ring, Point(-6.542202969588097, 6.815919922119708));
    append(ring, Point(-6.542202969588097, 7.615919922119708));
    append(ring, Point(-3.542202969588097, 7.615919922119709));
    correct(ring);

    cout << boolalpha
         << within(polygon, ring) << endl /* should return false */
         << covered_by(polygon, ring) << endl; /* should retrurn false */

    return 0;
}

构建并运行:

 g++ -g -o wi wi.cpp
 ./wi

得到结果:

 true
 true

多边形不在环内,而是boost::geometry::within(polygon, ring)返回true

boost_within

那么它是 boost-1.62 的错误吗?以及如何解决它。

4

1 回答 1

1

差异 7.615919922119709 - 7.615919922119708 是 1×10^-15。

这意味着几何图形垂直重叠。根据标准的简单功能规范,这意味着它们满足within

在 boost 几何中创建实心多边形

于 2018-05-03T10:18:35.803 回答