Your question is about 3 functions:
- intersects (box, polygon)
- intersects (box, ring)
- within (box, ring)
Let me start from #3. The function within only supports box-box and box-point input. It means ring is implicitly converted to its bounding box, and the answers you get are correct (when one box is within another they are considered as intersecting as geometric shapes).
For #2 it seems you want to get "false" even if box is within a ring. It means you want to consider ring (contour) as a polyline (aka "linestring"). You should explain to Boost.Geometry to consider a ring as a linestring.
To do so, you can probably "wrap" your contour (or ring) point container into some class and then register this class as a linestring (or as multi-linestring). The class itself could be very light-weight, simply keeping a pointer to the container and providing proper const-access. You register this class as a linestring using a macro BOOST_GEOMETRY_REGISTER_LINESTRING
or BOOST_GEOMETRY_REGISTER_MULTI_LINESTRING
.
After that you pass it to "intersects" roughly as intersects(my_linestring_wrapper(polygon), box_view(box[i]))
. Here the code box_view(box[i])
will return a light-weight object which behaves as a "ring" (a contour).
For #1 you can get box-box or ring-ring intersection. To force the latter, you need to consider the box as a ring. Standard way to achieve this in Boost.Geometry is to apply a proper "view" to the box.