Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/tools/qpoint.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||
---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||
2 | ** | - | ||||||
3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||
4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||
5 | ** | - | ||||||
6 | ** This file is part of the QtCore module of the Qt Toolkit. | - | ||||||
7 | ** | - | ||||||
8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||
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 http://www.qt.io/terms-conditions. For further | - | ||||||
15 | ** information use the contact form at http://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 2.1 or version 3 as published by the Free | - | ||||||
20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||
21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||
22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||
23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||
24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||
25 | ** | - | ||||||
26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||
27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||
28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||
29 | ** | - | ||||||
30 | ** $QT_END_LICENSE$ | - | ||||||
31 | ** | - | ||||||
32 | ****************************************************************************/ | - | ||||||
33 | - | |||||||
34 | #include "qpoint.h" | - | ||||||
35 | #include "qdatastream.h" | - | ||||||
36 | - | |||||||
37 | #include <private/qdebug_p.h> | - | ||||||
38 | - | |||||||
39 | QT_BEGIN_NAMESPACE | - | ||||||
40 | - | |||||||
41 | /*! | - | ||||||
42 | \class QPoint | - | ||||||
43 | \inmodule QtCore | - | ||||||
44 | \ingroup painting | - | ||||||
45 | \reentrant | - | ||||||
46 | - | |||||||
47 | \brief The QPoint class defines a point in the plane using integer | - | ||||||
48 | precision. | - | ||||||
49 | - | |||||||
50 | A point is specified by a x coordinate and an y coordinate which | - | ||||||
51 | can be accessed using the x() and y() functions. The isNull() | - | ||||||
52 | function returns \c true if both x and y are set to 0. The | - | ||||||
53 | coordinates can be set (or altered) using the setX() and setY() | - | ||||||
54 | functions, or alternatively the rx() and ry() functions which | - | ||||||
55 | return references to the coordinates (allowing direct | - | ||||||
56 | manipulation). | - | ||||||
57 | - | |||||||
58 | Given a point \e p, the following statements are all equivalent: | - | ||||||
59 | - | |||||||
60 | \snippet code/src_corelib_tools_qpoint.cpp 0 | - | ||||||
61 | - | |||||||
62 | A QPoint object can also be used as a vector: Addition and | - | ||||||
63 | subtraction are defined as for vectors (each component is added | - | ||||||
64 | separately). A QPoint object can also be divided or multiplied by | - | ||||||
65 | an \c int or a \c qreal. | - | ||||||
66 | - | |||||||
67 | In addition, the QPoint class provides the manhattanLength() | - | ||||||
68 | function which gives an inexpensive approximation of the length of | - | ||||||
69 | the QPoint object interpreted as a vector. Finally, QPoint objects | - | ||||||
70 | can be streamed as well as compared. | - | ||||||
71 | - | |||||||
72 | \sa QPointF, QPolygon | - | ||||||
73 | */ | - | ||||||
74 | - | |||||||
75 | - | |||||||
76 | /***************************************************************************** | - | ||||||
77 | QPoint member functions | - | ||||||
78 | *****************************************************************************/ | - | ||||||
79 | - | |||||||
80 | /*! | - | ||||||
81 | \fn QPoint::QPoint() | - | ||||||
82 | - | |||||||
83 | Constructs a null point, i.e. with coordinates (0, 0) | - | ||||||
84 | - | |||||||
85 | \sa isNull() | - | ||||||
86 | */ | - | ||||||
87 | - | |||||||
88 | /*! | - | ||||||
89 | \fn QPoint::QPoint(int xpos, int ypos) | - | ||||||
90 | - | |||||||
91 | Constructs a point with the given coordinates (\a xpos, \a ypos). | - | ||||||
92 | - | |||||||
93 | \sa setX(), setY() | - | ||||||
94 | */ | - | ||||||
95 | - | |||||||
96 | /*! | - | ||||||
97 | \fn bool QPoint::isNull() const | - | ||||||
98 | - | |||||||
99 | Returns \c true if both the x and y coordinates are set to 0, | - | ||||||
100 | otherwise returns \c false. | - | ||||||
101 | */ | - | ||||||
102 | - | |||||||
103 | /*! | - | ||||||
104 | \fn int QPoint::x() const | - | ||||||
105 | - | |||||||
106 | Returns the x coordinate of this point. | - | ||||||
107 | - | |||||||
108 | \sa setX(), rx() | - | ||||||
109 | */ | - | ||||||
110 | - | |||||||
111 | /*! | - | ||||||
112 | \fn int QPoint::y() const | - | ||||||
113 | - | |||||||
114 | Returns the y coordinate of this point. | - | ||||||
115 | - | |||||||
116 | \sa setY(), ry() | - | ||||||
117 | */ | - | ||||||
118 | - | |||||||
119 | /*! | - | ||||||
120 | \fn void QPoint::setX(int x) | - | ||||||
121 | - | |||||||
122 | Sets the x coordinate of this point to the given \a x coordinate. | - | ||||||
123 | - | |||||||
124 | \sa x(), setY() | - | ||||||
125 | */ | - | ||||||
126 | - | |||||||
127 | /*! | - | ||||||
128 | \fn void QPoint::setY(int y) | - | ||||||
129 | - | |||||||
130 | Sets the y coordinate of this point to the given \a y coordinate. | - | ||||||
131 | - | |||||||
132 | \sa y(), setX() | - | ||||||
133 | */ | - | ||||||
134 | - | |||||||
135 | - | |||||||
136 | /*! | - | ||||||
137 | \fn int &QPoint::rx() | - | ||||||
138 | - | |||||||
139 | Returns a reference to the x coordinate of this point. | - | ||||||
140 | - | |||||||
141 | Using a reference makes it possible to directly manipulate x. For example: | - | ||||||
142 | - | |||||||
143 | \snippet code/src_corelib_tools_qpoint.cpp 1 | - | ||||||
144 | - | |||||||
145 | \sa x(), setX() | - | ||||||
146 | */ | - | ||||||
147 | - | |||||||
148 | /*! | - | ||||||
149 | \fn int &QPoint::ry() | - | ||||||
150 | - | |||||||
151 | Returns a reference to the y coordinate of this point. | - | ||||||
152 | - | |||||||
153 | Using a reference makes it possible to directly manipulate y. For | - | ||||||
154 | example: | - | ||||||
155 | - | |||||||
156 | \snippet code/src_corelib_tools_qpoint.cpp 2 | - | ||||||
157 | - | |||||||
158 | \sa y(), setY() | - | ||||||
159 | */ | - | ||||||
160 | - | |||||||
161 | - | |||||||
162 | /*! | - | ||||||
163 | \fn QPoint &QPoint::operator+=(const QPoint &point) | - | ||||||
164 | - | |||||||
165 | Adds the given \a point to this point and returns a reference to | - | ||||||
166 | this point. For example: | - | ||||||
167 | - | |||||||
168 | \snippet code/src_corelib_tools_qpoint.cpp 3 | - | ||||||
169 | - | |||||||
170 | \sa operator-=() | - | ||||||
171 | */ | - | ||||||
172 | - | |||||||
173 | /*! | - | ||||||
174 | \fn QPoint &QPoint::operator-=(const QPoint &point) | - | ||||||
175 | - | |||||||
176 | Subtracts the given \a point from this point and returns a | - | ||||||
177 | reference to this point. For example: | - | ||||||
178 | - | |||||||
179 | \snippet code/src_corelib_tools_qpoint.cpp 4 | - | ||||||
180 | - | |||||||
181 | \sa operator+=() | - | ||||||
182 | */ | - | ||||||
183 | - | |||||||
184 | /*! | - | ||||||
185 | \fn QPoint &QPoint::operator*=(float factor) | - | ||||||
186 | - | |||||||
187 | Multiplies this point's coordinates by the given \a factor, and | - | ||||||
188 | returns a reference to this point. | - | ||||||
189 | - | |||||||
190 | Note that the result is rounded to the nearest integer as points are held as | - | ||||||
191 | integers. Use QPointF for floating point accuracy. | - | ||||||
192 | - | |||||||
193 | \sa operator/=() | - | ||||||
194 | */ | - | ||||||
195 | - | |||||||
196 | /*! | - | ||||||
197 | \fn QPoint &QPoint::operator*=(double factor) | - | ||||||
198 | - | |||||||
199 | Multiplies this point's coordinates by the given \a factor, and | - | ||||||
200 | returns a reference to this point. For example: | - | ||||||
201 | - | |||||||
202 | \snippet code/src_corelib_tools_qpoint.cpp 5 | - | ||||||
203 | - | |||||||
204 | Note that the result is rounded to the nearest integer as points are held as | - | ||||||
205 | integers. Use QPointF for floating point accuracy. | - | ||||||
206 | - | |||||||
207 | \sa operator/=() | - | ||||||
208 | */ | - | ||||||
209 | - | |||||||
210 | /*! | - | ||||||
211 | \fn QPoint &QPoint::operator*=(int factor) | - | ||||||
212 | - | |||||||
213 | Multiplies this point's coordinates by the given \a factor, and | - | ||||||
214 | returns a reference to this point. | - | ||||||
215 | - | |||||||
216 | \sa operator/=() | - | ||||||
217 | */ | - | ||||||
218 | - | |||||||
219 | /*! | - | ||||||
220 | \fn static int QPoint::dotProduct(const QPoint &p1, const QPoint &p2) | - | ||||||
221 | \since 5.1 | - | ||||||
222 | - | |||||||
223 | \snippet code/src_corelib_tools_qpoint.cpp 16 | - | ||||||
224 | - | |||||||
225 | Returns the dot product of \a p1 and \a p2. | - | ||||||
226 | */ | - | ||||||
227 | - | |||||||
228 | /*! | - | ||||||
229 | \fn bool operator==(const QPoint &p1, const QPoint &p2) | - | ||||||
230 | \relates QPoint | - | ||||||
231 | - | |||||||
232 | Returns \c true if \a p1 and \a p2 are equal; otherwise returns | - | ||||||
233 | false. | - | ||||||
234 | */ | - | ||||||
235 | - | |||||||
236 | /*! | - | ||||||
237 | \fn bool operator!=(const QPoint &p1, const QPoint &p2) | - | ||||||
238 | \relates QPoint | - | ||||||
239 | - | |||||||
240 | Returns \c true if \a p1 and \a p2 are not equal; otherwise returns \c false. | - | ||||||
241 | */ | - | ||||||
242 | - | |||||||
243 | /*! | - | ||||||
244 | \fn const QPoint operator+(const QPoint &p1, const QPoint &p2) | - | ||||||
245 | \relates QPoint | - | ||||||
246 | - | |||||||
247 | Returns a QPoint object that is the sum of the given points, \a p1 | - | ||||||
248 | and \a p2; each component is added separately. | - | ||||||
249 | - | |||||||
250 | \sa QPoint::operator+=() | - | ||||||
251 | */ | - | ||||||
252 | - | |||||||
253 | /*! | - | ||||||
254 | \fn const QPoint operator-(const QPoint &p1, const QPoint &p2) | - | ||||||
255 | \relates QPoint | - | ||||||
256 | - | |||||||
257 | Returns a QPoint object that is formed by subtracting \a p2 from | - | ||||||
258 | \a p1; each component is subtracted separately. | - | ||||||
259 | - | |||||||
260 | \sa QPoint::operator-=() | - | ||||||
261 | */ | - | ||||||
262 | - | |||||||
263 | /*! | - | ||||||
264 | \fn const QPoint operator*(const QPoint &point, float factor) | - | ||||||
265 | \relates QPoint | - | ||||||
266 | - | |||||||
267 | Returns a copy of the given \a point multiplied by the given \a factor. | - | ||||||
268 | - | |||||||
269 | Note that the result is rounded to the nearest integer as points | - | ||||||
270 | are held as integers. Use QPointF for floating point accuracy. | - | ||||||
271 | - | |||||||
272 | \sa QPoint::operator*=() | - | ||||||
273 | */ | - | ||||||
274 | - | |||||||
275 | /*! | - | ||||||
276 | \fn const QPoint operator*(const QPoint &point, double factor) | - | ||||||
277 | \relates QPoint | - | ||||||
278 | - | |||||||
279 | Returns a copy of the given \a point multiplied by the given \a factor. | - | ||||||
280 | - | |||||||
281 | Note that the result is rounded to the nearest integer as points | - | ||||||
282 | are held as integers. Use QPointF for floating point accuracy. | - | ||||||
283 | - | |||||||
284 | \sa QPoint::operator*=() | - | ||||||
285 | */ | - | ||||||
286 | - | |||||||
287 | /*! | - | ||||||
288 | \fn const QPoint operator*(const QPoint &point, int factor) | - | ||||||
289 | \relates QPoint | - | ||||||
290 | - | |||||||
291 | Returns a copy of the given \a point multiplied by the given \a factor. | - | ||||||
292 | - | |||||||
293 | \sa QPoint::operator*=() | - | ||||||
294 | */ | - | ||||||
295 | - | |||||||
296 | /*! | - | ||||||
297 | \fn const QPoint operator*(float factor, const QPoint &point) | - | ||||||
298 | \overload | - | ||||||
299 | \relates QPoint | - | ||||||
300 | - | |||||||
301 | Returns a copy of the given \a point multiplied by the given \a factor. | - | ||||||
302 | - | |||||||
303 | Note that the result is rounded to the nearest integer as points | - | ||||||
304 | are held as integers. Use QPointF for floating point accuracy. | - | ||||||
305 | - | |||||||
306 | \sa QPoint::operator*=() | - | ||||||
307 | */ | - | ||||||
308 | - | |||||||
309 | /*! | - | ||||||
310 | \fn const QPoint operator*(double factor, const QPoint &point) | - | ||||||
311 | \overload | - | ||||||
312 | \relates QPoint | - | ||||||
313 | - | |||||||
314 | Returns a copy of the given \a point multiplied by the given \a factor. | - | ||||||
315 | - | |||||||
316 | Note that the result is rounded to the nearest integer as points | - | ||||||
317 | are held as integers. Use QPointF for floating point accuracy. | - | ||||||
318 | - | |||||||
319 | \sa QPoint::operator*=() | - | ||||||
320 | */ | - | ||||||
321 | - | |||||||
322 | /*! | - | ||||||
323 | \fn const QPoint operator*(int factor, const QPoint &point) | - | ||||||
324 | \overload | - | ||||||
325 | \relates QPoint | - | ||||||
326 | - | |||||||
327 | Returns a copy of the given \a point multiplied by the given \a factor. | - | ||||||
328 | - | |||||||
329 | \sa QPoint::operator*=() | - | ||||||
330 | */ | - | ||||||
331 | - | |||||||
332 | /*! | - | ||||||
333 | \fn const QPoint operator+(const QPoint &point) | - | ||||||
334 | \relates QPoint | - | ||||||
335 | \since 5.0 | - | ||||||
336 | - | |||||||
337 | Returns \a point unmodified. | - | ||||||
338 | */ | - | ||||||
339 | - | |||||||
340 | /*! | - | ||||||
341 | \fn const QPoint operator-(const QPoint &point) | - | ||||||
342 | \overload | - | ||||||
343 | \relates QPoint | - | ||||||
344 | - | |||||||
345 | Returns a QPoint object that is formed by changing the sign of | - | ||||||
346 | both components of the given \a point. | - | ||||||
347 | - | |||||||
348 | Equivalent to \c{QPoint(0,0) - point}. | - | ||||||
349 | */ | - | ||||||
350 | - | |||||||
351 | /*! | - | ||||||
352 | \fn QPoint &QPoint::operator/=(qreal divisor) | - | ||||||
353 | \overload | - | ||||||
354 | - | |||||||
355 | Divides both x and y by the given \a divisor, and returns a reference to this | - | ||||||
356 | point. For example: | - | ||||||
357 | - | |||||||
358 | \snippet code/src_corelib_tools_qpoint.cpp 6 | - | ||||||
359 | - | |||||||
360 | Note that the result is rounded to the nearest integer as points are held as | - | ||||||
361 | integers. Use QPointF for floating point accuracy. | - | ||||||
362 | - | |||||||
363 | \sa operator*=() | - | ||||||
364 | */ | - | ||||||
365 | - | |||||||
366 | /*! | - | ||||||
367 | \fn const QPoint operator/(const QPoint &point, qreal divisor) | - | ||||||
368 | \relates QPoint | - | ||||||
369 | - | |||||||
370 | Returns the QPoint formed by dividing both components of the given \a point | - | ||||||
371 | by the given \a divisor. | - | ||||||
372 | - | |||||||
373 | Note that the result is rounded to the nearest integer as points are held as | - | ||||||
374 | integers. Use QPointF for floating point accuracy. | - | ||||||
375 | - | |||||||
376 | \sa QPoint::operator/=() | - | ||||||
377 | */ | - | ||||||
378 | - | |||||||
379 | /***************************************************************************** | - | ||||||
380 | QPoint stream functions | - | ||||||
381 | *****************************************************************************/ | - | ||||||
382 | #ifndef QT_NO_DATASTREAM | - | ||||||
383 | /*! | - | ||||||
384 | \fn QDataStream &operator<<(QDataStream &stream, const QPoint &point) | - | ||||||
385 | \relates QPoint | - | ||||||
386 | - | |||||||
387 | Writes the given \a point to the given \a stream and returns a | - | ||||||
388 | reference to the stream. | - | ||||||
389 | - | |||||||
390 | \sa {Serializing Qt Data Types} | - | ||||||
391 | */ | - | ||||||
392 | - | |||||||
393 | QDataStream &operator<<(QDataStream &s, const QPoint &p) | - | ||||||
394 | { | - | ||||||
395 | if (s.version() == 1)
| 0-159 | ||||||
396 | s << (qint16)p.x() << (qint16)p.y(); never executed: s << (qint16)p.x() << (qint16)p.y(); | 0 | ||||||
397 | else | - | ||||||
398 | s << (qint32)p.x() << (qint32)p.y(); executed 159 times by 6 tests: s << (qint32)p.x() << (qint32)p.y(); Executed by:
| 159 | ||||||
399 | return s; executed 159 times by 6 tests: return s; Executed by:
| 159 | ||||||
400 | } | - | ||||||
401 | - | |||||||
402 | /*! | - | ||||||
403 | \fn QDataStream &operator>>(QDataStream &stream, QPoint &point) | - | ||||||
404 | \relates QPoint | - | ||||||
405 | - | |||||||
406 | Reads a point from the given \a stream into the given \a point | - | ||||||
407 | and returns a reference to the stream. | - | ||||||
408 | - | |||||||
409 | \sa {Serializing Qt Data Types} | - | ||||||
410 | */ | - | ||||||
411 | - | |||||||
412 | QDataStream &operator>>(QDataStream &s, QPoint &p) | - | ||||||
413 | { | - | ||||||
414 | if (s.version() == 1) {
| 0-171 | ||||||
415 | qint16 x, y; | - | ||||||
416 | s >> x; p.rx() = x; | - | ||||||
417 | s >> y; p.ry() = y; | - | ||||||
418 | } never executed: end of block | 0 | ||||||
419 | else { | - | ||||||
420 | qint32 x, y; | - | ||||||
421 | s >> x; p.rx() = x; | - | ||||||
422 | s >> y; p.ry() = y; | - | ||||||
423 | } executed 171 times by 6 tests: end of block Executed by:
| 171 | ||||||
424 | return s; executed 171 times by 6 tests: return s; Executed by:
| 171 | ||||||
425 | } | - | ||||||
426 | - | |||||||
427 | #endif // QT_NO_DATASTREAM | - | ||||||
428 | /*! | - | ||||||
429 | \fn int QPoint::manhattanLength() const | - | ||||||
430 | - | |||||||
431 | Returns the sum of the absolute values of x() and y(), | - | ||||||
432 | traditionally known as the "Manhattan length" of the vector from | - | ||||||
433 | the origin to the point. For example: | - | ||||||
434 | - | |||||||
435 | \snippet code/src_corelib_tools_qpoint.cpp 7 | - | ||||||
436 | - | |||||||
437 | This is a useful, and quick to calculate, approximation to the | - | ||||||
438 | true length: | - | ||||||
439 | - | |||||||
440 | \snippet code/src_corelib_tools_qpoint.cpp 8 | - | ||||||
441 | - | |||||||
442 | The tradition of "Manhattan length" arises because such distances | - | ||||||
443 | apply to travelers who can only travel on a rectangular grid, like | - | ||||||
444 | the streets of Manhattan. | - | ||||||
445 | */ | - | ||||||
446 | - | |||||||
447 | #ifndef QT_NO_DEBUG_STREAM | - | ||||||
448 | QDebug operator<<(QDebug dbg, const QPoint &p) | - | ||||||
449 | { | - | ||||||
450 | QDebugStateSaver saver(dbg); | - | ||||||
451 | dbg.nospace(); | - | ||||||
452 | dbg << "QPoint" << '('; | - | ||||||
453 | QtDebugUtils::formatQPoint(dbg, p); | - | ||||||
454 | dbg << ')'; | - | ||||||
455 | return dbg; executed 34 times by 5 tests: return dbg; Executed by:
| 34 | ||||||
456 | } | - | ||||||
457 | - | |||||||
458 | QDebug operator<<(QDebug dbg, const QPointF &p) | - | ||||||
459 | { | - | ||||||
460 | QDebugStateSaver saver(dbg); | - | ||||||
461 | dbg.nospace(); | - | ||||||
462 | dbg << "QPointF" << '('; | - | ||||||
463 | QtDebugUtils::formatQPoint(dbg, p); | - | ||||||
464 | dbg << ')'; | - | ||||||
465 | return dbg; executed 6 times by 2 tests: return dbg; Executed by:
| 6 | ||||||
466 | } | - | ||||||
467 | #endif | - | ||||||
468 | - | |||||||
469 | /*! | - | ||||||
470 | \class QPointF | - | ||||||
471 | \inmodule QtCore | - | ||||||
472 | \ingroup painting | - | ||||||
473 | \reentrant | - | ||||||
474 | - | |||||||
475 | \brief The QPointF class defines a point in the plane using | - | ||||||
476 | floating point precision. | - | ||||||
477 | - | |||||||
478 | A point is specified by a x coordinate and an y coordinate which | - | ||||||
479 | can be accessed using the x() and y() functions. The coordinates | - | ||||||
480 | of the point are specified using floating point numbers for | - | ||||||
481 | accuracy. The isNull() function returns \c true if both x and y are | - | ||||||
482 | set to 0.0. The coordinates can be set (or altered) using the setX() | - | ||||||
483 | and setY() functions, or alternatively the rx() and ry() functions which | - | ||||||
484 | return references to the coordinates (allowing direct | - | ||||||
485 | manipulation). | - | ||||||
486 | - | |||||||
487 | Given a point \e p, the following statements are all equivalent: | - | ||||||
488 | - | |||||||
489 | \snippet code/src_corelib_tools_qpoint.cpp 9 | - | ||||||
490 | - | |||||||
491 | A QPointF object can also be used as a vector: Addition and | - | ||||||
492 | subtraction are defined as for vectors (each component is added | - | ||||||
493 | separately). A QPointF object can also be divided or multiplied by | - | ||||||
494 | an \c int or a \c qreal. | - | ||||||
495 | - | |||||||
496 | In addition, the QPointF class provides a constructor converting a | - | ||||||
497 | QPoint object into a QPointF object, and a corresponding toPoint() | - | ||||||
498 | function which returns a QPoint copy of \e this point. Finally, | - | ||||||
499 | QPointF objects can be streamed as well as compared. | - | ||||||
500 | - | |||||||
501 | \sa QPoint, QPolygonF | - | ||||||
502 | */ | - | ||||||
503 | - | |||||||
504 | /*! | - | ||||||
505 | \fn QPointF::QPointF() | - | ||||||
506 | - | |||||||
507 | Constructs a null point, i.e. with coordinates (0.0, 0.0) | - | ||||||
508 | - | |||||||
509 | \sa isNull() | - | ||||||
510 | */ | - | ||||||
511 | - | |||||||
512 | /*! | - | ||||||
513 | \fn QPointF::QPointF(const QPoint &point) | - | ||||||
514 | - | |||||||
515 | Constructs a copy of the given \a point. | - | ||||||
516 | - | |||||||
517 | \sa toPoint() | - | ||||||
518 | */ | - | ||||||
519 | - | |||||||
520 | /*! | - | ||||||
521 | \fn QPointF::QPointF(qreal xpos, qreal ypos) | - | ||||||
522 | - | |||||||
523 | Constructs a point with the given coordinates (\a xpos, \a ypos). | - | ||||||
524 | - | |||||||
525 | \sa setX(), setY() | - | ||||||
526 | */ | - | ||||||
527 | - | |||||||
528 | /*! | - | ||||||
529 | \fn bool QPointF::isNull() const | - | ||||||
530 | - | |||||||
531 | Returns \c true if both the x and y coordinates are set to 0.0 (ignoring | - | ||||||
532 | the sign); otherwise returns \c false. | - | ||||||
533 | */ | - | ||||||
534 | - | |||||||
535 | - | |||||||
536 | /*! | - | ||||||
537 | \fn qreal QPointF::manhattanLength() const | - | ||||||
538 | \since 4.6 | - | ||||||
539 | - | |||||||
540 | Returns the sum of the absolute values of x() and y(), | - | ||||||
541 | traditionally known as the "Manhattan length" of the vector from | - | ||||||
542 | the origin to the point. | - | ||||||
543 | - | |||||||
544 | \sa QPoint::manhattanLength() | - | ||||||
545 | */ | - | ||||||
546 | - | |||||||
547 | /*! | - | ||||||
548 | \fn qreal QPointF::x() const | - | ||||||
549 | - | |||||||
550 | Returns the x coordinate of this point. | - | ||||||
551 | - | |||||||
552 | \sa setX(), rx() | - | ||||||
553 | */ | - | ||||||
554 | - | |||||||
555 | /*! | - | ||||||
556 | \fn qreal QPointF::y() const | - | ||||||
557 | - | |||||||
558 | Returns the y coordinate of this point. | - | ||||||
559 | - | |||||||
560 | \sa setY(), ry() | - | ||||||
561 | */ | - | ||||||
562 | - | |||||||
563 | /*! | - | ||||||
564 | \fn void QPointF::setX(qreal x) | - | ||||||
565 | - | |||||||
566 | Sets the x coordinate of this point to the given \a x coordinate. | - | ||||||
567 | - | |||||||
568 | \sa x(), setY() | - | ||||||
569 | */ | - | ||||||
570 | - | |||||||
571 | /*! | - | ||||||
572 | \fn void QPointF::setY(qreal y) | - | ||||||
573 | - | |||||||
574 | Sets the y coordinate of this point to the given \a y coordinate. | - | ||||||
575 | - | |||||||
576 | \sa y(), setX() | - | ||||||
577 | */ | - | ||||||
578 | - | |||||||
579 | /*! | - | ||||||
580 | \fn qreal& QPointF::rx() | - | ||||||
581 | - | |||||||
582 | Returns a reference to the x coordinate of this point. | - | ||||||
583 | - | |||||||
584 | Using a reference makes it possible to directly manipulate x. For example: | - | ||||||
585 | - | |||||||
586 | \snippet code/src_corelib_tools_qpoint.cpp 10 | - | ||||||
587 | - | |||||||
588 | \sa x(), setX() | - | ||||||
589 | */ | - | ||||||
590 | - | |||||||
591 | /*! | - | ||||||
592 | \fn qreal& QPointF::ry() | - | ||||||
593 | - | |||||||
594 | Returns a reference to the y coordinate of this point. | - | ||||||
595 | - | |||||||
596 | Using a reference makes it possible to directly manipulate y. For example: | - | ||||||
597 | - | |||||||
598 | \snippet code/src_corelib_tools_qpoint.cpp 11 | - | ||||||
599 | - | |||||||
600 | \sa y(), setY() | - | ||||||
601 | */ | - | ||||||
602 | - | |||||||
603 | /*! | - | ||||||
604 | \fn QPointF& QPointF::operator+=(const QPointF &point) | - | ||||||
605 | - | |||||||
606 | Adds the given \a point to this point and returns a reference to | - | ||||||
607 | this point. For example: | - | ||||||
608 | - | |||||||
609 | \snippet code/src_corelib_tools_qpoint.cpp 12 | - | ||||||
610 | - | |||||||
611 | \sa operator-=() | - | ||||||
612 | */ | - | ||||||
613 | - | |||||||
614 | /*! | - | ||||||
615 | \fn QPointF& QPointF::operator-=(const QPointF &point) | - | ||||||
616 | - | |||||||
617 | Subtracts the given \a point from this point and returns a reference | - | ||||||
618 | to this point. For example: | - | ||||||
619 | - | |||||||
620 | \snippet code/src_corelib_tools_qpoint.cpp 13 | - | ||||||
621 | - | |||||||
622 | \sa operator+=() | - | ||||||
623 | */ | - | ||||||
624 | - | |||||||
625 | /*! | - | ||||||
626 | \fn QPointF& QPointF::operator*=(qreal factor) | - | ||||||
627 | - | |||||||
628 | Multiplies this point's coordinates by the given \a factor, and | - | ||||||
629 | returns a reference to this point. For example: | - | ||||||
630 | - | |||||||
631 | \snippet code/src_corelib_tools_qpoint.cpp 14 | - | ||||||
632 | - | |||||||
633 | \sa operator/=() | - | ||||||
634 | */ | - | ||||||
635 | - | |||||||
636 | /*! | - | ||||||
637 | \fn QPointF& QPointF::operator/=(qreal divisor) | - | ||||||
638 | - | |||||||
639 | Divides both x and y by the given \a divisor, and returns a reference | - | ||||||
640 | to this point. For example: | - | ||||||
641 | - | |||||||
642 | \snippet code/src_corelib_tools_qpoint.cpp 15 | - | ||||||
643 | - | |||||||
644 | \sa operator*=() | - | ||||||
645 | */ | - | ||||||
646 | - | |||||||
647 | /*! | - | ||||||
648 | \fn const QPointF operator+(const QPointF &p1, const QPointF &p2) | - | ||||||
649 | \relates QPointF | - | ||||||
650 | - | |||||||
651 | Returns a QPointF object that is the sum of the given points, \a p1 | - | ||||||
652 | and \a p2; each component is added separately. | - | ||||||
653 | - | |||||||
654 | \sa QPointF::operator+=() | - | ||||||
655 | */ | - | ||||||
656 | - | |||||||
657 | /*! | - | ||||||
658 | \fn const QPointF operator-(const QPointF &p1, const QPointF &p2) | - | ||||||
659 | \relates QPointF | - | ||||||
660 | - | |||||||
661 | Returns a QPointF object that is formed by subtracting \a p2 from \a p1; | - | ||||||
662 | each component is subtracted separately. | - | ||||||
663 | - | |||||||
664 | \sa QPointF::operator-=() | - | ||||||
665 | */ | - | ||||||
666 | - | |||||||
667 | /*! | - | ||||||
668 | \fn const QPointF operator*(const QPointF &point, qreal factor) | - | ||||||
669 | \relates QPointF | - | ||||||
670 | - | |||||||
671 | Returns a copy of the given \a point, multiplied by the given \a factor. | - | ||||||
672 | - | |||||||
673 | \sa QPointF::operator*=() | - | ||||||
674 | */ | - | ||||||
675 | - | |||||||
676 | /*! | - | ||||||
677 | \fn const QPointF operator*(qreal factor, const QPointF &point) | - | ||||||
678 | \relates QPointF | - | ||||||
679 | - | |||||||
680 | \overload | - | ||||||
681 | - | |||||||
682 | Returns a copy of the given \a point, multiplied by the given \a factor. | - | ||||||
683 | */ | - | ||||||
684 | - | |||||||
685 | /*! | - | ||||||
686 | \fn const QPointF operator+(const QPointF &point) | - | ||||||
687 | \relates QPointF | - | ||||||
688 | \since 5.0 | - | ||||||
689 | - | |||||||
690 | Returns \a point unmodified. | - | ||||||
691 | */ | - | ||||||
692 | - | |||||||
693 | /*! | - | ||||||
694 | \fn const QPointF operator-(const QPointF &point) | - | ||||||
695 | \relates QPointF | - | ||||||
696 | \overload | - | ||||||
697 | - | |||||||
698 | Returns a QPointF object that is formed by changing the sign of | - | ||||||
699 | both components of the given \a point. | - | ||||||
700 | - | |||||||
701 | Equivalent to \c {QPointF(0,0) - point}. | - | ||||||
702 | */ | - | ||||||
703 | - | |||||||
704 | /*! | - | ||||||
705 | \fn const QPointF operator/(const QPointF &point, qreal divisor) | - | ||||||
706 | \relates QPointF | - | ||||||
707 | - | |||||||
708 | Returns the QPointF object formed by dividing both components of | - | ||||||
709 | the given \a point by the given \a divisor. | - | ||||||
710 | - | |||||||
711 | \sa QPointF::operator/=() | - | ||||||
712 | */ | - | ||||||
713 | - | |||||||
714 | /*! | - | ||||||
715 | \fn QPoint QPointF::toPoint() const | - | ||||||
716 | - | |||||||
717 | Rounds the coordinates of this point to the nearest integer, and | - | ||||||
718 | returns a QPoint object with the rounded coordinates. | - | ||||||
719 | - | |||||||
720 | \sa QPointF() | - | ||||||
721 | */ | - | ||||||
722 | - | |||||||
723 | /*! | - | ||||||
724 | \fn static qreal QPointF::dotProduct(const QPointF &p1, const QPointF &p2) | - | ||||||
725 | \since 5.1 | - | ||||||
726 | - | |||||||
727 | \snippet code/src_corelib_tools_qpoint.cpp 17 | - | ||||||
728 | - | |||||||
729 | Returns the dot product of \a p1 and \a p2. | - | ||||||
730 | */ | - | ||||||
731 | - | |||||||
732 | /*! | - | ||||||
733 | \fn bool operator==(const QPointF &p1, const QPointF &p2) | - | ||||||
734 | \relates QPointF | - | ||||||
735 | - | |||||||
736 | Returns \c true if \a p1 is equal to \a p2; otherwise returns \c false. | - | ||||||
737 | */ | - | ||||||
738 | - | |||||||
739 | /*! | - | ||||||
740 | \fn bool operator!=(const QPointF &p1, const QPointF &p2); | - | ||||||
741 | \relates QPointF | - | ||||||
742 | - | |||||||
743 | Returns \c true if \a p1 is not equal to \a p2; otherwise returns \c false. | - | ||||||
744 | */ | - | ||||||
745 | - | |||||||
746 | #ifndef QT_NO_DATASTREAM | - | ||||||
747 | /*! | - | ||||||
748 | \fn QDataStream &operator<<(QDataStream &stream, const QPointF &point) | - | ||||||
749 | \relates QPointF | - | ||||||
750 | - | |||||||
751 | Writes the given \a point to the given \a stream and returns a | - | ||||||
752 | reference to the stream. | - | ||||||
753 | - | |||||||
754 | \sa {Serializing Qt Data Types} | - | ||||||
755 | */ | - | ||||||
756 | - | |||||||
757 | QDataStream &operator<<(QDataStream &s, const QPointF &p) | - | ||||||
758 | { | - | ||||||
759 | s << double(p.x()) << double(p.y()); | - | ||||||
760 | return s; executed 256 times by 10 tests: return s; Executed by:
| 256 | ||||||
761 | } | - | ||||||
762 | - | |||||||
763 | /*! | - | ||||||
764 | \fn QDataStream &operator>>(QDataStream &stream, QPointF &point) | - | ||||||
765 | \relates QPointF | - | ||||||
766 | - | |||||||
767 | Reads a point from the given \a stream into the given \a point | - | ||||||
768 | and returns a reference to the stream. | - | ||||||
769 | - | |||||||
770 | \sa {Serializing Qt Data Types} | - | ||||||
771 | */ | - | ||||||
772 | - | |||||||
773 | QDataStream &operator>>(QDataStream &s, QPointF &p) | - | ||||||
774 | { | - | ||||||
775 | double x, y; | - | ||||||
776 | s >> x; | - | ||||||
777 | s >> y; | - | ||||||
778 | p.setX(qreal(x)); | - | ||||||
779 | p.setY(qreal(y)); | - | ||||||
780 | return s; executed 136 times by 9 tests: return s; Executed by:
| 136 | ||||||
781 | } | - | ||||||
782 | #endif // QT_NO_DATASTREAM | - | ||||||
783 | - | |||||||
784 | QT_END_NAMESPACE | - | ||||||
Source code | Switch to Preprocessed file |