1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef QMATH_P_H |
5 | #define QMATH_P_H |
6 | |
7 | // |
8 | // W A R N I N G |
9 | // ------------- |
10 | // |
11 | // This file is not part of the Qt API. It exists purely as an |
12 | // implementation detail. This header file may change from version to |
13 | // version without notice, or even be removed. |
14 | // |
15 | // We mean it. |
16 | // |
17 | |
18 | #include <qmath.h> |
19 | #include <private/qglobal_p.h> |
20 | #include <qtransform.h> |
21 | |
22 | QT_BEGIN_NAMESPACE |
23 | |
24 | static const qreal Q_PI = qreal(M_PI); // pi |
25 | static const qreal Q_MM_PER_INCH = 25.4; |
26 | |
27 | inline QRect qt_mapFillRect(const QRectF &rect, const QTransform &xf) |
28 | { |
29 | // Only for xf <= scaling or 90 degree rotations |
30 | Q_ASSERT(xf.type() <= QTransform::TxScale |
31 | || (xf.type() == QTransform::TxRotate && qFuzzyIsNull(xf.m11()) && qFuzzyIsNull(xf.m22()))); |
32 | // Transform the corners instead of the rect to avoid hitting numerical accuracy limit |
33 | // when transforming topleft and size separately and adding afterwards, |
34 | // as that can sometimes be slightly off around the .5 point, leading to wrong rounding |
35 | QPoint pt1 = xf.map(p: rect.topLeft()).toPoint(); |
36 | QPoint pt2 = xf.map(p: rect.bottomRight()).toPoint(); |
37 | // Normalize and adjust for the QRect vs. QRectF bottomright |
38 | return QRect::span(p1: pt1, p2: pt2).adjusted(xp1: 0, yp1: 0, xp2: -1, yp2: -1); |
39 | } |
40 | |
41 | QT_END_NAMESPACE |
42 | |
43 | #endif // QMATH_P_H |
44 | |