Opened 5 years ago

Last modified 5 years ago

#13078 new Bugs

boost::geometry::intersection between a polygon and a box produces incorrect results

Reported by: David R <ratchkov@…> Owned by: Barend Gehrels
Milestone: To Be Determined Component: geometry
Version: Boost 1.59.0 Severity: Problem
Keywords: Cc:

Description

I am intersecting a polygon with a box and with a polygon of the same points as the box. The result from box intersection is incorrect - it is a large as the original polygon.

Here is the code:

#include <iostream>`

#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>

namespace bg = boost::geometry;
namespace bgm = bg::model;

typedef double base_type;
typedef bgm::d2::point_xy<base_type> point_type;
typedef bgm::polygon<point_type> polygon_type;
typedef bgm::multi_polygon<polygon_type> multipolygon_type;

int main() {
std::vector<point_type> points {
    {7.99922500000000127329e+02, 1.04990090625000011642e+04},
    {7.99922500000000013642e+02, 9.99905624999999963620e+03},
    {3.99961250000000006821e+02, 9.99905624999999963620e+03},
    {3.99961250000000006821e+02, 1.04990090625000011642e+04},
    {7.99922500000000127329e+02, 1.04990090625000011642e+04},
};
polygon_type poly;
bg::assign_points(poly, points);
bgm::box<point_type> box(
    {5.99941874999999981810e+02, 1.02490326562500013097e+04},
    {7.99922500000000013642e+02, 1.04990090625000011642e+04}
);

std::vector<point_type> box_points {
    {5.99941874999999981810e+02, 1.02490326562500013097e+04},
    {5.99941874999999981810e+02, 1.04990090625000011642e+04},
    {7.99922500000000013642e+02, 1.04990090625000011642e+04},
    {7.99922500000000013642e+02, 1.02490326562500013097e+04},
    {5.99941874999999981810e+02, 1.02490326562500013097e+04},
};
polygon_type box2;
bg::assign_points(box2, box_points);

multipolygon_type out;
bg::intersection(poly, box, out);
std::cout << bg::area(out) << " " << bg::wkt(out) << std::endl;

multipolygon_type out2;
bg::intersection(poly, box2, out2);
std::cout << bg::area(out2) << " " <<  bg::wkt(out2) << std::endl;
return 0;
}

And this is the output:

199962 MULTIPOLYGON(((599.942 10499,799.923 10499,799.923 9999.06,399.961 9999.06,399.961 10499,599.942 10499)))
49990.4 MULTIPOLYGON(((799.923 10249,599.942 10249,599.942 10499,799.923 10499,799.923 10249)))

Is this expected?

Change History (1)

comment:1 by John Maddock, 5 years ago

Component: Nonegeometry
Owner: set to Barend Gehrels
Note: See TracTickets for help on using tickets.