Skip to content

Instantly share code, notes, and snippets.

@mariosv
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mariosv/9c8f4fa106c0546f95cf to your computer and use it in GitHub Desktop.
Save mariosv/9c8f4fa106c0546f95cf to your computer and use it in GitHub Desktop.
[boost::geometry] within() invalid result
#include <iostream>
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/geometries.hpp>
#include <boost/geometry/io/wkt/wkt.hpp>
#include <boost/geometry/strategies/cartesian/point_in_poly_franklin.hpp>
#include <boost/geometry/strategies/cartesian/point_in_poly_crossings_multiply.hpp>
namespace bg = boost::geometry;
typedef bg::model::point<double, 2, bg::cs::cartesian> Point;
typedef bg::model::polygon<Point> Polygon;
int main()
{
Polygon poly;
bg::read_wkt("POLYGON((-2.00000000000000000000 -1.99999999999999977796,"
"-1.99999999999999977796 2.00000000000000000000,"
"2.00000000000000000000 1.99999999999999977796,"
"1.99999999999999977796 -2.00000000000000000000,"
"-2.00000000000000000000 -1.99999999999999977796))",
poly);
Point p;
bg::read_wkt("POINT(4.00000000000000000000 -2.00000000000000044409)", p);
bool r1 = bg::within(p, poly);
bool r2 = bg::within(p, poly, bg::strategy::within::franklin<Point>());
bool r3 = bg::within(p, poly,
bg::strategy::within::crossings_multiply<Point>());
std::cout << "results: " << r1 << ", " << r2 << ", " << r3 << "\n";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment