QtBase  v6.3.1
qmath_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39 
40 #ifndef QMATH_P_H
41 #define QMATH_P_H
42 
43 //
44 // W A R N I N G
45 // -------------
46 //
47 // This file is not part of the Qt API. It exists purely as an
48 // implementation detail. This header file may change from version to
49 // version without notice, or even be removed.
50 //
51 // We mean it.
52 //
53 
54 #include <qmath.h>
55 #include <qtransform.h>
56 
58 
59 static const qreal Q_PI = qreal(M_PI); // pi
60 static const qreal Q_MM_PER_INCH = 25.4;
61 
62 inline QRect qt_mapFillRect(const QRectF &rect, const QTransform &xf)
63 {
64  // Only for xf <= scaling or 90 degree rotations
66  || (xf.type() == QTransform::TxRotate && qFuzzyIsNull(xf.m11()) && qFuzzyIsNull(xf.m22())));
67  // Transform the corners instead of the rect to avoid hitting numerical accuracy limit
68  // when transforming topleft and size separately and adding afterwards,
69  // as that can sometimes be slightly off around the .5 point, leading to wrong rounding
70  QPoint pt1 = xf.map(rect.topLeft()).toPoint();
71  QPoint pt2 = xf.map(rect.bottomRight()).toPoint();
72  // Normalize and adjust for the QRect vs. QRectF bottomright
73  return QRect::span(pt1, pt2).adjusted(0, 0, -1, -1);
74 }
75 
77 
78 #endif // QMATH_P_H
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:52
The QRectF class defines a finite rectangle in the plane using floating point precision.
Definition: qrect.h:511
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:59
constexpr QRect adjusted(int x1, int y1, int x2, int y2) const noexcept
Definition: qrect.h:397
static constexpr QRect span(const QPoint &p1, const QPoint &p2) noexcept
Definition: qrect.h:499
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:56
QPoint map(const QPoint &p) const
qreal m11() const
Definition: qtransform.h:226
TransformationType type() const
qreal m22() const
Definition: qtransform.h:242
rect
[4]
#define M_PI
Definition: easing.cpp:23
bool qFuzzyIsNull(qfloat16 f) noexcept
Definition: qfloat16.h:249
QT_END_INCLUDE_NAMESPACE typedef double qreal
Definition: qglobal.h:341
QRect qt_mapFillRect(const QRectF &rect, const QTransform &xf)
Definition: qmath_p.h:62
#define Q_ASSERT(cond)
Definition: qrandom.cpp:84