Exemplo n.º 1
0
/*!
    Returns true if this sphere intersects \a box; false otherwise.
*/
bool QSphere3D::intersects(const QBox3D &box) const
{
    if (box.isFinite()) {
        // Use Arvo's Algorithm to determine if we have an intersection.
        qreal dist = 0.0f;
        qreal center = m_center.x();
        qreal minval = box.minimum().x();
        qreal maxval = box.maximum().x();
        if (center < minval)
            dist += (center - minval) * (center - minval);
        else if (center > maxval)
            dist += (center - maxval) * (center - maxval);
        center = m_center.y();
        minval = box.minimum().y();
        maxval = box.maximum().y();
        if (center < minval)
            dist += (center - minval) * (center - minval);
        else if (center > maxval)
            dist += (center - maxval) * (center - maxval);
        center = m_center.z();
        minval = box.minimum().z();
        maxval = box.maximum().z();
        if (center < minval)
            dist += (center - minval) * (center - minval);
        else if (center > maxval)
            dist += (center - maxval) * (center - maxval);
        return dist <= (m_radius * m_radius);
    } else {
        return box.isInfinite();
    }
}
Exemplo n.º 2
0
QDebug operator<<(QDebug dbg, const QBox3D &box)
{
    if (box.isFinite()) {
        dbg.nospace() << "QBox3D(("
            << box.minimum().x() << ", " << box.minimum().y() << ", "
            << box.minimum().z() << ") - ("
            << box.maximum().x() << ", " << box.maximum().y() << ", "
            << box.maximum().z() << ')';
        return dbg.space();
    } else if (box.isNull()) {
        dbg << "QBox3D(null)";
        return dbg;
    } else {
        dbg << "QBox3D(infinite)";
        return dbg;
    }
}
Exemplo n.º 3
0
/*!
    Unites this box with \a box by expanding this box to encompass the
    region defined by \a box.  If \a box is already contained within
    this box, then this box will be unchanged.

    \sa united(), intersect()
*/
void QBox3D::unite(const QBox3D& box)
{
    if (box.boxtype == Finite) {
        unite(box.minimum());
        unite(box.maximum());
    } else if (box.boxtype == Infinite) {
        setToInfinite();
    }
}