I want to determine if point is inside polygon with boost::geometry.
I use function boost::geometry::within and type boost::geometry::linear_ring<boost::geometry::point_2d>
to specify contour.
All work fine if I don't need to account orientation of contour.
But in my case I want to account orientation. I mean that if inner region for specific contour is considered limited by its border and finite, then the inner area of inverted contour should be infinite - complementation to area of initial contour.
Is it possible to account orientation of contour in within
function?
It can be expessed in the following code:
// Create contour which defines square
boost::geometry::linear_ring<boost::geometry::point_2d> contour;
contour.push_back(boost::geometry::point_2d(4, 2));
contour.push_back(boost::geometry::point_2d(2, 2));
contour.push_back(boost::geometry::point_2d(2, 4));
contour.push_back(boost::geometry::point_2d(4, 4));
contour.push_back(boost::geometry::point_2d(4, 2));
// Create contour which defines square with opposite direction.
boost::geometry::linear_ring<boost::geometry::point_2d> contourInverted = contour;
std::reverse(contourInverted.begin(), contourInverted.end());
// Specify point inside square
boost::geometry::point_2d testPoint(3, 3);
// Perform tests
bool ret1 = boost::geometry::within(testPoint, contour);
bool ret2 = boost::geometry::within(testPoint, contourInverted);
After execution of the code above ret1
and ret2
are both true
. But I would have ret1 != ret2
.
In general I need to obtain functionaly when ret1 != ret2
for any testPoint
(I don't consider border cases here when point is exactly on the border or polygon is degenerated etc...)
I tried different strategies to pass to boost::geometry::within
, but I have not obtained what I need.
It seems that functionality which I need or similar is implemented somewhere in the boost::geometry
, because the documetation for within has example of polygon with holes. But I have not realised how to use it for my case.
There is also quite simple workaround. I need just write a code to determine orientation of contour. Then I just negate or not result of within
function depending on contour orientation. But if boost::geometry
has implementation already I don't want to duplicate it.