Qt 4.8
qpoint.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtCore 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 Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QPOINT_H
43 #define QPOINT_H
44 
45 #include <QtCore/qnamespace.h>
46 
48 
50 
51 QT_MODULE(Core)
52 
54 {
55 public:
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 
74  QPoint &operator*=(float c);
75  QPoint &operator*=(double c);
76  QPoint &operator*=(int c);
77 
78  QPoint &operator/=(qreal c);
79 
80  friend inline bool operator==(const QPoint &, const QPoint &);
81  friend inline bool operator!=(const QPoint &, const QPoint &);
82  friend inline const QPoint operator+(const QPoint &, const QPoint &);
83  friend inline const QPoint operator-(const QPoint &, const QPoint &);
84  friend inline const QPoint operator*(const QPoint &, float);
85  friend inline const QPoint operator*(float, const QPoint &);
86  friend inline const QPoint operator*(const QPoint &, double);
87  friend inline const QPoint operator*(double, const QPoint &);
88  friend inline const QPoint operator*(const QPoint &, int);
89  friend inline const QPoint operator*(int, const QPoint &);
90  friend inline const QPoint operator-(const QPoint &);
91  friend inline const QPoint operator/(const QPoint &, qreal);
92 
93 private:
94  friend class QTransform;
95  // ### Qt 5; remove the ifdef and just have the same order on all platforms.
96 #if defined(Q_OS_MAC) && !defined(Q_OS_IOS)
97  int yp;
98  int xp;
99 #else
100  int xp;
101  int yp;
102 #endif
103 };
104 
106 
107 /*****************************************************************************
108  QPoint stream functions
109  *****************************************************************************/
110 #ifndef QT_NO_DATASTREAM
113 #endif
114 
115 /*****************************************************************************
116  QPoint inline functions
117  *****************************************************************************/
118 
120 { xp=0; yp=0; }
121 
122 inline QPoint::QPoint(int xpos, int ypos)
123 { xp = xpos; yp = ypos; }
124 
125 inline bool QPoint::isNull() const
126 { return xp == 0 && yp == 0; }
127 
128 inline int QPoint::x() const
129 { return xp; }
130 
131 inline int QPoint::y() const
132 { return yp; }
133 
134 inline void QPoint::setX(int xpos)
135 { xp = xpos; }
136 
137 inline void QPoint::setY(int ypos)
138 { yp = ypos; }
139 
140 inline int &QPoint::rx()
141 { return xp; }
142 
143 inline int &QPoint::ry()
144 { return yp; }
145 
147 { xp+=p.xp; yp+=p.yp; return *this; }
148 
150 { xp-=p.xp; yp-=p.yp; return *this; }
151 
153 { xp = qRound(xp*c); yp = qRound(yp*c); return *this; }
154 
155 inline QPoint &QPoint::operator*=(double c)
156 { xp = qRound(xp*c); yp = qRound(yp*c); return *this; }
157 
159 { xp = xp*c; yp = yp*c; return *this; }
160 
161 inline bool operator==(const QPoint &p1, const QPoint &p2)
162 { return p1.xp == p2.xp && p1.yp == p2.yp; }
163 
164 inline bool operator!=(const QPoint &p1, const QPoint &p2)
165 { return p1.xp != p2.xp || p1.yp != p2.yp; }
166 
167 inline const QPoint operator+(const QPoint &p1, const QPoint &p2)
168 { return QPoint(p1.xp+p2.xp, p1.yp+p2.yp); }
169 
170 inline const QPoint operator-(const QPoint &p1, const QPoint &p2)
171 { return QPoint(p1.xp-p2.xp, p1.yp-p2.yp); }
172 
173 inline const QPoint operator*(const QPoint &p, float c)
174 { return QPoint(qRound(p.xp*c), qRound(p.yp*c)); }
175 
176 inline const QPoint operator*(const QPoint &p, double c)
177 { return QPoint(qRound(p.xp*c), qRound(p.yp*c)); }
178 
179 inline const QPoint operator*(const QPoint &p, int c)
180 { return QPoint(p.xp*c, p.yp*c); }
181 
182 inline const QPoint operator*(float c, const QPoint &p)
183 { return QPoint(qRound(p.xp*c), qRound(p.yp*c)); }
184 
185 inline const QPoint operator*(double c, const QPoint &p)
186 { return QPoint(qRound(p.xp*c), qRound(p.yp*c)); }
187 
188 inline const QPoint operator*(int c, const QPoint &p)
189 { return QPoint(p.xp*c, p.yp*c); }
190 
191 inline const QPoint operator-(const QPoint &p)
192 { return QPoint(-p.xp, -p.yp); }
193 
195 {
196  xp = qRound(xp/c);
197  yp = qRound(yp/c);
198  return *this;
199 }
200 
201 inline const QPoint operator/(const QPoint &p, qreal c)
202 {
203  return QPoint(qRound(p.xp/c), qRound(p.yp/c));
204 }
205 
206 #ifndef QT_NO_DEBUG_STREAM
208 #endif
209 
210 
211 
212 
213 
215 {
216 public:
217  QPointF();
218  QPointF(const QPoint &p);
219  QPointF(qreal xpos, qreal ypos);
220 
221  qreal manhattanLength() const;
222 
223  bool isNull() const;
224 
225  qreal x() const;
226  qreal y() const;
227  void setX(qreal x);
228  void setY(qreal y);
229 
230  qreal &rx();
231  qreal &ry();
232 
233  QPointF &operator+=(const QPointF &p);
234  QPointF &operator-=(const QPointF &p);
237 
238  friend inline bool operator==(const QPointF &, const QPointF &);
239  friend inline bool operator!=(const QPointF &, const QPointF &);
240  friend inline const QPointF operator+(const QPointF &, const QPointF &);
241  friend inline const QPointF operator-(const QPointF &, const QPointF &);
242  friend inline const QPointF operator*(qreal, const QPointF &);
243  friend inline const QPointF operator*(const QPointF &, qreal);
244  friend inline const QPointF operator-(const QPointF &);
245  friend inline const QPointF operator/(const QPointF &, qreal);
246 
247  QPoint toPoint() const;
248 
249 private:
250  friend class QMatrix;
251  friend class QTransform;
252 
255 };
256 
258 
259 /*****************************************************************************
260  QPointF stream functions
261  *****************************************************************************/
262 #ifndef QT_NO_DATASTREAM
265 #endif
266 
267 /*****************************************************************************
268  QPointF inline functions
269  *****************************************************************************/
270 
271 inline QPointF::QPointF() : xp(0), yp(0) { }
272 
273 inline QPointF::QPointF(qreal xpos, qreal ypos) : xp(xpos), yp(ypos) { }
274 
275 inline QPointF::QPointF(const QPoint &p) : xp(p.x()), yp(p.y()) { }
276 
277 inline bool QPointF::isNull() const
278 {
279  return qIsNull(xp) && qIsNull(yp);
280 }
281 
282 inline qreal QPointF::x() const
283 {
284  return xp;
285 }
286 
287 inline qreal QPointF::y() const
288 {
289  return yp;
290 }
291 
292 inline void QPointF::setX(qreal xpos)
293 {
294  xp = xpos;
295 }
296 
297 inline void QPointF::setY(qreal ypos)
298 {
299  yp = ypos;
300 }
301 
303 {
304  return xp;
305 }
306 
308 {
309  return yp;
310 }
311 
313 {
314  xp+=p.xp;
315  yp+=p.yp;
316  return *this;
317 }
318 
320 {
321  xp-=p.xp; yp-=p.yp; return *this;
322 }
323 
325 {
326  xp*=c; yp*=c; return *this;
327 }
328 
329 inline bool operator==(const QPointF &p1, const QPointF &p2)
330 {
331  return qFuzzyIsNull(p1.xp - p2.xp) && qFuzzyIsNull(p1.yp - p2.yp);
332 }
333 
334 inline bool operator!=(const QPointF &p1, const QPointF &p2)
335 {
336  return !qFuzzyIsNull(p1.xp - p2.xp) || !qFuzzyIsNull(p1.yp - p2.yp);
337 }
338 
339 inline const QPointF operator+(const QPointF &p1, const QPointF &p2)
340 {
341  return QPointF(p1.xp+p2.xp, p1.yp+p2.yp);
342 }
343 
344 inline const QPointF operator-(const QPointF &p1, const QPointF &p2)
345 {
346  return QPointF(p1.xp-p2.xp, p1.yp-p2.yp);
347 }
348 
349 inline const QPointF operator*(const QPointF &p, qreal c)
350 {
351  return QPointF(p.xp*c, p.yp*c);
352 }
353 
354 inline const QPointF operator*(qreal c, const QPointF &p)
355 {
356  return QPointF(p.xp*c, p.yp*c);
357 }
358 
359 inline const QPointF operator-(const QPointF &p)
360 {
361  return QPointF(-p.xp, -p.yp);
362 }
363 
365 {
366  xp/=c;
367  yp/=c;
368  return *this;
369 }
370 
371 inline const QPointF operator/(const QPointF &p, qreal c)
372 {
373  return QPointF(p.xp/c, p.yp/c);
374 }
375 
376 inline QPoint QPointF::toPoint() const
377 {
378  return QPoint(qRound(xp), qRound(yp));
379 }
380 
381 #ifndef QT_NO_DEBUG_STREAM
383 #endif
384 
386 
388 
389 #endif // QPOINT_H
The QDebug class provides an output stream for debugging information.
Definition: qdebug.h:62
double d
Definition: qnumeric_p.h:62
QPoint & operator*=(float c)
Definition: qpoint.h:152
QPointF & operator+=(const QPointF &p)
Adds the given point to this point and returns a reference to this point.
Definition: qpoint.h:312
double qreal
Definition: qglobal.h:1193
unsigned char c[8]
Definition: qnumeric_p.h:62
QPointF & operator/=(qreal c)
Divides both x and y by the given divisor, and returns a reference to this point. ...
Definition: qpoint.h:364
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
#define QT_MODULE(x)
Definition: qglobal.h:2783
friend const QPoint operator*(const QPoint &, float)
Definition: qpoint.h:173
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
The QMatrix class specifies 2D transformations of a coordinate system.
Definition: qmatrix.h:61
friend const QPointF operator*(qreal, const QPointF &)
Definition: qpoint.h:354
void setY(qreal y)
Sets the y coordinate of this point to the given y coordinate.
Definition: qpoint.h:297
friend const QPointF operator-(const QPointF &, const QPointF &)
Returns a QPointF object that is formed by subtracting p2 from p1; each component is subtracted separ...
Definition: qpoint.h:344
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
QDataStream & operator<<(QDataStream &stream, const QPointF &point)
Writes the given point to the given stream and returns a reference to the stream. ...
Definition: qpoint.cpp:849
friend const QPoint operator-(const QPoint &, const QPoint &)
Returns a QPoint object that is formed by subtracting p2 from p1; each component is subtracted separa...
Definition: qpoint.h:170
int & ry()
Returns a reference to the y coordinate of this point.
Definition: qpoint.h:143
friend const QPoint operator/(const QPoint &, qreal)
Returns the QPoint formed by dividing both components of the given point by the given divisor...
Definition: qpoint.h:201
friend bool operator!=(const QPointF &, const QPointF &)
Returns true if p1 is not equal to p2; otherwise returns false.
Definition: qpoint.h:334
static bool qIsNull(double d)
Definition: qglobal.h:2061
friend const QPoint operator+(const QPoint &, const QPoint &)
Returns a QPoint object that is the sum of the given points, p1 and p2; each component is added separ...
Definition: qpoint.h:167
QPoint()
Constructs a null point, i.
Definition: qpoint.h:119
const QByteArray operator+(const QByteArray &a1, const QByteArray &a2)
Returns a byte array that is the result of concatenating byte array a1 and byte array a2...
Definition: qbytearray.h:564
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
QDataStream & operator<<(QDataStream &stream, const QPoint &point)
Writes the given point to the given stream and returns a reference to the stream. ...
Definition: qpoint.cpp:435
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
qreal & rx()
Returns a reference to the x coordinate of this point.
Definition: qpoint.h:302
qreal xp
Definition: qpoint.h:253
int manhattanLength() const
Returns the sum of the absolute values of x() and y(), traditionally known as the "Manhattan length" ...
Definition: qpoint.cpp:489
qreal yp
Definition: qpoint.h:254
bool isNull() const
Returns true if both the x and y coordinates are set to 0, otherwise returns false.
Definition: qpoint.h:125
int & rx()
Returns a reference to the x coordinate of this point.
Definition: qpoint.h:140
friend const QPointF operator+(const QPointF &, const QPointF &)
Returns a QPointF object that is the sum of the given points, p1 and p2; each component is added sepa...
Definition: qpoint.h:339
QPointF & operator-=(const QPointF &p)
Subtracts the given point from this point and returns a reference to this point.
Definition: qpoint.h:319
QDataStream & operator>>(QDataStream &stream, QPoint &point)
Reads a point from the given stream into the given point and returns a reference to the stream...
Definition: qpoint.cpp:457
int xp
Definition: qpoint.h:98
bool operator!=(const T *o, const QPointer< T > &p)
Definition: qpointer.h:122
QPointF()
Constructs a null point, i.
Definition: qpoint.h:271
void setY(int y)
Sets the y coordinate of this point to the given y coordinate.
Definition: qpoint.h:137
#define Q_CORE_EXPORT
Definition: qglobal.h:1449
QPointF & operator*=(qreal c)
Multiplies this point&#39;s coordinates by the given factor, and returns a reference to this point...
Definition: qpoint.h:324
QPoint toPoint() const
Rounds the coordinates of this point to the nearest integer, and returns a QPoint object with the rou...
Definition: qpoint.h:376
QPoint & operator-=(const QPoint &p)
Subtracts the given point from this point and returns a reference to this point.
Definition: qpoint.h:149
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
QGenericMatrix< N, M, T > operator/(const QGenericMatrix< N, M, T > &matrix, T divisor)
Returns the result of dividing all elements of matrix by divisor.
friend bool operator!=(const QPoint &, const QPoint &)
Returns true if p1 and p2 are not equal; otherwise returns false.
Definition: qpoint.h:164
bool isNull() const
Returns true if both the x and y coordinates are set to +0.
Definition: qpoint.h:277
friend bool operator==(const QPoint &, const QPoint &)
Returns true if p1 and p2 are equal; otherwise returns false.
Definition: qpoint.h:161
bool operator==(const T *o, const QPointer< T > &p)
Definition: qpointer.h:87
qreal & ry()
Returns a reference to the y coordinate of this point.
Definition: qpoint.h:307
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
void setX(qreal x)
Sets the x coordinate of this point to the given x coordinate.
Definition: qpoint.h:292
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
static Q_DECL_CONSTEXPR bool qFuzzyIsNull(double d)
Definition: qglobal.h:2043
QGenericMatrix< M1, M2, T > operator*(const QGenericMatrix< N, M2, T > &m1, const QGenericMatrix< M1, N, T > &m2)
QPoint & operator+=(const QPoint &p)
Adds the given point to this point and returns a reference to this point.
Definition: qpoint.h:146
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:71
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
friend const QPointF operator/(const QPointF &, qreal)
Returns the QPointF object formed by dividing both components of the given point by the given divisor...
Definition: qpoint.h:371
timeval & operator+=(timeval &t1, const timeval &t2)
Definition: qcore_unix_p.h:120
int yp
Definition: qpoint.h:97
#define class
#define QT_END_HEADER
Definition: qglobal.h:137
void setX(int x)
Sets the x coordinate of this point to the given x coordinate.
Definition: qpoint.h:134
QDataStream & operator<<(QDataStream &out, const QUrl &url)
Writes url url to the stream out and returns a reference to the stream.
Definition: qurl.cpp:6757
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203
QPoint & operator/=(qreal c)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qpoint.h:194
friend bool operator==(const QPointF &, const QPointF &)
Returns true if p1 is equal to p2; otherwise returns false.
Definition: qpoint.h:329
static bool isNull(const QVariant::Private *d)
Definition: qvariant.cpp:300
Q_DECLARE_TYPEINFO(QPoint, Q_MOVABLE_TYPE)
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65
QDataStream & operator>>(QDataStream &in, QUrl &url)
Reads a url into url from the stream in and returns a reference to the stream.
Definition: qurl.cpp:6774
QGenericMatrix< N, M, T > operator-(const QGenericMatrix< N, M, T > &m1, const QGenericMatrix< N, M, T > &m2)
Returns the difference of m1 and m2.