source: trunk/doc/html/qpoint.html@ 190

Last change on this file since 190 was 190, checked in by rudi, 14 years ago

reference documentation added

File size: 17.8 KB
Line 
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2<!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/src/kernel/qpoint.cpp:42 -->
3<html>
4<head>
5<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
6<title>QPoint Class</title>
7<style type="text/css"><!--
8fn { margin-left: 1cm; text-indent: -1cm; }
9a:link { color: #004faf; text-decoration: none }
10a:visited { color: #672967; text-decoration: none }
11body { background: #ffffff; color: black; }
12--></style>
13</head>
14<body>
15
16<table border="0" cellpadding="0" cellspacing="0" width="100%">
17<tr bgcolor="#E5E5E5">
18<td valign=center>
19 <a href="index.html">
20<font color="#004faf">Home</font></a>
21 | <a href="classes.html">
22<font color="#004faf">All&nbsp;Classes</font></a>
23 | <a href="mainclasses.html">
24<font color="#004faf">Main&nbsp;Classes</font></a>
25 | <a href="annotated.html">
26<font color="#004faf">Annotated</font></a>
27 | <a href="groups.html">
28<font color="#004faf">Grouped&nbsp;Classes</font></a>
29 | <a href="functions.html">
30<font color="#004faf">Functions</font></a>
31</td>
32<td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>QPoint Class Reference</h1>
33
34<p>The QPoint class defines a point in the plane.
35<a href="#details">More...</a>
36<p><tt>#include &lt;<a href="qpoint-h.html">qpoint.h</a>&gt;</tt>
37<p><a href="qpoint-members.html">List of all member functions.</a>
38<h2>Public Members</h2>
39<ul>
40<li class=fn><a href="#QPoint"><b>QPoint</b></a> ()</li>
41<li class=fn><a href="#QPoint-2"><b>QPoint</b></a> ( int&nbsp;xpos, int&nbsp;ypos )</li>
42<li class=fn>bool <a href="#isNull"><b>isNull</b></a> () const</li>
43<li class=fn>int <a href="#x"><b>x</b></a> () const</li>
44<li class=fn>int <a href="#y"><b>y</b></a> () const</li>
45<li class=fn>void <a href="#setX"><b>setX</b></a> ( int&nbsp;x )</li>
46<li class=fn>void <a href="#setY"><b>setY</b></a> ( int&nbsp;y )</li>
47<li class=fn>int <a href="#manhattanLength"><b>manhattanLength</b></a> () const</li>
48<li class=fn>QCOORD &amp; <a href="#rx"><b>rx</b></a> ()</li>
49<li class=fn>QCOORD &amp; <a href="#ry"><b>ry</b></a> ()</li>
50<li class=fn>QPoint &amp; <a href="#operator+-eq"><b>operator+=</b></a> ( const&nbsp;QPoint&nbsp;&amp;&nbsp;p )</li>
51<li class=fn>QPoint &amp; <a href="#operator--eq"><b>operator-=</b></a> ( const&nbsp;QPoint&nbsp;&amp;&nbsp;p )</li>
52<li class=fn>QPoint &amp; <a href="#operator*-eq"><b>operator*=</b></a> ( int&nbsp;c )</li>
53<li class=fn>QPoint &amp; <a href="#operator*-eq-2"><b>operator*=</b></a> ( double&nbsp;c )</li>
54<li class=fn>QPoint &amp; <a href="#operator/-eq"><b>operator/=</b></a> ( int&nbsp;c )</li>
55<li class=fn>QPoint &amp; <a href="#operator/-eq-2"><b>operator/=</b></a> ( double&nbsp;c )</li>
56</ul>
57<h2>Related Functions</h2>
58<ul>
59<li class=fn>bool <a href="#operator-eq-eq"><b>operator==</b></a> ( const&nbsp;QPoint&nbsp;&amp;&nbsp;p1, const&nbsp;QPoint&nbsp;&amp;&nbsp;p2 )</li>
60<li class=fn>bool <a href="#operator!-eq"><b>operator!=</b></a> ( const&nbsp;QPoint&nbsp;&amp;&nbsp;p1, const&nbsp;QPoint&nbsp;&amp;&nbsp;p2 )</li>
61<li class=fn>const QPoint <a href="#operator+"><b>operator+</b></a> ( const&nbsp;QPoint&nbsp;&amp;&nbsp;p1, const&nbsp;QPoint&nbsp;&amp;&nbsp;p2 )</li>
62<li class=fn>const QPoint <a href="#operator-"><b>operator-</b></a> ( const&nbsp;QPoint&nbsp;&amp;&nbsp;p1, const&nbsp;QPoint&nbsp;&amp;&nbsp;p2 )</li>
63<li class=fn>const QPoint <a href="#operator*"><b>operator*</b></a> ( const&nbsp;QPoint&nbsp;&amp;&nbsp;p, int&nbsp;c )</li>
64<li class=fn>const QPoint <a href="#operator*-2"><b>operator*</b></a> ( int&nbsp;c, const&nbsp;QPoint&nbsp;&amp;&nbsp;p )</li>
65<li class=fn>const QPoint <a href="#operator*-3"><b>operator*</b></a> ( const&nbsp;QPoint&nbsp;&amp;&nbsp;p, double&nbsp;c )</li>
66<li class=fn>const QPoint <a href="#operator*-4"><b>operator*</b></a> ( double&nbsp;c, const&nbsp;QPoint&nbsp;&amp;&nbsp;p )</li>
67<li class=fn>const QPoint <a href="#operator--2"><b>operator-</b></a> ( const&nbsp;QPoint&nbsp;&amp;&nbsp;p )</li>
68<li class=fn>const QPoint <a href="#operator/"><b>operator/</b></a> ( const&nbsp;QPoint&nbsp;&amp;&nbsp;p, int&nbsp;c )</li>
69<li class=fn>const QPoint <a href="#operator/-2"><b>operator/</b></a> ( const&nbsp;QPoint&nbsp;&amp;&nbsp;p, double&nbsp;c )</li>
70<li class=fn>QDataStream &amp; <a href="#operator-lt-lt"><b>operator&lt;&lt;</b></a> ( QDataStream&nbsp;&amp;&nbsp;s, const&nbsp;QPoint&nbsp;&amp;&nbsp;p )</li>
71<li class=fn>QDataStream &amp; <a href="#operator-gt-gt"><b>operator&gt;&gt;</b></a> ( QDataStream&nbsp;&amp;&nbsp;s, QPoint&nbsp;&amp;&nbsp;p )</li>
72</ul>
73<hr><a name="details"></a><h2>Detailed Description</h2>
74
75
76The QPoint class defines a point in the plane.
77<p>
78
79
80<p> A point is specified by an x coordinate and a y coordinate.
81<p> The coordinate type is <tt>QCOORD</tt> (a 32-bit integer). The minimum
82value of <tt>QCOORD</tt> is <tt>QCOORD_MIN</tt> (-2147483648) and the maximum
83value is <tt>QCOORD_MAX</tt> (2147483647).
84<p> The coordinates are accessed by the functions <a href="#x">x</a>() and <a href="#y">y</a>(); they
85can be set by <a href="#setX">setX</a>() and <a href="#setY">setY</a>() or by the reference functions <a href="#rx">rx</a>()
86and <a href="#ry">ry</a>().
87<p> Given a point <em>p</em>, the following statements are all equivalent:
88<pre>
89 p.setX( p.x() + 1 );
90 p += <a href="#QPoint">QPoint</a>( 1, 0 );
91 p.rx()++;
92 </pre>
93
94<p> A QPoint can also be used as a vector. Addition and subtraction
95of QPoints are defined as for vectors (each component is added
96separately). You can divide or multiply a QPoint by an <tt>int</tt> or a
97<tt>double</tt>. The function <a href="#manhattanLength">manhattanLength</a>() gives an inexpensive
98approximation of the length of the QPoint interpreted as a vector.
99<p> Example:
100<pre>
101 //QPoint oldPos is defined somewhere else
102 MyWidget::mouseMoveEvent( <a href="qmouseevent.html">QMouseEvent</a> *e )
103 {
104 QPoint vector = e-&gt;<a href="qmouseevent.html#pos">pos</a>() - oldPos;
105 if ( vector.<a href="#manhattanLength">manhattanLength</a>() &gt; 3 )
106 ... //mouse has moved more than 3 pixels since oldPos
107 }
108 </pre>
109
110<p> QPoints can be compared for equality or inequality, and they can
111be written to and read from a QStream.
112<p> <p>See also <a href="qpointarray.html">QPointArray</a>, <a href="qsize.html">QSize</a>, <a href="qrect.html">QRect</a>, <a href="graphics.html">Graphics Classes</a>, and <a href="images.html">Image Processing Classes</a>.
113
114<hr><h2>Member Function Documentation</h2>
115<h3 class=fn><a name="QPoint"></a>QPoint::QPoint ()
116</h3>
117
118<p> Constructs a point with coordinates (0, 0) (<a href="#isNull">isNull</a>() returns TRUE).
119
120<h3 class=fn><a name="QPoint-2"></a>QPoint::QPoint ( int&nbsp;xpos, int&nbsp;ypos )
121</h3>
122
123<p> Constructs a point with x value <em>xpos</em> and y value <em>ypos</em>.
124
125<h3 class=fn>bool <a name="isNull"></a>QPoint::isNull () const
126</h3>
127
128<p> Returns TRUE if both the x value and the y value are 0; otherwise
129returns FALSE.
130
131<h3 class=fn>int <a name="manhattanLength"></a>QPoint::manhattanLength () const
132</h3>
133Returns the sum of the absolute values of <a href="#x">x</a>() and <a href="#y">y</a>(),
134traditionally known as the "Manhattan length" of the vector from
135the origin to the point. The tradition arises because such
136distances apply to travelers who can only travel on a rectangular
137grid, like the streets of Manhattan.
138<p> This is a useful, and quick to calculate, approximation to the
139true length: sqrt(pow(x(),2)+pow(y(),2)).
140
141<h3 class=fn><a href="qpoint.html">QPoint</a>&nbsp;&amp; <a name="operator*-eq"></a>QPoint::operator*= ( int&nbsp;c )
142</h3>
143
144<p> Multiplies this point's x and y by <em>c</em>, and returns a reference
145to this point.
146<p> Example:
147<pre>
148 QPoint p( -1, 4 );
149 p *= 2; // p becomes (-2,8)
150 </pre>
151
152
153<h3 class=fn><a href="qpoint.html">QPoint</a>&nbsp;&amp; <a name="operator*-eq-2"></a>QPoint::operator*= ( double&nbsp;c )
154</h3>
155This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
156<p> Multiplies this point's x and y by <em>c</em>, and returns a reference
157to this point.
158<p> Example:
159<pre>
160 QPoint p( -1, 4 );
161 p *= 2.5; // p becomes (-3,10)
162 </pre>
163
164<p> Note that the result is truncated because points are held as
165integers.
166
167<h3 class=fn><a href="qpoint.html">QPoint</a>&nbsp;&amp; <a name="operator+-eq"></a>QPoint::operator+= ( const&nbsp;<a href="qpoint.html">QPoint</a>&nbsp;&amp;&nbsp;p )
168</h3>
169
170<p> Adds point <em>p</em> to this point and returns a reference to this
171point.
172<p> Example:
173<pre>
174 QPoint p( 3, 7 );
175 QPoint q( -1, 4 );
176 p += q; // p becomes (2,11)
177 </pre>
178
179
180<h3 class=fn><a href="qpoint.html">QPoint</a>&nbsp;&amp; <a name="operator--eq"></a>QPoint::operator-= ( const&nbsp;<a href="qpoint.html">QPoint</a>&nbsp;&amp;&nbsp;p )
181</h3>
182
183<p> Subtracts point <em>p</em> from this point and returns a reference to
184this point.
185<p> Example:
186<pre>
187 QPoint p( 3, 7 );
188 QPoint q( -1, 4 );
189 p -= q; // p becomes (4,3)
190 </pre>
191
192
193<h3 class=fn><a href="qpoint.html">QPoint</a>&nbsp;&amp; <a name="operator/-eq"></a>QPoint::operator/= ( int&nbsp;c )
194</h3>
195
196<p> Divides both x and y by <em>c</em>, and returns a reference to this
197point.
198<p> Example:
199<pre>
200 QPoint p( -2, 8 );
201 p /= 2; // p becomes (-1,4)
202 </pre>
203
204
205<h3 class=fn><a href="qpoint.html">QPoint</a>&nbsp;&amp; <a name="operator/-eq-2"></a>QPoint::operator/= ( double&nbsp;c )
206</h3>
207This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
208<p> Divides both x and y by <em>c</em>, and returns a reference to this
209point.
210<p> Example:
211<pre>
212 QPoint p( -3, 10 );
213 p /= 2.5; // p becomes (-1,4)
214 </pre>
215
216<p> Note that the result is truncated because points are held as
217integers.
218
219<h3 class=fn>QCOORD &amp; <a name="rx"></a>QPoint::rx ()
220</h3>
221
222<p> Returns a reference to the x coordinate of the point.
223<p> Using a reference makes it possible to directly manipulate x.
224<p> Example:
225<pre>
226 QPoint p( 1, 2 );
227 p.<a href="#rx">rx</a>()--; // p becomes (0, 2)
228 </pre>
229
230<p> <p>See also <a href="#ry">ry</a>().
231
232<h3 class=fn>QCOORD &amp; <a name="ry"></a>QPoint::ry ()
233</h3>
234
235<p> Returns a reference to the y coordinate of the point.
236<p> Using a reference makes it possible to directly manipulate y.
237<p> Example:
238<pre>
239 QPoint p( 1, 2 );
240 p.<a href="#ry">ry</a>()++; // p becomes (1, 3)
241 </pre>
242
243<p> <p>See also <a href="#rx">rx</a>().
244
245<h3 class=fn>void <a name="setX"></a>QPoint::setX ( int&nbsp;x )
246</h3>
247
248<p> Sets the x coordinate of the point to <em>x</em>.
249<p> <p>See also <a href="#x">x</a>() and <a href="#setY">setY</a>().
250
251<p>Example: <a href="tutorial1-14.html#x2422">t14/cannon.cpp</a>.
252<h3 class=fn>void <a name="setY"></a>QPoint::setY ( int&nbsp;y )
253</h3>
254
255<p> Sets the y coordinate of the point to <em>y</em>.
256<p> <p>See also <a href="#y">y</a>() and <a href="#setX">setX</a>().
257
258<p>Example: <a href="tutorial1-14.html#x2423">t14/cannon.cpp</a>.
259<h3 class=fn>int <a name="x"></a>QPoint::x () const
260</h3>
261
262<p> Returns the x coordinate of the point.
263<p> <p>See also <a href="#setX">setX</a>() and <a href="#y">y</a>().
264
265<p>Examples: <a href="canvas-example.html#x2944">canvas/canvas.cpp</a>, <a href="tutorial2-06.html#x2581">chart/canvasview.cpp</a>, <a href="dirview-example.html#x1696">dirview/dirview.cpp</a>, <a href="fileiconview-example.html#x864">fileiconview/qfileiconview.cpp</a>, <a href="helpsystem-example.html#x2679">helpsystem/tooltip.cpp</a>, <a href="life-example.html#x1893">life/life.cpp</a>, and <a href="tutorial1-14.html#x2424">t14/cannon.cpp</a>.
266<h3 class=fn>int <a name="y"></a>QPoint::y () const
267</h3>
268
269<p> Returns the y coordinate of the point.
270<p> <p>See also <a href="#setY">setY</a>() and <a href="#x">x</a>().
271
272<p>Examples: <a href="canvas-example.html#x2945">canvas/canvas.cpp</a>, <a href="tutorial2-06.html#x2582">chart/canvasview.cpp</a>, <a href="fileiconview-example.html#x865">fileiconview/qfileiconview.cpp</a>, <a href="helpsystem-example.html#x2680">helpsystem/tooltip.cpp</a>, <a href="life-example.html#x1894">life/life.cpp</a>, <a href="tutorial1-14.html#x2425">t14/cannon.cpp</a>, and <a href="themes-example.html#x230">themes/wood.cpp</a>.
273<hr><h2>Related Functions</h2>
274<h3 class=fn>bool <a name="operator!-eq"></a>operator!= ( const&nbsp;<a href="qpoint.html">QPoint</a>&nbsp;&amp;&nbsp;p1, const&nbsp;<a href="qpoint.html">QPoint</a>&nbsp;&amp;&nbsp;p2 )
275</h3>
276
277<p>
278<p> Returns TRUE if <em>p1</em> and <em>p2</em> are not equal; otherwise returns FALSE.
279
280<h3 class=fn>const&nbsp;<a href="qpoint.html">QPoint</a> <a name="operator*"></a>operator* ( const&nbsp;<a href="qpoint.html">QPoint</a>&nbsp;&amp;&nbsp;p, int&nbsp;c )
281</h3>
282
283<p>
284<p> Returns the QPoint formed by multiplying both components of <em>p</em>
285by <em>c</em>.
286
287<h3 class=fn>const&nbsp;<a href="qpoint.html">QPoint</a> <a name="operator*-2"></a>operator* ( int&nbsp;c, const&nbsp;<a href="qpoint.html">QPoint</a>&nbsp;&amp;&nbsp;p )
288</h3>
289This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
290<p>
291<p> Returns the QPoint formed by multiplying both components of <em>p</em>
292by <em>c</em>.
293
294<h3 class=fn>const&nbsp;<a href="qpoint.html">QPoint</a> <a name="operator*-3"></a>operator* ( const&nbsp;<a href="qpoint.html">QPoint</a>&nbsp;&amp;&nbsp;p, double&nbsp;c )
295</h3>
296This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
297<p>
298<p> Returns the QPoint formed by multiplying both components of <em>p</em>
299by <em>c</em>.
300<p> Note that the result is truncated because points are held as
301integers.
302
303<h3 class=fn>const&nbsp;<a href="qpoint.html">QPoint</a> <a name="operator*-4"></a>operator* ( double&nbsp;c, const&nbsp;<a href="qpoint.html">QPoint</a>&nbsp;&amp;&nbsp;p )
304</h3>
305This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
306<p>
307<p> Returns the QPoint formed by multiplying both components of <em>p</em>
308by <em>c</em>.
309<p> Note that the result is truncated because points are held as
310integers.
311
312<h3 class=fn>const&nbsp;<a href="qpoint.html">QPoint</a> <a name="operator+"></a>operator+ ( const&nbsp;<a href="qpoint.html">QPoint</a>&nbsp;&amp;&nbsp;p1, const&nbsp;<a href="qpoint.html">QPoint</a>&nbsp;&amp;&nbsp;p2 )
313</h3>
314
315<p>
316<p> Returns the sum of <em>p1</em> and <em>p2</em>; each component is added separately.
317
318<h3 class=fn>const&nbsp;<a href="qpoint.html">QPoint</a> <a name="operator-"></a>operator- ( const&nbsp;<a href="qpoint.html">QPoint</a>&nbsp;&amp;&nbsp;p1, const&nbsp;<a href="qpoint.html">QPoint</a>&nbsp;&amp;&nbsp;p2 )
319</h3>
320
321<p>
322<p> Returns <em>p2</em> subtracted from <em>p1</em>; each component is subtracted
323separately.
324
325<h3 class=fn>const&nbsp;<a href="qpoint.html">QPoint</a> <a name="operator--2"></a>operator- ( const&nbsp;<a href="qpoint.html">QPoint</a>&nbsp;&amp;&nbsp;p )
326</h3>
327This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
328<p>
329<p> Returns the QPoint formed by changing the sign of both components
330of <em>p</em>, equivalent to <tt>QPoint(0,0) - p</tt>.
331
332<h3 class=fn>const&nbsp;<a href="qpoint.html">QPoint</a> <a name="operator/"></a>operator/ ( const&nbsp;<a href="qpoint.html">QPoint</a>&nbsp;&amp;&nbsp;p, int&nbsp;c )
333</h3>
334
335<p>
336<p> Returns the QPoint formed by dividing both components of <em>p</em> by
337<em>c</em>.
338
339<h3 class=fn>const&nbsp;<a href="qpoint.html">QPoint</a> <a name="operator/-2"></a>operator/ ( const&nbsp;<a href="qpoint.html">QPoint</a>&nbsp;&amp;&nbsp;p, double&nbsp;c )
340</h3>
341This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
342<p>
343<p> Returns the QPoint formed by dividing both components of <em>p</em>
344by <em>c</em>.
345<p> Note that the result is truncated because points are held as
346integers.
347
348<h3 class=fn><a href="qdatastream.html">QDataStream</a>&nbsp;&amp; <a name="operator-lt-lt"></a>operator&lt;&lt; ( <a href="qdatastream.html">QDataStream</a>&nbsp;&amp;&nbsp;s, const&nbsp;<a href="qpoint.html">QPoint</a>&nbsp;&amp;&nbsp;p )
349</h3>
350
351<p> Writes point <em>p</em> to the stream <em>s</em> and returns a reference to
352the stream.
353<p> <p>See also <a href="datastreamformat.html">Format of the QDataStream operators</a>.
354
355<h3 class=fn>bool <a name="operator-eq-eq"></a>operator== ( const&nbsp;<a href="qpoint.html">QPoint</a>&nbsp;&amp;&nbsp;p1, const&nbsp;<a href="qpoint.html">QPoint</a>&nbsp;&amp;&nbsp;p2 )
356</h3>
357
358<p>
359<p> Returns TRUE if <em>p1</em> and <em>p2</em> are equal; otherwise returns FALSE.
360
361<h3 class=fn><a href="qdatastream.html">QDataStream</a>&nbsp;&amp; <a name="operator-gt-gt"></a>operator&gt;&gt; ( <a href="qdatastream.html">QDataStream</a>&nbsp;&amp;&nbsp;s, <a href="qpoint.html">QPoint</a>&nbsp;&amp;&nbsp;p )
362</h3>
363
364<p> Reads a QPoint from the stream <em>s</em> into point <em>p</em> and returns a
365reference to the stream.
366<p> <p>See also <a href="datastreamformat.html">Format of the QDataStream operators</a>.
367
368<!-- eof -->
369<hr><p>
370This file is part of the <a href="index.html">Qt toolkit</a>.
371Copyright &copy; 1995-2007
372<a href="http://www.trolltech.com/">Trolltech</a>. All Rights Reserved.<p><address><hr><div align=center>
373<table width=100% cellspacing=0 border=0><tr>
374<td>Copyright &copy; 2007
375<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
376<td align=right><div align=right>Qt 3.3.8</div>
377</table></div></address></body>
378</html>
Note: See TracBrowser for help on using the repository browser.