Example #1
0
    return path;
}

bool minigis::rectIntersectPolyHollow(const QRectF &rect, const QPolygonF &poly, bool closed)
{
    foreach (QPointF p, poly)
        if (rect.contains(p))
            return true;

    QLineF top(rect.topLeft(), rect.topRight());
    QLineF right(rect.topRight(), rect.bottomRight());
    QLineF bottom(rect.bottomRight(), rect.bottomLeft());
    QLineF left(rect.bottomLeft(), rect.topLeft());

    int N = closed ? poly.size() + 1 : poly.size();
    for (int i = 1; i < N; ++i) {
        QLineF tmp(poly[i-1], poly[i % poly.size()]);
        QPointF a;
        if (top.intersect(tmp, &a)    == QLineF::BoundedIntersection)
            return true;
        if (bottom.intersect(tmp, &a) == QLineF::BoundedIntersection)
            return true;
        if (right.intersect(tmp, &a)  == QLineF::BoundedIntersection)
            return true;
        if (left.intersect(tmp, &a)   == QLineF::BoundedIntersection)
            return true;
    }

    return false;
}