1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtCore module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
45 #include <QtCore/qnamespace.h>
53 class Q_CORE_EXPORT QPoint
57 QPoint(int xpos, int ypos);
66 int manhattanLength() const;
71 QPoint &operator+=(const QPoint &p);
72 QPoint &operator-=(const QPoint &p);
74 QPoint &operator*=(float c);
75 QPoint &operator*=(double c);
76 QPoint &operator*=(int c);
78 QPoint &operator/=(qreal c);
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);
94 friend class QTransform;
95 // ### Qt 5; remove the ifdef and just have the same order on all platforms.
105 Q_DECLARE_TYPEINFO(QPoint, Q_MOVABLE_TYPE);
107 /*****************************************************************************
108 QPoint stream functions
109 *****************************************************************************/
110 #ifndef QT_NO_DATASTREAM
111 Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QPoint &);
112 Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QPoint &);
115 /*****************************************************************************
116 QPoint inline functions
117 *****************************************************************************/
119 inline QPoint::QPoint()
122 inline QPoint::QPoint(int xpos, int ypos)
123 { xp = xpos; yp = ypos; }
125 inline bool QPoint::isNull() const
126 { return xp == 0 && yp == 0; }
128 inline int QPoint::x() const
131 inline int QPoint::y() const
134 inline void QPoint::setX(int xpos)
137 inline void QPoint::setY(int ypos)
140 inline int &QPoint::rx()
143 inline int &QPoint::ry()
146 inline QPoint &QPoint::operator+=(const QPoint &p)
147 { xp+=p.xp; yp+=p.yp; return *this; }
149 inline QPoint &QPoint::operator-=(const QPoint &p)
150 { xp-=p.xp; yp-=p.yp; return *this; }
152 inline QPoint &QPoint::operator*=(float c)
153 { xp = qRound(xp*c); yp = qRound(yp*c); return *this; }
155 inline QPoint &QPoint::operator*=(double c)
156 { xp = qRound(xp*c); yp = qRound(yp*c); return *this; }
158 inline QPoint &QPoint::operator*=(int c)
159 { xp = xp*c; yp = yp*c; return *this; }
161 inline bool operator==(const QPoint &p1, const QPoint &p2)
162 { return p1.xp == p2.xp && p1.yp == p2.yp; }
164 inline bool operator!=(const QPoint &p1, const QPoint &p2)
165 { return p1.xp != p2.xp || p1.yp != p2.yp; }
167 inline const QPoint operator+(const QPoint &p1, const QPoint &p2)
168 { return QPoint(p1.xp+p2.xp, p1.yp+p2.yp); }
170 inline const QPoint operator-(const QPoint &p1, const QPoint &p2)
171 { return QPoint(p1.xp-p2.xp, p1.yp-p2.yp); }
173 inline const QPoint operator*(const QPoint &p, float c)
174 { return QPoint(qRound(p.xp*c), qRound(p.yp*c)); }
176 inline const QPoint operator*(const QPoint &p, double c)
177 { return QPoint(qRound(p.xp*c), qRound(p.yp*c)); }
179 inline const QPoint operator*(const QPoint &p, int c)
180 { return QPoint(p.xp*c, p.yp*c); }
182 inline const QPoint operator*(float c, const QPoint &p)
183 { return QPoint(qRound(p.xp*c), qRound(p.yp*c)); }
185 inline const QPoint operator*(double c, const QPoint &p)
186 { return QPoint(qRound(p.xp*c), qRound(p.yp*c)); }
188 inline const QPoint operator*(int c, const QPoint &p)
189 { return QPoint(p.xp*c, p.yp*c); }
191 inline const QPoint operator-(const QPoint &p)
192 { return QPoint(-p.xp, -p.yp); }
194 inline QPoint &QPoint::operator/=(qreal c)
201 inline const QPoint operator/(const QPoint &p, qreal c)
203 return QPoint(qRound(p.xp/c), qRound(p.yp/c));
206 #ifndef QT_NO_DEBUG_STREAM
207 Q_CORE_EXPORT QDebug operator<<(QDebug, const QPoint &);
214 class Q_CORE_EXPORT QPointF
218 QPointF(const QPoint &p);
219 QPointF(qreal xpos, qreal ypos);
221 qreal manhattanLength() const;
233 QPointF &operator+=(const QPointF &p);
234 QPointF &operator-=(const QPointF &p);
235 QPointF &operator*=(qreal c);
236 QPointF &operator/=(qreal c);
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);
247 QPoint toPoint() const;
250 friend class QMatrix;
251 friend class QTransform;
257 Q_DECLARE_TYPEINFO(QPointF, Q_MOVABLE_TYPE);
259 /*****************************************************************************
260 QPointF stream functions
261 *****************************************************************************/
262 #ifndef QT_NO_DATASTREAM
263 Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QPointF &);
264 Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QPointF &);
267 /*****************************************************************************
268 QPointF inline functions
269 *****************************************************************************/
271 inline QPointF::QPointF() : xp(0), yp(0) { }
273 inline QPointF::QPointF(qreal xpos, qreal ypos) : xp(xpos), yp(ypos) { }
275 inline QPointF::QPointF(const QPoint &p) : xp(p.x()), yp(p.y()) { }
277 inline bool QPointF::isNull() const
279 return qIsNull(xp) && qIsNull(yp);
282 inline qreal QPointF::x() const
287 inline qreal QPointF::y() const
292 inline void QPointF::setX(qreal xpos)
297 inline void QPointF::setY(qreal ypos)
302 inline qreal &QPointF::rx()
307 inline qreal &QPointF::ry()
312 inline QPointF &QPointF::operator+=(const QPointF &p)
319 inline QPointF &QPointF::operator-=(const QPointF &p)
321 xp-=p.xp; yp-=p.yp; return *this;
324 inline QPointF &QPointF::operator*=(qreal c)
326 xp*=c; yp*=c; return *this;
329 inline bool operator==(const QPointF &p1, const QPointF &p2)
331 return qFuzzyIsNull(p1.xp - p2.xp) && qFuzzyIsNull(p1.yp - p2.yp);
334 inline bool operator!=(const QPointF &p1, const QPointF &p2)
336 return !qFuzzyIsNull(p1.xp - p2.xp) || !qFuzzyIsNull(p1.yp - p2.yp);
339 inline const QPointF operator+(const QPointF &p1, const QPointF &p2)
341 return QPointF(p1.xp+p2.xp, p1.yp+p2.yp);
344 inline const QPointF operator-(const QPointF &p1, const QPointF &p2)
346 return QPointF(p1.xp-p2.xp, p1.yp-p2.yp);
349 inline const QPointF operator*(const QPointF &p, qreal c)
351 return QPointF(p.xp*c, p.yp*c);
354 inline const QPointF operator*(qreal c, const QPointF &p)
356 return QPointF(p.xp*c, p.yp*c);
359 inline const QPointF operator-(const QPointF &p)
361 return QPointF(-p.xp, -p.yp);
364 inline QPointF &QPointF::operator/=(qreal c)
371 inline const QPointF operator/(const QPointF &p, qreal c)
373 return QPointF(p.xp/c, p.yp/c);
376 inline QPoint QPointF::toPoint() const
378 return QPoint(qRound(xp), qRound(yp));
381 #ifndef QT_NO_DEBUG_STREAM
382 Q_CORE_EXPORT QDebug operator<<(QDebug d, const QPointF &p);