/*! 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(); } }
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; } }