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;
99 Q_DECLARE_TYPEINFO(QPoint, Q_MOVABLE_TYPE);
101 /*****************************************************************************
102 QPoint stream functions
103 *****************************************************************************/
104 #ifndef QT_NO_DATASTREAM
105 Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QPoint &);
106 Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QPoint &);
109 /*****************************************************************************
110 QPoint inline functions
111 *****************************************************************************/
113 inline QPoint::QPoint()
116 inline QPoint::QPoint(int xpos, int ypos)
117 { xp = xpos; yp = ypos; }
119 inline bool QPoint::isNull() const
120 { return xp == 0 && yp == 0; }
122 inline int QPoint::x() const
125 inline int QPoint::y() const
128 inline void QPoint::setX(int xpos)
131 inline void QPoint::setY(int ypos)
134 inline int &QPoint::rx()
137 inline int &QPoint::ry()
140 inline QPoint &QPoint::operator+=(const QPoint &p)
141 { xp+=p.xp; yp+=p.yp; return *this; }
143 inline QPoint &QPoint::operator-=(const QPoint &p)
144 { xp-=p.xp; yp-=p.yp; return *this; }
146 inline QPoint &QPoint::operator*=(float c)
147 { xp = qRound(xp*c); yp = qRound(yp*c); return *this; }
149 inline QPoint &QPoint::operator*=(double c)
150 { xp = qRound(xp*c); yp = qRound(yp*c); return *this; }
152 inline QPoint &QPoint::operator*=(int c)
153 { xp = xp*c; yp = yp*c; return *this; }
155 inline bool operator==(const QPoint &p1, const QPoint &p2)
156 { return p1.xp == p2.xp && p1.yp == p2.yp; }
158 inline bool operator!=(const QPoint &p1, const QPoint &p2)
159 { return p1.xp != p2.xp || p1.yp != p2.yp; }
161 inline const QPoint operator+(const QPoint &p1, const QPoint &p2)
162 { return QPoint(p1.xp+p2.xp, p1.yp+p2.yp); }
164 inline const QPoint operator-(const QPoint &p1, const QPoint &p2)
165 { return QPoint(p1.xp-p2.xp, p1.yp-p2.yp); }
167 inline const QPoint operator*(const QPoint &p, float c)
168 { return QPoint(qRound(p.xp*c), qRound(p.yp*c)); }
170 inline const QPoint operator*(const QPoint &p, double c)
171 { return QPoint(qRound(p.xp*c), qRound(p.yp*c)); }
173 inline const QPoint operator*(const QPoint &p, int c)
174 { return QPoint(p.xp*c, p.yp*c); }
176 inline const QPoint operator*(float c, const QPoint &p)
177 { return QPoint(qRound(p.xp*c), qRound(p.yp*c)); }
179 inline const QPoint operator*(double c, const QPoint &p)
180 { return QPoint(qRound(p.xp*c), qRound(p.yp*c)); }
182 inline const QPoint operator*(int c, const QPoint &p)
183 { return QPoint(p.xp*c, p.yp*c); }
185 inline const QPoint operator-(const QPoint &p)
186 { return QPoint(-p.xp, -p.yp); }
188 inline QPoint &QPoint::operator/=(qreal c)
195 inline const QPoint operator/(const QPoint &p, qreal c)
197 return QPoint(qRound(p.xp/c), qRound(p.yp/c));
200 #ifndef QT_NO_DEBUG_STREAM
201 Q_CORE_EXPORT QDebug operator<<(QDebug, const QPoint &);
208 class Q_CORE_EXPORT QPointF
212 QPointF(const QPoint &p);
213 QPointF(qreal xpos, qreal ypos);
215 qreal manhattanLength() const;
227 QPointF &operator+=(const QPointF &p);
228 QPointF &operator-=(const QPointF &p);
229 QPointF &operator*=(qreal c);
230 QPointF &operator/=(qreal c);
232 friend inline bool operator==(const QPointF &, const QPointF &);
233 friend inline bool operator!=(const QPointF &, const QPointF &);
234 friend inline const QPointF operator+(const QPointF &, const QPointF &);
235 friend inline const QPointF operator-(const QPointF &, const QPointF &);
236 friend inline const QPointF operator*(qreal, const QPointF &);
237 friend inline const QPointF operator*(const QPointF &, qreal);
238 friend inline const QPointF operator-(const QPointF &);
239 friend inline const QPointF operator/(const QPointF &, qreal);
241 QPoint toPoint() const;
244 friend class QMatrix;
245 friend class QTransform;
251 Q_DECLARE_TYPEINFO(QPointF, Q_MOVABLE_TYPE);
253 /*****************************************************************************
254 QPointF stream functions
255 *****************************************************************************/
256 #ifndef QT_NO_DATASTREAM
257 Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QPointF &);
258 Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QPointF &);
261 /*****************************************************************************
262 QPointF inline functions
263 *****************************************************************************/
265 inline QPointF::QPointF() : xp(0), yp(0) { }
267 inline QPointF::QPointF(qreal xpos, qreal ypos) : xp(xpos), yp(ypos) { }
269 inline QPointF::QPointF(const QPoint &p) : xp(p.x()), yp(p.y()) { }
271 inline bool QPointF::isNull() const
273 return qIsNull(xp) && qIsNull(yp);
276 inline qreal QPointF::x() const
281 inline qreal QPointF::y() const
286 inline void QPointF::setX(qreal xpos)
291 inline void QPointF::setY(qreal ypos)
296 inline qreal &QPointF::rx()
301 inline qreal &QPointF::ry()
306 inline QPointF &QPointF::operator+=(const QPointF &p)
313 inline QPointF &QPointF::operator-=(const QPointF &p)
315 xp-=p.xp; yp-=p.yp; return *this;
318 inline QPointF &QPointF::operator*=(qreal c)
320 xp*=c; yp*=c; return *this;
323 inline bool operator==(const QPointF &p1, const QPointF &p2)
325 return qFuzzyIsNull(p1.xp - p2.xp) && qFuzzyIsNull(p1.yp - p2.yp);
328 inline bool operator!=(const QPointF &p1, const QPointF &p2)
330 return !qFuzzyIsNull(p1.xp - p2.xp) || !qFuzzyIsNull(p1.yp - p2.yp);
333 inline const QPointF operator+(const QPointF &p1, const QPointF &p2)
335 return QPointF(p1.xp+p2.xp, p1.yp+p2.yp);
338 inline const QPointF operator-(const QPointF &p1, const QPointF &p2)
340 return QPointF(p1.xp-p2.xp, p1.yp-p2.yp);
343 inline const QPointF operator*(const QPointF &p, qreal c)
345 return QPointF(p.xp*c, p.yp*c);
348 inline const QPointF operator*(qreal c, const QPointF &p)
350 return QPointF(p.xp*c, p.yp*c);
353 inline const QPointF operator-(const QPointF &p)
355 return QPointF(-p.xp, -p.yp);
358 inline QPointF &QPointF::operator/=(qreal c)
365 inline const QPointF operator/(const QPointF &p, qreal c)
367 return QPointF(p.xp/c, p.yp/c);
370 inline QPoint QPointF::toPoint() const
372 return QPoint(qRound(xp), qRound(yp));
375 #ifndef QT_NO_DEBUG_STREAM
376 Q_CORE_EXPORT QDebug operator<<(QDebug d, const QPointF &p);