 # Geometry :

Subject: [geometry] Call to geometry::within returns true when point is outside ring
From: Rob K. (kashiraja_at_[hidden])
Date: 2012-10-14 19:57:23

Hi,
I'm seeing some unexpected behavior in a call to within. In the code below
I am checking if a coordinate (0,0) is within a ring. The ring is
positioned to the right of the origin so within should return false, but it
returns true.
However, if the ring coordinates conform to a true rectangle (for example,
all lines are parallel to either X or Y axis), the function returns false
regardless of where the rectangle is positioned in the Y direction (as
expected).

Moving the ring along different offsets along the y-axis, it seems if any
line intersects the x-axis at an angle, it returns true. E.g. in the test
case below the top line is (4,0) to (6,-.1).
I've just started using this library so it is possible I have over looked
some assumption (I have made sure that the coordinates are listed in
clockwise order at least).

I a post a month or two ago that indicates that ::within might still not be
fully functional? (
http://boost-geometry.203548.n3.nabble.com/a-ring-concept-implementation-of-a-true-circle-td4025091.html#a4025110
)

Thanks,
Rob

-----
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/adapted/boost_tuple.hpp>
#include <boost/assign.hpp>

bool TestPointWithinRing()
{
typedef boost::geometry::model::d2::point_xy<double> Point;
typedef boost::geometry::model::ring<Point> Ring;

bool result = false;
Point myPoint;
Ring myRect;

boost::geometry::assign_values(myPoint, 0.0, 0.0);

// (0,0) is within
// (4,0)-----(6,-.1)
// | |
// (4,-3.1)--(6,-3.1)
//

// Within returns TRUE (should return FALSE)
boost::geometry::assign_points(
myRect, boost::assign::tuple_list_of
(6., -.1) (6., -3.1) (4., -3.1) (4., 0.)
);

// Within returns false in both cases: (OK)
//boost::geometry::assign_points(
// myRect, boost::assign::tuple_list_of
// (6., -.1) (6., -3.1) (4., -3.1) (4., -.1)
//);
//boost::geometry::assign_points(
// myRect, boost::assign::tuple_list_of
// (6., 0) (6., -3.1) (4., -3.1) (4., 0)
//);

result = boost::geometry::within(myPoint, myRect);

return result;
}

Geometry list run by mateusz at loskot.net