I'm currently using boost 1.67 and
I'm finding that if I use boost::geometry::within()
to check if a point is within a segment, I'm not getting answers I'd expect. For example, I can construct a couple of segments that intersect, and use boost::geometry::intersection()
to acquire the point of intersection. I would expect that point to be within each of the edges. That's not always what I'm seeing, however. Here's some code demonstrating my problem:
#include <iostream>
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
int main() {
using point_t = boost::geometry::model::d2::point_xy<double>;
using segment_t = boost::geometry::model::segment<point_t>;
segment_t e1{point_t{100, 350}, point_t{-100, 400}};
segment_t e2{point_t{0, 0}, point_t{90, 600}};
std::vector<point_t> iv;
boost::geometry::intersection(e1, e2, iv);
assert(iv.size() == 1);
const auto& v = iv[0];
bool is_within = boost::geometry::within(v, e1);
std::cout << "is within? " << is_within << std::endl;
is_within = boost::geometry::within(v, e2);
std::cout << "is within? " << is_within << std::endl;
return 0;
}
In this case within()
returns false for both edges.