Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-26 08:20:07

0001 // Copyright (C) 2022 The Qt Company Ltd.
0002 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
0003 
0004 #ifndef QRECT_H
0005 #define QRECT_H
0006 
0007 #include <QtCore/qcheckedint_impl.h>
0008 #include <QtCore/qhashfunctions.h>
0009 #include <QtCore/qmargins.h>
0010 #include <QtCore/qsize.h>
0011 #include <QtCore/qpoint.h>
0012 
0013 #ifdef topLeft
0014 #error qrect.h must be included before any header file that defines topLeft
0015 #endif
0016 
0017 #if defined(Q_OS_DARWIN) || defined(Q_QDOC)
0018 struct CGRect;
0019 #endif
0020 #if defined(Q_OS_WASM) || defined(Q_QDOC)
0021 namespace emscripten {
0022 class val;
0023 }
0024 #endif
0025 
0026 QT_BEGIN_NAMESPACE
0027 
0028 class QRectF;
0029 
0030 class Q_CORE_EXPORT QRect
0031 {
0032 public:
0033     constexpr QRect() noexcept : x1(0), y1(0), x2(-1), y2(-1) {}
0034     constexpr QRect(const QPoint &topleft, const QPoint &bottomright) noexcept;
0035     constexpr QRect(const QPoint &topleft, const QSize &size) noexcept;
0036     constexpr QRect(int left, int top, int width, int height) noexcept;
0037 
0038     constexpr inline bool isNull() const noexcept;
0039     constexpr inline bool isEmpty() const noexcept;
0040     constexpr inline bool isValid() const noexcept;
0041 
0042     constexpr inline int left() const noexcept;
0043     constexpr inline int top() const noexcept;
0044     constexpr inline int right() const noexcept;
0045     constexpr inline int bottom() const noexcept;
0046     [[nodiscard]] QRect normalized() const noexcept;
0047 
0048     constexpr inline int x() const noexcept;
0049     constexpr inline int y() const noexcept;
0050     constexpr inline void setLeft(int pos) noexcept;
0051     constexpr inline void setTop(int pos) noexcept;
0052     constexpr inline void setRight(int pos) noexcept;
0053     constexpr inline void setBottom(int pos) noexcept;
0054     constexpr inline void setX(int x) noexcept;
0055     constexpr inline void setY(int y) noexcept;
0056 
0057     constexpr inline void setTopLeft(const QPoint &p) noexcept;
0058     constexpr inline void setBottomRight(const QPoint &p) noexcept;
0059     constexpr inline void setTopRight(const QPoint &p) noexcept;
0060     constexpr inline void setBottomLeft(const QPoint &p) noexcept;
0061 
0062     constexpr inline QPoint topLeft() const noexcept;
0063     constexpr inline QPoint bottomRight() const noexcept;
0064     constexpr inline QPoint topRight() const noexcept;
0065     constexpr inline QPoint bottomLeft() const noexcept;
0066     constexpr inline QPoint center() const noexcept;
0067 
0068     constexpr inline void moveLeft(int pos) noexcept;
0069     constexpr inline void moveTop(int pos) noexcept;
0070     constexpr inline void moveRight(int pos) noexcept;
0071     constexpr inline void moveBottom(int pos) noexcept;
0072     constexpr inline void moveTopLeft(const QPoint &p) noexcept;
0073     constexpr inline void moveBottomRight(const QPoint &p) noexcept;
0074     constexpr inline void moveTopRight(const QPoint &p) noexcept;
0075     constexpr inline void moveBottomLeft(const QPoint &p) noexcept;
0076     constexpr inline void moveCenter(const QPoint &p) noexcept;
0077 
0078     constexpr inline void translate(int dx, int dy) noexcept;
0079     constexpr inline void translate(const QPoint &p) noexcept;
0080     [[nodiscard]] constexpr inline QRect translated(int dx, int dy) const noexcept;
0081     [[nodiscard]] constexpr inline QRect translated(const QPoint &p) const noexcept;
0082     [[nodiscard]] constexpr inline QRect transposed() const noexcept;
0083 
0084     constexpr inline void moveTo(int x, int t) noexcept;
0085     constexpr inline void moveTo(const QPoint &p) noexcept;
0086 
0087     constexpr inline void setRect(int x, int y, int w, int h) noexcept;
0088     constexpr inline void getRect(int *x, int *y, int *w, int *h) const;
0089 
0090     constexpr inline void setCoords(int x1, int y1, int x2, int y2) noexcept;
0091     constexpr inline void getCoords(int *x1, int *y1, int *x2, int *y2) const;
0092 
0093     constexpr inline void adjust(int x1, int y1, int x2, int y2) noexcept;
0094     [[nodiscard]] constexpr inline QRect adjusted(int x1, int y1, int x2, int y2) const noexcept;
0095 
0096     constexpr inline QSize size() const noexcept;
0097     constexpr inline int width() const noexcept;
0098     constexpr inline int height() const noexcept;
0099     constexpr inline void setWidth(int w) noexcept;
0100     constexpr inline void setHeight(int h) noexcept;
0101     constexpr inline void setSize(const QSize &s) noexcept;
0102 
0103     QRect operator|(const QRect &r) const noexcept;
0104     QRect operator&(const QRect &r) const noexcept;
0105     inline QRect &operator|=(const QRect &r) noexcept;
0106     inline QRect &operator&=(const QRect &r) noexcept;
0107 
0108     bool contains(const QRect &r, bool proper = false) const noexcept;
0109     bool contains(const QPoint &p, bool proper = false) const noexcept;
0110     inline bool contains(int x, int y) const noexcept;
0111     inline bool contains(int x, int y, bool proper) const noexcept;
0112     [[nodiscard]] inline QRect united(const QRect &other) const noexcept;
0113     [[nodiscard]] inline QRect intersected(const QRect &other) const noexcept;
0114     bool intersects(const QRect &r) const noexcept;
0115 
0116     constexpr inline QRect marginsAdded(const QMargins &margins) const noexcept;
0117     constexpr inline QRect marginsRemoved(const QMargins &margins) const noexcept;
0118     constexpr inline QRect &operator+=(const QMargins &margins) noexcept;
0119     constexpr inline QRect &operator-=(const QMargins &margins) noexcept;
0120 
0121     [[nodiscard]] static constexpr inline QRect span(const QPoint &p1, const QPoint &p2) noexcept;
0122 
0123 private:
0124     friend constexpr bool comparesEqual(const QRect &r1, const QRect &r2) noexcept
0125     { return r1.x1==r2.x1 && r1.x2==r2.x2 && r1.y1==r2.y1 && r1.y2==r2.y2; }
0126     Q_DECLARE_EQUALITY_COMPARABLE_LITERAL_TYPE(QRect)
0127     friend constexpr inline size_t qHash(const QRect &, size_t) noexcept;
0128 
0129 public:
0130 #if defined(Q_OS_DARWIN) || defined(Q_QDOC)
0131     [[nodiscard]] CGRect toCGRect() const noexcept;
0132 #endif
0133     [[nodiscard]] constexpr inline QRectF toRectF() const noexcept;
0134 
0135 private:
0136     using Representation = QtPrivate::QCheckedIntegers::QCheckedInt<int>;
0137 
0138     constexpr QRect(Representation aleft,
0139                     Representation atop,
0140                     Representation awidth,
0141                     Representation aheight) noexcept
0142         : x1(aleft), y1(atop),
0143           x2(aleft + awidth - 1), y2(atop + aheight - 1)
0144     {}
0145 
0146     Representation x1;
0147     Representation y1;
0148     Representation x2;
0149     Representation y2;
0150 };
0151 Q_DECLARE_TYPEINFO(QRect, Q_RELOCATABLE_TYPE);
0152 
0153 
0154 /*****************************************************************************
0155   QRect stream functions
0156  *****************************************************************************/
0157 #ifndef QT_NO_DATASTREAM
0158 Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QRect &);
0159 Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QRect &);
0160 #endif
0161 
0162 /*****************************************************************************
0163   QRect inline member functions
0164  *****************************************************************************/
0165 
0166 constexpr inline QRect::QRect(int aleft, int atop, int awidth, int aheight) noexcept
0167     : QRect(Representation(aleft), Representation(atop), Representation(awidth), Representation(aheight)) {}
0168 
0169 constexpr inline QRect::QRect(const QPoint &atopLeft, const QPoint &abottomRight) noexcept
0170     : x1(atopLeft.x()), y1(atopLeft.y()), x2(abottomRight.x()), y2(abottomRight.y()) {}
0171 
0172 constexpr inline QRect::QRect(const QPoint &atopLeft, const QSize &asize) noexcept
0173     : x1(atopLeft.x()), y1(atopLeft.y()), x2(x1 + asize.width() - 1), y2(y1 + asize.height() - 1) {}
0174 
0175 constexpr inline bool QRect::isNull() const noexcept
0176 {
0177     // This strange behavior is here for backwards compatibility -- a
0178     // rectangle spanning from INT_MIN to INT_MAX is considered null.
0179     constexpr Representation minInt((std::numeric_limits<int>::min)());
0180     constexpr Representation maxInt((std::numeric_limits<int>::max)());
0181     const auto adjustedX1 = Q_UNLIKELY(x1 == minInt) ? maxInt : x1 - 1;
0182     const auto adjustedY1 = Q_UNLIKELY(y1 == minInt) ? maxInt : y1 - 1;
0183     return x2 == adjustedX1 && y2 == adjustedY1;
0184 }
0185 
0186 constexpr inline bool QRect::isEmpty() const noexcept
0187 { return x1 > x2 || y1 > y2; }
0188 
0189 constexpr inline bool QRect::isValid() const noexcept
0190 { return x1 <= x2 && y1 <= y2; }
0191 
0192 constexpr inline int QRect::left() const noexcept
0193 { return x1.value(); }
0194 
0195 constexpr inline int QRect::top() const noexcept
0196 { return y1.value(); }
0197 
0198 constexpr inline int QRect::right() const noexcept
0199 { return x2.value(); }
0200 
0201 constexpr inline int QRect::bottom() const noexcept
0202 { return y2.value(); }
0203 
0204 constexpr inline int QRect::x() const noexcept
0205 { return x1.value(); }
0206 
0207 constexpr inline int QRect::y() const noexcept
0208 { return y1.value(); }
0209 
0210 constexpr inline void QRect::setLeft(int pos) noexcept
0211 { x1.setValue(pos); }
0212 
0213 constexpr inline void QRect::setTop(int pos) noexcept
0214 { y1.setValue(pos); }
0215 
0216 constexpr inline void QRect::setRight(int pos) noexcept
0217 { x2.setValue(pos); }
0218 
0219 constexpr inline void QRect::setBottom(int pos) noexcept
0220 { y2.setValue(pos); }
0221 
0222 constexpr inline void QRect::setTopLeft(const QPoint &p) noexcept
0223 { x1.setValue(p.x()); y1.setValue(p.y()); }
0224 
0225 constexpr inline void QRect::setBottomRight(const QPoint &p) noexcept
0226 { x2.setValue(p.x()); y2.setValue(p.y()); }
0227 
0228 constexpr inline void QRect::setTopRight(const QPoint &p) noexcept
0229 { x2.setValue(p.x()); y1.setValue(p.y()); }
0230 
0231 constexpr inline void QRect::setBottomLeft(const QPoint &p) noexcept
0232 { x1.setValue(p.x()); y2.setValue(p.y()); }
0233 
0234 constexpr inline void QRect::setX(int ax) noexcept
0235 { x1.setValue(ax); }
0236 
0237 constexpr inline void QRect::setY(int ay) noexcept
0238 { y1.setValue(ay); }
0239 
0240 constexpr inline QPoint QRect::topLeft() const noexcept
0241 { return QPoint(x1, y1); }
0242 
0243 constexpr inline QPoint QRect::bottomRight() const noexcept
0244 { return QPoint(x2, y2); }
0245 
0246 constexpr inline QPoint QRect::topRight() const noexcept
0247 { return QPoint(x2, y1); }
0248 
0249 constexpr inline QPoint QRect::bottomLeft() const noexcept
0250 { return QPoint(x1, y2); }
0251 
0252 constexpr inline QPoint QRect::center() const noexcept
0253 {
0254     // cast avoids overflow on addition
0255     return QPoint(int((qint64(x1.value()) + x2.value()) / 2),
0256                   int((qint64(y1.value()) + y2.value()) / 2));
0257 }
0258 
0259 constexpr inline int QRect::width() const noexcept
0260 { return (x2 - x1 + 1).value(); }
0261 
0262 constexpr inline int QRect::height() const noexcept
0263 { return (y2 - y1 + 1).value(); }
0264 
0265 constexpr inline QSize QRect::size() const noexcept
0266 { return QSize(width(), height()); }
0267 
0268 constexpr inline void QRect::translate(int dx, int dy) noexcept
0269 {
0270     x1 += dx;
0271     y1 += dy;
0272     x2 += dx;
0273     y2 += dy;
0274 }
0275 
0276 constexpr inline void QRect::translate(const QPoint &p) noexcept
0277 {
0278     x1 += p.x();
0279     y1 += p.y();
0280     x2 += p.x();
0281     y2 += p.y();
0282 }
0283 
0284 constexpr inline QRect QRect::translated(int dx, int dy) const noexcept
0285 { return QRect(QPoint(x1 + dx, y1 + dy), QPoint(x2 + dx, y2 + dy)); }
0286 
0287 constexpr inline QRect QRect::translated(const QPoint &p) const noexcept
0288 { return QRect(QPoint(x1 + p.x(), y1 + p.y()), QPoint(x2 + p.x(), y2 + p.y())); }
0289 
0290 constexpr inline QRect QRect::transposed() const noexcept
0291 { return QRect(topLeft(), size().transposed()); }
0292 
0293 constexpr inline void QRect::moveTo(int ax, int ay) noexcept
0294 {
0295     Representation rax(ax);
0296     Representation ray(ay);
0297     x2 += rax - x1;
0298     y2 += ray - y1;
0299     x1 = rax;
0300     y1 = ray;
0301 }
0302 
0303 constexpr inline void QRect::moveTo(const QPoint &p) noexcept
0304 {
0305     x2 += Representation(p.x()) - x1;
0306     y2 += Representation(p.y()) - y1;
0307     x1 = Representation(p.x());
0308     y1 = Representation(p.y());
0309 }
0310 
0311 constexpr inline void QRect::moveLeft(int pos) noexcept
0312 { x2 += (pos - x1); x1.setValue(pos); }
0313 
0314 constexpr inline void QRect::moveTop(int pos) noexcept
0315 { y2 += (pos - y1); y1.setValue(pos); }
0316 
0317 constexpr inline void QRect::moveRight(int pos) noexcept
0318 {
0319     x1 += (pos - x2);
0320     x2.setValue(pos);
0321 }
0322 
0323 constexpr inline void QRect::moveBottom(int pos) noexcept
0324 {
0325     y1 += (pos - y2);
0326     y2.setValue(pos);
0327 }
0328 
0329 constexpr inline void QRect::moveTopLeft(const QPoint &p) noexcept
0330 {
0331     moveLeft(p.x());
0332     moveTop(p.y());
0333 }
0334 
0335 constexpr inline void QRect::moveBottomRight(const QPoint &p) noexcept
0336 {
0337     moveRight(p.x());
0338     moveBottom(p.y());
0339 }
0340 
0341 constexpr inline void QRect::moveTopRight(const QPoint &p) noexcept
0342 {
0343     moveRight(p.x());
0344     moveTop(p.y());
0345 }
0346 
0347 constexpr inline void QRect::moveBottomLeft(const QPoint &p) noexcept
0348 {
0349     moveLeft(p.x());
0350     moveBottom(p.y());
0351 }
0352 
0353 constexpr inline void QRect::moveCenter(const QPoint &p) noexcept
0354 {
0355     auto w = x2 - x1;
0356     auto h = y2 - y1;
0357     x1 = p.x() - w/2;
0358     y1 = p.y() - h/2;
0359     x2 = x1 + w;
0360     y2 = y1 + h;
0361 }
0362 
0363 constexpr inline void QRect::getRect(int *ax, int *ay, int *aw, int *ah) const
0364 {
0365     *ax = x1.value();
0366     *ay = y1.value();
0367     *aw = (x2 - x1 + 1).value();
0368     *ah = (y2 - y1 + 1).value();
0369 }
0370 
0371 constexpr inline void QRect::setRect(int ax, int ay, int aw, int ah) noexcept
0372 {
0373     x1.setValue(ax);
0374     y1.setValue(ay);
0375     x2 = (x1 + aw - 1);
0376     y2 = (y1 + ah - 1);
0377 }
0378 
0379 constexpr inline void QRect::getCoords(int *xp1, int *yp1, int *xp2, int *yp2) const
0380 {
0381     *xp1 = x1.value();
0382     *yp1 = y1.value();
0383     *xp2 = x2.value();
0384     *yp2 = y2.value();
0385 }
0386 
0387 constexpr inline void QRect::setCoords(int xp1, int yp1, int xp2, int yp2) noexcept
0388 {
0389     x1.setValue(xp1);
0390     y1.setValue(yp1);
0391     x2.setValue(xp2);
0392     y2.setValue(yp2);
0393 }
0394 
0395 constexpr inline QRect QRect::adjusted(int xp1, int yp1, int xp2, int yp2) const noexcept
0396 { return QRect(QPoint(x1 + xp1, y1 + yp1), QPoint(x2 + xp2, y2 + yp2)); }
0397 
0398 constexpr inline void QRect::adjust(int dx1, int dy1, int dx2, int dy2) noexcept
0399 {
0400     x1 += dx1;
0401     y1 += dy1;
0402     x2 += dx2;
0403     y2 += dy2;
0404 }
0405 
0406 constexpr inline void QRect::setWidth(int w) noexcept
0407 { x2 = (x1 + w - 1); }
0408 
0409 constexpr inline void QRect::setHeight(int h) noexcept
0410 { y2 = (y1 + h - 1); }
0411 
0412 constexpr inline void QRect::setSize(const QSize &s) noexcept
0413 {
0414     x2 = (s.width()  + x1 - 1);
0415     y2 = (s.height() + y1 - 1);
0416 }
0417 
0418 inline bool QRect::contains(int ax, int ay, bool aproper) const noexcept
0419 {
0420     return contains(QPoint(ax, ay), aproper);
0421 }
0422 
0423 inline bool QRect::contains(int ax, int ay) const noexcept
0424 {
0425     return contains(QPoint(ax, ay), false);
0426 }
0427 
0428 inline QRect &QRect::operator|=(const QRect &r) noexcept
0429 {
0430     *this = *this | r;
0431     return *this;
0432 }
0433 
0434 inline QRect &QRect::operator&=(const QRect &r) noexcept
0435 {
0436     *this = *this & r;
0437     return *this;
0438 }
0439 
0440 inline QRect QRect::intersected(const QRect &other) const noexcept
0441 {
0442     return *this & other;
0443 }
0444 
0445 inline QRect QRect::united(const QRect &r) const noexcept
0446 {
0447     return *this | r;
0448 }
0449 
0450 constexpr inline size_t qHash(const QRect &r, size_t seed = 0) noexcept
0451 {
0452     return qHashMulti(seed, r.x1, r.x2, r.y1, r.y2);
0453 }
0454 
0455 constexpr inline QRect operator+(const QRect &rectangle, const QMargins &margins) noexcept
0456 {
0457     return QRect(QPoint(rectangle.left() - margins.left(), rectangle.top() - margins.top()),
0458                  QPoint(rectangle.right() + margins.right(), rectangle.bottom() + margins.bottom()));
0459 }
0460 
0461 constexpr inline QRect operator+(const QMargins &margins, const QRect &rectangle) noexcept
0462 {
0463     return QRect(QPoint(rectangle.left() - margins.left(), rectangle.top() - margins.top()),
0464                  QPoint(rectangle.right() + margins.right(), rectangle.bottom() + margins.bottom()));
0465 }
0466 
0467 constexpr inline QRect operator-(const QRect &lhs, const QMargins &rhs) noexcept
0468 {
0469     return QRect(QPoint(lhs.left() + rhs.left(), lhs.top() + rhs.top()),
0470                  QPoint(lhs.right() - rhs.right(), lhs.bottom() - rhs.bottom()));
0471 }
0472 
0473 constexpr inline QRect QRect::marginsAdded(const QMargins &margins) const noexcept
0474 {
0475     return QRect(QPoint(x1 - margins.left(), y1 - margins.top()),
0476                  QPoint(x2 + margins.right(), y2 + margins.bottom()));
0477 }
0478 
0479 constexpr inline QRect QRect::marginsRemoved(const QMargins &margins) const noexcept
0480 {
0481     return QRect(QPoint(x1 + margins.left(), y1 + margins.top()),
0482                  QPoint(x2 - margins.right(), y2 - margins.bottom()));
0483 }
0484 
0485 constexpr inline QRect &QRect::operator+=(const QMargins &margins) noexcept
0486 {
0487     *this = marginsAdded(margins);
0488     return *this;
0489 }
0490 
0491 constexpr inline QRect &QRect::operator-=(const QMargins &margins) noexcept
0492 {
0493     *this = marginsRemoved(margins);
0494     return *this;
0495 }
0496 
0497 constexpr QRect QRect::span(const QPoint &p1, const QPoint &p2) noexcept
0498 {
0499     return QRect(QPoint(qMin(p1.x(), p2.x()), qMin(p1.y(), p2.y())),
0500                  QPoint(qMax(p1.x(), p2.x()), qMax(p1.y(), p2.y())));
0501 }
0502 
0503 #ifndef QT_NO_DEBUG_STREAM
0504 Q_CORE_EXPORT QDebug operator<<(QDebug, const QRect &);
0505 #endif
0506 
0507 
0508 class Q_CORE_EXPORT QRectF
0509 {
0510 public:
0511     constexpr QRectF() noexcept : xp(0.), yp(0.), w(0.), h(0.) {}
0512     constexpr QRectF(const QPointF &topleft, const QSizeF &size) noexcept;
0513     constexpr QRectF(const QPointF &topleft, const QPointF &bottomRight) noexcept;
0514     constexpr QRectF(qreal left, qreal top, qreal width, qreal height) noexcept;
0515     constexpr QRectF(const QRect &rect) noexcept;
0516 
0517     constexpr inline bool isNull() const noexcept;
0518     constexpr inline bool isEmpty() const noexcept;
0519     constexpr inline bool isValid() const noexcept;
0520     [[nodiscard]] QRectF normalized() const noexcept;
0521 
0522     constexpr inline qreal left() const noexcept { return xp; }
0523     constexpr inline qreal top() const noexcept { return yp; }
0524     constexpr inline qreal right() const noexcept { return xp + w; }
0525     constexpr inline qreal bottom() const noexcept { return yp + h; }
0526 
0527     constexpr inline qreal x() const noexcept;
0528     constexpr inline qreal y() const noexcept;
0529     constexpr inline void setLeft(qreal pos) noexcept;
0530     constexpr inline void setTop(qreal pos) noexcept;
0531     constexpr inline void setRight(qreal pos) noexcept;
0532     constexpr inline void setBottom(qreal pos) noexcept;
0533     constexpr inline void setX(qreal pos) noexcept { setLeft(pos); }
0534     constexpr inline void setY(qreal pos) noexcept { setTop(pos); }
0535 
0536     constexpr inline QPointF topLeft() const noexcept { return QPointF(xp, yp); }
0537     constexpr inline QPointF bottomRight() const noexcept { return QPointF(xp+w, yp+h); }
0538     constexpr inline QPointF topRight() const noexcept { return QPointF(xp+w, yp); }
0539     constexpr inline QPointF bottomLeft() const noexcept { return QPointF(xp, yp+h); }
0540     constexpr inline QPointF center() const noexcept;
0541 
0542     constexpr inline void setTopLeft(const QPointF &p) noexcept;
0543     constexpr inline void setBottomRight(const QPointF &p) noexcept;
0544     constexpr inline void setTopRight(const QPointF &p) noexcept;
0545     constexpr inline void setBottomLeft(const QPointF &p) noexcept;
0546 
0547     constexpr inline void moveLeft(qreal pos) noexcept;
0548     constexpr inline void moveTop(qreal pos) noexcept;
0549     constexpr inline void moveRight(qreal pos) noexcept;
0550     constexpr inline void moveBottom(qreal pos) noexcept;
0551     constexpr inline void moveTopLeft(const QPointF &p) noexcept;
0552     constexpr inline void moveBottomRight(const QPointF &p) noexcept;
0553     constexpr inline void moveTopRight(const QPointF &p) noexcept;
0554     constexpr inline void moveBottomLeft(const QPointF &p) noexcept;
0555     constexpr inline void moveCenter(const QPointF &p) noexcept;
0556 
0557     constexpr inline void translate(qreal dx, qreal dy) noexcept;
0558     constexpr inline void translate(const QPointF &p) noexcept;
0559 
0560     [[nodiscard]] constexpr inline QRectF translated(qreal dx, qreal dy) const noexcept;
0561     [[nodiscard]] constexpr inline QRectF translated(const QPointF &p) const noexcept;
0562 
0563     [[nodiscard]] constexpr inline QRectF transposed() const noexcept;
0564 
0565     constexpr inline void moveTo(qreal x, qreal y) noexcept;
0566     constexpr inline void moveTo(const QPointF &p) noexcept;
0567 
0568     constexpr inline void setRect(qreal x, qreal y, qreal w, qreal h) noexcept;
0569     constexpr inline void getRect(qreal *x, qreal *y, qreal *w, qreal *h) const;
0570 
0571     constexpr inline void setCoords(qreal x1, qreal y1, qreal x2, qreal y2) noexcept;
0572     constexpr inline void getCoords(qreal *x1, qreal *y1, qreal *x2, qreal *y2) const;
0573 
0574     constexpr inline void adjust(qreal x1, qreal y1, qreal x2, qreal y2) noexcept;
0575     [[nodiscard]] constexpr inline QRectF adjusted(qreal x1, qreal y1, qreal x2, qreal y2) const noexcept;
0576 
0577     constexpr inline QSizeF size() const noexcept;
0578     constexpr inline qreal width() const noexcept;
0579     constexpr inline qreal height() const noexcept;
0580     constexpr inline void setWidth(qreal w) noexcept;
0581     constexpr inline void setHeight(qreal h) noexcept;
0582     constexpr inline void setSize(const QSizeF &s) noexcept;
0583 
0584     QRectF operator|(const QRectF &r) const noexcept;
0585     QRectF operator&(const QRectF &r) const noexcept;
0586     inline QRectF &operator|=(const QRectF &r) noexcept;
0587     inline QRectF &operator&=(const QRectF &r) noexcept;
0588 
0589     bool contains(const QRectF &r) const noexcept;
0590     bool contains(const QPointF &p) const noexcept;
0591     inline bool contains(qreal x, qreal y) const noexcept;
0592     [[nodiscard]] inline QRectF united(const QRectF &other) const noexcept;
0593     [[nodiscard]] inline QRectF intersected(const QRectF &other) const noexcept;
0594     bool intersects(const QRectF &r) const noexcept;
0595 
0596     constexpr inline QRectF marginsAdded(const QMarginsF &margins) const noexcept;
0597     constexpr inline QRectF marginsRemoved(const QMarginsF &margins) const noexcept;
0598     constexpr inline QRectF &operator+=(const QMarginsF &margins) noexcept;
0599     constexpr inline QRectF &operator-=(const QMarginsF &margins) noexcept;
0600 
0601 private:
0602     friend constexpr bool comparesEqual(const QRectF &r1, const QRectF &r2) noexcept
0603     {
0604         return r1.topLeft() == r2.topLeft()
0605             && r1.size() == r2.size();
0606     }
0607     Q_DECLARE_EQUALITY_COMPARABLE_LITERAL_TYPE(QRectF)
0608 
0609     friend constexpr bool comparesEqual(const QRectF &r1, const QRect &r2) noexcept
0610     { return r1.topLeft() == r2.topLeft() && r1.size() == r2.size(); }
0611     Q_DECLARE_EQUALITY_COMPARABLE_LITERAL_TYPE(QRectF, QRect)
0612 
0613     friend constexpr bool qFuzzyCompare(const QRectF &lhs, const QRectF &rhs) noexcept
0614     {
0615         return qFuzzyCompare(lhs.topLeft(), rhs.topLeft())
0616                 && qFuzzyCompare(lhs.bottomRight(), rhs.bottomRight());
0617     }
0618 
0619     friend constexpr bool qFuzzyIsNull(const QRectF &rect) noexcept
0620     {
0621         return qFuzzyIsNull(rect.w) && qFuzzyIsNull(rect.h);
0622     }
0623 
0624 public:
0625     [[nodiscard]] constexpr inline QRect toRect() const noexcept;
0626     [[nodiscard]] QRect toAlignedRect() const noexcept;
0627 
0628 #if defined(Q_OS_DARWIN) || defined(Q_QDOC)
0629     [[nodiscard]] static QRectF fromCGRect(CGRect rect) noexcept;
0630     [[nodiscard]] CGRect toCGRect() const noexcept;
0631 #endif
0632 
0633 #if defined(Q_OS_WASM) || defined(Q_QDOC)
0634     [[nodiscard]] static QRectF fromDOMRect(emscripten::val domRect);
0635     [[nodiscard]] emscripten::val toDOMRect() const;
0636 #endif
0637 
0638 private:
0639     qreal xp;
0640     qreal yp;
0641     qreal w;
0642     qreal h;
0643 };
0644 Q_DECLARE_TYPEINFO(QRectF, Q_RELOCATABLE_TYPE);
0645 
0646 
0647 /*****************************************************************************
0648   QRectF stream functions
0649  *****************************************************************************/
0650 #ifndef QT_NO_DATASTREAM
0651 Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QRectF &);
0652 Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QRectF &);
0653 #endif
0654 
0655 /*****************************************************************************
0656   QRectF inline member functions
0657  *****************************************************************************/
0658 
0659 constexpr inline QRectF::QRectF(qreal aleft, qreal atop, qreal awidth, qreal aheight) noexcept
0660     : xp(aleft), yp(atop), w(awidth), h(aheight)
0661 {
0662 }
0663 
0664 constexpr inline QRectF::QRectF(const QPointF &atopLeft, const QSizeF &asize) noexcept
0665     : xp(atopLeft.x()), yp(atopLeft.y()), w(asize.width()), h(asize.height())
0666 {
0667 }
0668 
0669 
0670 constexpr inline QRectF::QRectF(const QPointF &atopLeft, const QPointF &abottomRight) noexcept
0671     : xp(atopLeft.x()), yp(atopLeft.y()), w(abottomRight.x() - atopLeft.x()), h(abottomRight.y() - atopLeft.y())
0672 {
0673 }
0674 
0675 constexpr inline QRectF::QRectF(const QRect &r) noexcept
0676     : xp(r.x()),
0677       yp(r.y()),
0678       w(qint64(r.right()) - r.left() + 1),
0679       h(qint64(r.bottom()) - r.top() + 1)
0680 {
0681 }
0682 
0683 QT_WARNING_PUSH
0684 QT_WARNING_DISABLE_FLOAT_COMPARE
0685 
0686 constexpr inline bool QRectF::isNull() const noexcept
0687 { return w == 0. && h == 0.; }
0688 
0689 constexpr inline bool QRectF::isEmpty() const noexcept
0690 { return w <= 0. || h <= 0.; }
0691 
0692 QT_WARNING_POP
0693 
0694 constexpr inline bool QRectF::isValid() const noexcept
0695 { return w > 0. && h > 0.; }
0696 
0697 constexpr inline qreal QRectF::x() const noexcept
0698 { return xp; }
0699 
0700 constexpr inline qreal QRectF::y() const noexcept
0701 { return yp; }
0702 
0703 constexpr inline void QRectF::setLeft(qreal pos) noexcept
0704 { qreal diff = pos - xp; xp += diff; w -= diff; }
0705 
0706 constexpr inline void QRectF::setRight(qreal pos) noexcept
0707 { w = pos - xp; }
0708 
0709 constexpr inline void QRectF::setTop(qreal pos) noexcept
0710 { qreal diff = pos - yp; yp += diff; h -= diff; }
0711 
0712 constexpr inline void QRectF::setBottom(qreal pos) noexcept
0713 { h = pos - yp; }
0714 
0715 constexpr inline void QRectF::setTopLeft(const QPointF &p) noexcept
0716 { setLeft(p.x()); setTop(p.y()); }
0717 
0718 constexpr inline void QRectF::setTopRight(const QPointF &p) noexcept
0719 { setRight(p.x()); setTop(p.y()); }
0720 
0721 constexpr inline void QRectF::setBottomLeft(const QPointF &p) noexcept
0722 { setLeft(p.x()); setBottom(p.y()); }
0723 
0724 constexpr inline void QRectF::setBottomRight(const QPointF &p) noexcept
0725 { setRight(p.x()); setBottom(p.y()); }
0726 
0727 constexpr inline QPointF QRectF::center() const noexcept
0728 { return QPointF(xp + w/2, yp + h/2); }
0729 
0730 constexpr inline void QRectF::moveLeft(qreal pos) noexcept
0731 { xp = pos; }
0732 
0733 constexpr inline void QRectF::moveTop(qreal pos) noexcept
0734 { yp = pos; }
0735 
0736 constexpr inline void QRectF::moveRight(qreal pos) noexcept
0737 { xp = pos - w; }
0738 
0739 constexpr inline void QRectF::moveBottom(qreal pos) noexcept
0740 { yp = pos - h; }
0741 
0742 constexpr inline void QRectF::moveTopLeft(const QPointF &p) noexcept
0743 { moveLeft(p.x()); moveTop(p.y()); }
0744 
0745 constexpr inline void QRectF::moveTopRight(const QPointF &p) noexcept
0746 { moveRight(p.x()); moveTop(p.y()); }
0747 
0748 constexpr inline void QRectF::moveBottomLeft(const QPointF &p) noexcept
0749 { moveLeft(p.x()); moveBottom(p.y()); }
0750 
0751 constexpr inline void QRectF::moveBottomRight(const QPointF &p) noexcept
0752 { moveRight(p.x()); moveBottom(p.y()); }
0753 
0754 constexpr inline void QRectF::moveCenter(const QPointF &p) noexcept
0755 { xp = p.x() - w/2; yp = p.y() - h/2; }
0756 
0757 constexpr inline qreal QRectF::width() const noexcept
0758 { return w; }
0759 
0760 constexpr inline qreal QRectF::height() const noexcept
0761 { return h; }
0762 
0763 constexpr inline QSizeF QRectF::size() const noexcept
0764 { return QSizeF(w, h); }
0765 
0766 constexpr inline void QRectF::translate(qreal dx, qreal dy) noexcept
0767 {
0768     xp += dx;
0769     yp += dy;
0770 }
0771 
0772 constexpr inline void QRectF::translate(const QPointF &p) noexcept
0773 {
0774     xp += p.x();
0775     yp += p.y();
0776 }
0777 
0778 constexpr inline void QRectF::moveTo(qreal ax, qreal ay) noexcept
0779 {
0780     xp = ax;
0781     yp = ay;
0782 }
0783 
0784 constexpr inline void QRectF::moveTo(const QPointF &p) noexcept
0785 {
0786     xp = p.x();
0787     yp = p.y();
0788 }
0789 
0790 constexpr inline QRectF QRectF::translated(qreal dx, qreal dy) const noexcept
0791 {
0792     return QRectF(xp + dx, yp + dy, w, h);
0793 }
0794 
0795 constexpr inline QRectF QRectF::translated(const QPointF &p) const noexcept
0796 { return QRectF(xp + p.x(), yp + p.y(), w, h); }
0797 
0798 constexpr inline QRectF QRectF::transposed() const noexcept
0799 { return QRectF(topLeft(), size().transposed()); }
0800 
0801 constexpr inline void QRectF::getRect(qreal *ax, qreal *ay, qreal *aaw, qreal *aah) const
0802 {
0803     *ax = this->xp;
0804     *ay = this->yp;
0805     *aaw = this->w;
0806     *aah = this->h;
0807 }
0808 
0809 constexpr inline void QRectF::setRect(qreal ax, qreal ay, qreal aaw, qreal aah) noexcept
0810 {
0811     this->xp = ax;
0812     this->yp = ay;
0813     this->w = aaw;
0814     this->h = aah;
0815 }
0816 
0817 constexpr inline void QRectF::getCoords(qreal *xp1, qreal *yp1, qreal *xp2, qreal *yp2) const
0818 {
0819     *xp1 = xp;
0820     *yp1 = yp;
0821     *xp2 = xp + w;
0822     *yp2 = yp + h;
0823 }
0824 
0825 constexpr inline void QRectF::setCoords(qreal xp1, qreal yp1, qreal xp2, qreal yp2) noexcept
0826 {
0827     xp = xp1;
0828     yp = yp1;
0829     w = xp2 - xp1;
0830     h = yp2 - yp1;
0831 }
0832 
0833 constexpr inline void QRectF::adjust(qreal xp1, qreal yp1, qreal xp2, qreal yp2) noexcept
0834 {
0835     xp += xp1;
0836     yp += yp1;
0837     w += xp2 - xp1;
0838     h += yp2 - yp1;
0839 }
0840 
0841 constexpr inline QRectF QRectF::adjusted(qreal xp1, qreal yp1, qreal xp2, qreal yp2) const noexcept
0842 {
0843     return QRectF(xp + xp1, yp + yp1, w + xp2 - xp1, h + yp2 - yp1);
0844 }
0845 
0846 constexpr inline void QRectF::setWidth(qreal aw) noexcept
0847 { this->w = aw; }
0848 
0849 constexpr inline void QRectF::setHeight(qreal ah) noexcept
0850 { this->h = ah; }
0851 
0852 constexpr inline void QRectF::setSize(const QSizeF &s) noexcept
0853 {
0854     w = s.width();
0855     h = s.height();
0856 }
0857 
0858 inline bool QRectF::contains(qreal ax, qreal ay) const noexcept
0859 {
0860     return contains(QPointF(ax, ay));
0861 }
0862 
0863 inline QRectF &QRectF::operator|=(const QRectF &r) noexcept
0864 {
0865     *this = *this | r;
0866     return *this;
0867 }
0868 
0869 inline QRectF &QRectF::operator&=(const QRectF &r) noexcept
0870 {
0871     *this = *this & r;
0872     return *this;
0873 }
0874 
0875 inline QRectF QRectF::intersected(const QRectF &r) const noexcept
0876 {
0877     return *this & r;
0878 }
0879 
0880 inline QRectF QRectF::united(const QRectF &r) const noexcept
0881 {
0882     return *this | r;
0883 }
0884 
0885 constexpr QRectF QRect::toRectF() const noexcept { return *this; }
0886 
0887 constexpr inline QRect QRectF::toRect() const noexcept
0888 {
0889     // This rounding is designed to minimize the maximum possible difference
0890     // in topLeft(), bottomRight(), and size() after rounding.
0891     // All dimensions are at most off by 0.75, and topLeft by at most 0.5.
0892     const int nxp = QtPrivate::qSaturateRound(xp);
0893     const int nyp = QtPrivate::qSaturateRound(yp);
0894     const int nw = QtPrivate::qSaturateRound(w + (xp - nxp) / 2);
0895     const int nh = QtPrivate::qSaturateRound(h + (yp - nyp) / 2);
0896     return QRect(nxp, nyp, nw, nh);
0897 }
0898 
0899 constexpr inline QRectF operator+(const QRectF &lhs, const QMarginsF &rhs) noexcept
0900 {
0901     return QRectF(QPointF(lhs.left() - rhs.left(), lhs.top() - rhs.top()),
0902                   QSizeF(lhs.width() + rhs.left() + rhs.right(), lhs.height() + rhs.top() + rhs.bottom()));
0903 }
0904 
0905 constexpr inline QRectF operator+(const QMarginsF &lhs, const QRectF &rhs) noexcept
0906 {
0907     return QRectF(QPointF(rhs.left() - lhs.left(), rhs.top() - lhs.top()),
0908                   QSizeF(rhs.width() + lhs.left() + lhs.right(), rhs.height() + lhs.top() + lhs.bottom()));
0909 }
0910 
0911 constexpr inline QRectF operator-(const QRectF &lhs, const QMarginsF &rhs) noexcept
0912 {
0913     return QRectF(QPointF(lhs.left() + rhs.left(), lhs.top() + rhs.top()),
0914                   QSizeF(lhs.width() - rhs.left() - rhs.right(), lhs.height() - rhs.top() - rhs.bottom()));
0915 }
0916 
0917 constexpr inline QRectF QRectF::marginsAdded(const QMarginsF &margins) const noexcept
0918 {
0919     return QRectF(QPointF(xp - margins.left(), yp - margins.top()),
0920                   QSizeF(w + margins.left() + margins.right(), h + margins.top() + margins.bottom()));
0921 }
0922 
0923 constexpr inline QRectF QRectF::marginsRemoved(const QMarginsF &margins) const noexcept
0924 {
0925     return QRectF(QPointF(xp + margins.left(), yp + margins.top()),
0926                   QSizeF(w - margins.left() - margins.right(), h - margins.top() - margins.bottom()));
0927 }
0928 
0929 constexpr inline QRectF &QRectF::operator+=(const QMarginsF &margins) noexcept
0930 {
0931     *this = marginsAdded(margins);
0932     return *this;
0933 }
0934 
0935 constexpr inline QRectF &QRectF::operator-=(const QMarginsF &margins) noexcept
0936 {
0937     *this = marginsRemoved(margins);
0938     return *this;
0939 }
0940 
0941 #ifndef QT_NO_DEBUG_STREAM
0942 Q_CORE_EXPORT QDebug operator<<(QDebug, const QRectF &);
0943 #endif
0944 
0945 QT_END_NAMESPACE
0946 
0947 #endif // QRECT_H