source: trunk/src/corelib/tools/qpoint.h

Last change on this file was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 9.2 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the QtCore module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#ifndef QPOINT_H
43#define QPOINT_H
44
45#include <QtCore/qnamespace.h>
46
47QT_BEGIN_HEADER
48
49QT_BEGIN_NAMESPACE
50
51QT_MODULE(Core)
52
53class Q_CORE_EXPORT QPoint
54{
55public:
56 QPoint();
57 QPoint(int xpos, int ypos);
58
59 bool isNull() const;
60
61 int x() const;
62 int y() const;
63 void setX(int x);
64 void setY(int y);
65
66 int manhattanLength() const;
67
68 int &rx();
69 int &ry();
70
71 QPoint &operator+=(const QPoint &p);
72 QPoint &operator-=(const QPoint &p);
73 QPoint &operator*=(qreal c);
74 QPoint &operator/=(qreal c);
75
76 friend inline bool operator==(const QPoint &, const QPoint &);
77 friend inline bool operator!=(const QPoint &, const QPoint &);
78 friend inline const QPoint operator+(const QPoint &, const QPoint &);
79 friend inline const QPoint operator-(const QPoint &, const QPoint &);
80 friend inline const QPoint operator*(const QPoint &, qreal);
81 friend inline const QPoint operator*(qreal, const QPoint &);
82 friend inline const QPoint operator-(const QPoint &);
83 friend inline const QPoint operator/(const QPoint &, qreal);
84
85private:
86 friend class QTransform;
87 // ### Qt 5; remove the ifdef and just have the same order on all platforms.
88#if defined(Q_OS_MAC)
89 int yp;
90 int xp;
91#else
92 int xp;
93 int yp;
94#endif
95};
96
97Q_DECLARE_TYPEINFO(QPoint, Q_MOVABLE_TYPE);
98
99/*****************************************************************************
100 QPoint stream functions
101 *****************************************************************************/
102#ifndef QT_NO_DATASTREAM
103Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QPoint &);
104Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QPoint &);
105#endif
106
107/*****************************************************************************
108 QPoint inline functions
109 *****************************************************************************/
110
111inline QPoint::QPoint()
112{ xp=0; yp=0; }
113
114inline QPoint::QPoint(int xpos, int ypos)
115{ xp = xpos; yp = ypos; }
116
117inline bool QPoint::isNull() const
118{ return xp == 0 && yp == 0; }
119
120inline int QPoint::x() const
121{ return xp; }
122
123inline int QPoint::y() const
124{ return yp; }
125
126inline void QPoint::setX(int xpos)
127{ xp = xpos; }
128
129inline void QPoint::setY(int ypos)
130{ yp = ypos; }
131
132inline int &QPoint::rx()
133{ return xp; }
134
135inline int &QPoint::ry()
136{ return yp; }
137
138inline QPoint &QPoint::operator+=(const QPoint &p)
139{ xp+=p.xp; yp+=p.yp; return *this; }
140
141inline QPoint &QPoint::operator-=(const QPoint &p)
142{ xp-=p.xp; yp-=p.yp; return *this; }
143
144inline QPoint &QPoint::operator*=(qreal c)
145{ xp = qRound(xp*c); yp = qRound(yp*c); return *this; }
146
147inline bool operator==(const QPoint &p1, const QPoint &p2)
148{ return p1.xp == p2.xp && p1.yp == p2.yp; }
149
150inline bool operator!=(const QPoint &p1, const QPoint &p2)
151{ return p1.xp != p2.xp || p1.yp != p2.yp; }
152
153inline const QPoint operator+(const QPoint &p1, const QPoint &p2)
154{ return QPoint(p1.xp+p2.xp, p1.yp+p2.yp); }
155
156inline const QPoint operator-(const QPoint &p1, const QPoint &p2)
157{ return QPoint(p1.xp-p2.xp, p1.yp-p2.yp); }
158
159inline const QPoint operator*(const QPoint &p, qreal c)
160{ return QPoint(qRound(p.xp*c), qRound(p.yp*c)); }
161
162inline const QPoint operator*(qreal c, const QPoint &p)
163{ return QPoint(qRound(p.xp*c), qRound(p.yp*c)); }
164
165inline const QPoint operator-(const QPoint &p)
166{ return QPoint(-p.xp, -p.yp); }
167
168inline QPoint &QPoint::operator/=(qreal c)
169{
170 xp = qRound(xp/c);
171 yp = qRound(yp/c);
172 return *this;
173}
174
175inline const QPoint operator/(const QPoint &p, qreal c)
176{
177 return QPoint(qRound(p.xp/c), qRound(p.yp/c));
178}
179
180#ifndef QT_NO_DEBUG_STREAM
181Q_CORE_EXPORT QDebug operator<<(QDebug, const QPoint &);
182#endif
183
184
185
186
187
188class Q_CORE_EXPORT QPointF
189{
190public:
191 QPointF();
192 QPointF(const QPoint &p);
193 QPointF(qreal xpos, qreal ypos);
194
195 qreal manhattanLength() const;
196
197 bool isNull() const;
198
199 qreal x() const;
200 qreal y() const;
201 void setX(qreal x);
202 void setY(qreal y);
203
204 qreal &rx();
205 qreal &ry();
206
207 QPointF &operator+=(const QPointF &p);
208 QPointF &operator-=(const QPointF &p);
209 QPointF &operator*=(qreal c);
210 QPointF &operator/=(qreal c);
211
212 friend inline bool operator==(const QPointF &, const QPointF &);
213 friend inline bool operator!=(const QPointF &, const QPointF &);
214 friend inline const QPointF operator+(const QPointF &, const QPointF &);
215 friend inline const QPointF operator-(const QPointF &, const QPointF &);
216 friend inline const QPointF operator*(qreal, const QPointF &);
217 friend inline const QPointF operator*(const QPointF &, qreal);
218 friend inline const QPointF operator-(const QPointF &);
219 friend inline const QPointF operator/(const QPointF &, qreal);
220
221 QPoint toPoint() const;
222
223private:
224 friend class QMatrix;
225 friend class QTransform;
226
227 qreal xp;
228 qreal yp;
229};
230
231Q_DECLARE_TYPEINFO(QPointF, Q_MOVABLE_TYPE);
232
233/*****************************************************************************
234 QPointF stream functions
235 *****************************************************************************/
236#ifndef QT_NO_DATASTREAM
237Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QPointF &);
238Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QPointF &);
239#endif
240
241/*****************************************************************************
242 QPointF inline functions
243 *****************************************************************************/
244
245inline QPointF::QPointF() : xp(0), yp(0) { }
246
247inline QPointF::QPointF(qreal xpos, qreal ypos) : xp(xpos), yp(ypos) { }
248
249inline QPointF::QPointF(const QPoint &p) : xp(p.x()), yp(p.y()) { }
250
251inline bool QPointF::isNull() const
252{
253 return qIsNull(xp) && qIsNull(yp);
254}
255
256inline qreal QPointF::x() const
257{
258 return xp;
259}
260
261inline qreal QPointF::y() const
262{
263 return yp;
264}
265
266inline void QPointF::setX(qreal xpos)
267{
268 xp = xpos;
269}
270
271inline void QPointF::setY(qreal ypos)
272{
273 yp = ypos;
274}
275
276inline qreal &QPointF::rx()
277{
278 return xp;
279}
280
281inline qreal &QPointF::ry()
282{
283 return yp;
284}
285
286inline QPointF &QPointF::operator+=(const QPointF &p)
287{
288 xp+=p.xp;
289 yp+=p.yp;
290 return *this;
291}
292
293inline QPointF &QPointF::operator-=(const QPointF &p)
294{
295 xp-=p.xp; yp-=p.yp; return *this;
296}
297
298inline QPointF &QPointF::operator*=(qreal c)
299{
300 xp*=c; yp*=c; return *this;
301}
302
303inline bool operator==(const QPointF &p1, const QPointF &p2)
304{
305 return qFuzzyIsNull(p1.xp - p2.xp) && qFuzzyIsNull(p1.yp - p2.yp);
306}
307
308inline bool operator!=(const QPointF &p1, const QPointF &p2)
309{
310 return !qFuzzyIsNull(p1.xp - p2.xp) || !qFuzzyIsNull(p1.yp - p2.yp);
311}
312
313inline const QPointF operator+(const QPointF &p1, const QPointF &p2)
314{
315 return QPointF(p1.xp+p2.xp, p1.yp+p2.yp);
316}
317
318inline const QPointF operator-(const QPointF &p1, const QPointF &p2)
319{
320 return QPointF(p1.xp-p2.xp, p1.yp-p2.yp);
321}
322
323inline const QPointF operator*(const QPointF &p, qreal c)
324{
325 return QPointF(p.xp*c, p.yp*c);
326}
327
328inline const QPointF operator*(qreal c, const QPointF &p)
329{
330 return QPointF(p.xp*c, p.yp*c);
331}
332
333inline const QPointF operator-(const QPointF &p)
334{
335 return QPointF(-p.xp, -p.yp);
336}
337
338inline QPointF &QPointF::operator/=(qreal c)
339{
340 xp/=c;
341 yp/=c;
342 return *this;
343}
344
345inline const QPointF operator/(const QPointF &p, qreal c)
346{
347 return QPointF(p.xp/c, p.yp/c);
348}
349
350inline QPoint QPointF::toPoint() const
351{
352 return QPoint(qRound(xp), qRound(yp));
353}
354
355#ifndef QT_NO_DEBUG_STREAM
356Q_CORE_EXPORT QDebug operator<<(QDebug d, const QPointF &p);
357#endif
358
359QT_END_NAMESPACE
360
361QT_END_HEADER
362
363#endif // QPOINT_H
Note: See TracBrowser for help on using the repository browser.