Opened 8 years ago

Closed 8 years ago

#10234 closed Bugs (fixed)

boost::geometry::covered_by wrong results

Reported by: Alexander Sarychev <alex-x@…> Owned by: awulkiew
Milestone: Boost 1.56.0 Component: geometry
Version: Boost 1.55.0 Severity: Problem
Keywords: geometry covered_by Cc:

Description

I have a problem with boost::geometry::covered_by method to determine if point is inside polygon or not. In the example below I have point that is exactly out of polygon. Point is far away from polygon by x coordinate (0.1377). The 3rd point of polygon has y-coordinate (4.9999999999999982). And this leads to problem I think. When I change 4.9999999999999982 to 5.00 all is OK. What to do?

#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/geometry/io/wkt/wkt.hpp>


int main()
{
typedef boost::geometry::model::d2::point_xy<double> bg_point;
typedef boost::geometry::model::polygon< bg_point, false, true > bg_polygon;

// point is tested (out of polygon)
bg_point    p(0.1377, 5.00);

// polygon
bg_polygon  poly;
boost::geometry::read_wkt("POLYGON((0.1277 4.97,  0.1277 5.00, 0.1278 4.9999999999999982, 0.1278 4.97, 0.1277 4.97))", poly);

bool inside;

// inside = true here (ERROR!)
inside = boost::geometry::covered_by(p, poly);

// change 4.9999999999999982 to 5.00
boost::geometry::read_wkt("POLYGON((0.1277 4.97,  0.1277 5.00, 0.1278 5.00, 0.1278 4.97, 0.1277 4.97))", poly);

// inside = false here (OK)
inside = boost::geometry::covered_by(p, poly);

return 0;
}

Change History (4)

comment:1 by Barend Gehrels, 8 years ago

Milestone: To Be DeterminedBoost 1.56.0
Owner: changed from Barend Gehrels to awulkiew

Thanks for the report. Adam, most probably similar problem as you recently solved, can you confirm that? If so, it will be fixed in 1.56

comment:2 by awulkiew, 8 years ago

Yes, it's fixed. The cause is the same as in https://svn.boost.org/trac/boost/ticket/9628.

I also added a test, just in case: https://github.com/boostorg/geometry/commit/42cf08658ce632014c14a3bfd70ef020832b296b

Should this be resolved as fixed or duplicate?

comment:3 by Barend Gehrels, 8 years ago

I would set it to fixed, they have the same cause but this issue states covered_by, the other within, so it is from user-perspective another algorithm that is fixed, and you added a testcase (thanks)

comment:4 by awulkiew, 8 years ago

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.