Opened 5 years ago

Last modified 4 years ago

#13179 new Bugs

geometry::covered_by and geometry::within not working for certain values

Reported by: Stanley <stanley.foerster@…> Owned by: Barend Gehrels
Milestone: To Be Determined Component: geometry
Version: Boost 1.65.0 Severity: Problem
Keywords: Cc:

Description

covered_by and within return false even if the point is obviously located within the polygon, as the following code demonstrates:

#include <iostream>

#include <boost/version.hpp>

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

typedef boost::geometry::model::d2::point_xy<double> Point;
typedef boost::geometry::model::polygon<Point> Polygon;

int main() {
    std::cout << "Running Boost in version " << BOOST_VERSION << std::endl;

    Polygon polygon;
    std::vector<Point> points;

    points.emplace_back(Point(68.3, 35.5));
    points.emplace_back(Point(68.3, 35.6));
    points.emplace_back(Point(70.3, 35.9));
    points.emplace_back(Point(70.3, 35.8));
    Point point(69.2, 35.7);

    boost::geometry::assign_points(polygon, points);

    std::cout << "Point is covered by polygon: " << boost::geometry::covered_by(point, polygon) << std::endl;
    std::cout << "Point is within by polygon: " << boost::geometry::within(point, polygon) << std::endl;

    return 0;
}

which gives:

Running Boost in version 106500
Point is covered by polygon: 0
Point is within by polygon: 0

Change History (1)

in reply to:  description comment:1 by anonymous, 4 years ago

Replying to Stanley <stanley.foerster@…>:

covered_by and within return false even if the point is obviously located within the polygon, as the following code demonstrates:

#include <iostream>

#include <boost/version.hpp>

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

typedef boost::geometry::model::d2::point_xy<double> Point;
typedef boost::geometry::model::polygon<Point> Polygon;

int main() {
    std::cout << "Running Boost in version " << BOOST_VERSION << std::endl;

    Polygon polygon;
    std::vector<Point> points;

    points.emplace_back(Point(68.3, 35.5));
    points.emplace_back(Point(68.3, 35.6));
    points.emplace_back(Point(70.3, 35.9));
    points.emplace_back(Point(70.3, 35.8));
    Point point(69.2, 35.7);

    boost::geometry::assign_points(polygon, points);

    std::cout << "Point is covered by polygon: " << boost::geometry::covered_by(point, polygon) << std::endl;
    std::cout << "Point is within by polygon: " << boost::geometry::within(point, polygon) << std::endl;

    return 0;
}

which gives:

Running Boost in version 106500
Point is covered by polygon: 0
Point is within by polygon: 0

Did you ever find a work around for this? I'm testing the boost rtree, and it appears that "remove" is not properly drilling down because of the geometry::covered_by.. so even in boost version 1.67 (the latest), I'm stuck using my custom r-tree as boost does not remove all values. NOTE the intersection tests always work (so it seems anyways), as its simply I cannot remove certain values out of the rtree, and my guess is its related to this bug here that you documented.

Note: See TracTickets for help on using tickets.