Reputation: 7728
I am looking for an approach to find a set of squares that are fully contained inside a QPolygon, which is not necessarily convex. My naive approach so far looks like this:
QRectF boundingRect(mShape->boundingRect());
for (int x = boundingRect.x() - 1; x < boundingRect.width(); x++)
{
for (int y = boundingRect.y() - 1; y < boundingRect.height(); y++)
{
QRectF rect(x, y, 1, 1);
QPolygonF cell(rect);
QPolygonF intersection = mShape->polygon().intersected(cell);
if (!intersection.empty())
{
// Cell is fully contained
}
}
}
When I visualise the result, it looks like this:
This is almost what I want, except that the cells intersecting with the "outline" of the polygon shouldn't be there. Does anyone have a nice idea how I could construct a set of squares that are entirely "inside" the polygon?
Upvotes: 0
Views: 1086
Reputation: 88017
Assuming that the larger polygon is convex (it is in your example), it should be sufficient to check that all four corners of your square are inside the larger polygon. Use the containsPoint method on the larger polygon.
Upvotes: 1