You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
qt3/doc/html/qpoint.html

379 lines
17 KiB

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/src/kernel/qpoint.cpp:42 -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>QPoint Class</title>
<style type="text/css"><!--
fn { margin-left: 1cm; text-indent: -1cm; }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
body { background: #ffffff; color: black; }
--></style>
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr bgcolor="#E5E5E5">
<td valign=center>
<a href="index.html">
<font color="#004faf">Home</font></a>
| <a href="classes.html">
<font color="#004faf">All&nbsp;Classes</font></a>
| <a href="mainclasses.html">
<font color="#004faf">Main&nbsp;Classes</font></a>
| <a href="annotated.html">
<font color="#004faf">Annotated</font></a>
| <a href="groups.html">
<font color="#004faf">Grouped&nbsp;Classes</font></a>
| <a href="functions.html">
<font color="#004faf">Functions</font></a>
</td>
<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>
<p>The QPoint class defines a point in the plane.
<a href="#details">More...</a>
<p><tt>#include &lt;<a href="qpoint-h.html">qpoint.h</a>&gt;</tt>
<p><a href="qpoint-members.html">List of all member functions.</a>
<h2>Public Members</h2>
<ul>
<li class=fn><a href="#QPoint"><b>QPoint</b></a> ()</li>
<li class=fn><a href="#QPoint-2"><b>QPoint</b></a> ( int&nbsp;xpos, int&nbsp;ypos )</li>
<li class=fn>bool <a href="#isNull"><b>isNull</b></a> () const</li>
<li class=fn>int <a href="#x"><b>x</b></a> () const</li>
<li class=fn>int <a href="#y"><b>y</b></a> () const</li>
<li class=fn>void <a href="#setX"><b>setX</b></a> ( int&nbsp;x )</li>
<li class=fn>void <a href="#setY"><b>setY</b></a> ( int&nbsp;y )</li>
<li class=fn>int <a href="#manhattanLength"><b>manhattanLength</b></a> () const</li>
<li class=fn>QCOORD &amp; <a href="#rx"><b>rx</b></a> ()</li>
<li class=fn>QCOORD &amp; <a href="#ry"><b>ry</b></a> ()</li>
<li class=fn>QPoint &amp; <a href="#operator+-eq"><b>operator+=</b></a> ( const&nbsp;QPoint&nbsp;&amp;&nbsp;p )</li>
<li class=fn>QPoint &amp; <a href="#operator--eq"><b>operator-=</b></a> ( const&nbsp;QPoint&nbsp;&amp;&nbsp;p )</li>
<li class=fn>QPoint &amp; <a href="#operator*-eq"><b>operator*=</b></a> ( int&nbsp;c )</li>
<li class=fn>QPoint &amp; <a href="#operator*-eq-2"><b>operator*=</b></a> ( double&nbsp;c )</li>
<li class=fn>QPoint &amp; <a href="#operator/-eq"><b>operator/=</b></a> ( int&nbsp;c )</li>
<li class=fn>QPoint &amp; <a href="#operator/-eq-2"><b>operator/=</b></a> ( double&nbsp;c )</li>
</ul>
<h2>Related Functions</h2>
<ul>
<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>
<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>
<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>
<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>
<li class=fn>const QPoint <a href="#operator*"><b>operator*</b></a> ( const&nbsp;QPoint&nbsp;&amp;&nbsp;p, int&nbsp;c )</li>
<li class=fn>const QPoint <a href="#operator*-2"><b>operator*</b></a> ( int&nbsp;c, const&nbsp;QPoint&nbsp;&amp;&nbsp;p )</li>
<li class=fn>const QPoint <a href="#operator*-3"><b>operator*</b></a> ( const&nbsp;QPoint&nbsp;&amp;&nbsp;p, double&nbsp;c )</li>
<li class=fn>const QPoint <a href="#operator*-4"><b>operator*</b></a> ( double&nbsp;c, const&nbsp;QPoint&nbsp;&amp;&nbsp;p )</li>
<li class=fn>const QPoint <a href="#operator--2"><b>operator-</b></a> ( const&nbsp;QPoint&nbsp;&amp;&nbsp;p )</li>
<li class=fn>const QPoint <a href="#operator/"><b>operator/</b></a> ( const&nbsp;QPoint&nbsp;&amp;&nbsp;p, int&nbsp;c )</li>
<li class=fn>const QPoint <a href="#operator/-2"><b>operator/</b></a> ( const&nbsp;QPoint&nbsp;&amp;&nbsp;p, double&nbsp;c )</li>
<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>
<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>
</ul>
<hr><a name="details"></a><h2>Detailed Description</h2>
The QPoint class defines a point in the plane.
<p>
<p> A point is specified by an x coordinate and a y coordinate.
<p> The coordinate type is <tt>QCOORD</tt> (a 32-bit integer). The minimum
value of <tt>QCOORD</tt> is <tt>QCOORD_MIN</tt> (-2147483648) and the maximum
value is <tt>QCOORD_MAX</tt> (2147483647).
<p> The coordinates are accessed by the functions <a href="#x">x</a>() and <a href="#y">y</a>(); they
can be set by <a href="#setX">setX</a>() and <a href="#setY">setY</a>() or by the reference functions <a href="#rx">rx</a>()
and <a href="#ry">ry</a>().
<p> Given a point <em>p</em>, the following statements are all equivalent:
<pre>
p.setX( p.x() + 1 );
p += <a href="#QPoint">QPoint</a>( 1, 0 );
p.rx()++;
</pre>
<p> A QPoint can also be used as a vector. Addition and subtraction
of QPoints are defined as for vectors (each component is added
separately). You can divide or multiply a QPoint by an <tt>int</tt> or a
<tt>double</tt>. The function <a href="#manhattanLength">manhattanLength</a>() gives an inexpensive
approximation of the length of the QPoint interpreted as a vector.
<p> Example:
<pre>
//QPoint oldPos is defined somewhere else
MyWidget::mouseMoveEvent( <a href="qmouseevent.html">QMouseEvent</a> *e )
{
QPoint vector = e-&gt;<a href="qmouseevent.html#pos">pos</a>() - oldPos;
if ( vector.<a href="#manhattanLength">manhattanLength</a>() &gt; 3 )
... //mouse has moved more than 3 pixels since oldPos
}
</pre>
<p> QPoints can be compared for equality or inequality, and they can
be written to and read from a QStream.
<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>.
<hr><h2>Member Function Documentation</h2>
<h3 class=fn><a name="QPoint"></a>QPoint::QPoint ()
</h3>
<p> Constructs a point with coordinates (0, 0) (<a href="#isNull">isNull</a>() returns TRUE).
<h3 class=fn><a name="QPoint-2"></a>QPoint::QPoint ( int&nbsp;xpos, int&nbsp;ypos )
</h3>
<p> Constructs a point with x value <em>xpos</em> and y value <em>ypos</em>.
<h3 class=fn>bool <a name="isNull"></a>QPoint::isNull () const
</h3>
<p> Returns TRUE if both the x value and the y value are 0; otherwise
returns FALSE.
<h3 class=fn>int <a name="manhattanLength"></a>QPoint::manhattanLength () const
</h3>
Returns the sum of the absolute values of <a href="#x">x</a>() and <a href="#y">y</a>(),
traditionally known as the "Manhattan length" of the vector from
the origin to the point. The tradition arises because such
distances apply to travelers who can only travel on a rectangular
grid, like the streets of Manhattan.
<p> This is a useful, and quick to calculate, approximation to the
true length: sqrt(pow(x(),2)+pow(y(),2)).
<h3 class=fn><a href="qpoint.html">QPoint</a>&nbsp;&amp; <a name="operator*-eq"></a>QPoint::operator*= ( int&nbsp;c )
</h3>
<p> Multiplies this point's x and y by <em>c</em>, and returns a reference
to this point.
<p> Example:
<pre>
QPoint p( -1, 4 );
p *= 2; // p becomes (-2,8)
</pre>
<h3 class=fn><a href="qpoint.html">QPoint</a>&nbsp;&amp; <a name="operator*-eq-2"></a>QPoint::operator*= ( double&nbsp;c )
</h3>
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
<p> Multiplies this point's x and y by <em>c</em>, and returns a reference
to this point.
<p> Example:
<pre>
QPoint p( -1, 4 );
p *= 2.5; // p becomes (-3,10)
</pre>
<p> Note that the result is truncated because points are held as
integers.
<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 )
</h3>
<p> Adds point <em>p</em> to this point and returns a reference to this
point.
<p> Example:
<pre>
QPoint p( 3, 7 );
QPoint q( -1, 4 );
p += q; // p becomes (2,11)
</pre>
<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 )
</h3>
<p> Subtracts point <em>p</em> from this point and returns a reference to
this point.
<p> Example:
<pre>
QPoint p( 3, 7 );
QPoint q( -1, 4 );
p -= q; // p becomes (4,3)
</pre>
<h3 class=fn><a href="qpoint.html">QPoint</a>&nbsp;&amp; <a name="operator/-eq"></a>QPoint::operator/= ( int&nbsp;c )
</h3>
<p> Divides both x and y by <em>c</em>, and returns a reference to this
point.
<p> Example:
<pre>
QPoint p( -2, 8 );
p /= 2; // p becomes (-1,4)
</pre>
<h3 class=fn><a href="qpoint.html">QPoint</a>&nbsp;&amp; <a name="operator/-eq-2"></a>QPoint::operator/= ( double&nbsp;c )
</h3>
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
<p> Divides both x and y by <em>c</em>, and returns a reference to this
point.
<p> Example:
<pre>
QPoint p( -3, 10 );
p /= 2.5; // p becomes (-1,4)
</pre>
<p> Note that the result is truncated because points are held as
integers.
<h3 class=fn>QCOORD &amp; <a name="rx"></a>QPoint::rx ()
</h3>
<p> Returns a reference to the x coordinate of the point.
<p> Using a reference makes it possible to directly manipulate x.
<p> Example:
<pre>
QPoint p( 1, 2 );
p.<a href="#rx">rx</a>()--; // p becomes (0, 2)
</pre>
<p> <p>See also <a href="#ry">ry</a>().
<h3 class=fn>QCOORD &amp; <a name="ry"></a>QPoint::ry ()
</h3>
<p> Returns a reference to the y coordinate of the point.
<p> Using a reference makes it possible to directly manipulate y.
<p> Example:
<pre>
QPoint p( 1, 2 );
p.<a href="#ry">ry</a>()++; // p becomes (1, 3)
</pre>
<p> <p>See also <a href="#rx">rx</a>().
<h3 class=fn>void <a name="setX"></a>QPoint::setX ( int&nbsp;x )
</h3>
<p> Sets the x coordinate of the point to <em>x</em>.
<p> <p>See also <a href="#x">x</a>() and <a href="#setY">setY</a>().
<p>Example: <a href="tutorial1-14.html#x2422">t14/cannon.cpp</a>.
<h3 class=fn>void <a name="setY"></a>QPoint::setY ( int&nbsp;y )
</h3>
<p> Sets the y coordinate of the point to <em>y</em>.
<p> <p>See also <a href="#y">y</a>() and <a href="#setX">setX</a>().
<p>Example: <a href="tutorial1-14.html#x2423">t14/cannon.cpp</a>.
<h3 class=fn>int <a name="x"></a>QPoint::x () const
</h3>
<p> Returns the x coordinate of the point.
<p> <p>See also <a href="#setX">setX</a>() and <a href="#y">y</a>().
<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>.
<h3 class=fn>int <a name="y"></a>QPoint::y () const
</h3>
<p> Returns the y coordinate of the point.
<p> <p>See also <a href="#setY">setY</a>() and <a href="#x">x</a>().
<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>.
<hr><h2>Related Functions</h2>
<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 )
</h3>
<p>
<p> Returns TRUE if <em>p1</em> and <em>p2</em> are not equal; otherwise returns FALSE.
<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 )
</h3>
<p>
<p> Returns the QPoint formed by multiplying both components of <em>p</em>
by <em>c</em>.
<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 )
</h3>
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
<p>
<p> Returns the QPoint formed by multiplying both components of <em>p</em>
by <em>c</em>.
<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 )
</h3>
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
<p>
<p> Returns the QPoint formed by multiplying both components of <em>p</em>
by <em>c</em>.
<p> Note that the result is truncated because points are held as
integers.
<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 )
</h3>
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
<p>
<p> Returns the QPoint formed by multiplying both components of <em>p</em>
by <em>c</em>.
<p> Note that the result is truncated because points are held as
integers.
<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 )
</h3>
<p>
<p> Returns the sum of <em>p1</em> and <em>p2</em>; each component is added separately.
<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 )
</h3>
<p>
<p> Returns <em>p2</em> subtracted from <em>p1</em>; each component is subtracted
separately.
<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 )
</h3>
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
<p>
<p> Returns the QPoint formed by changing the sign of both components
of <em>p</em>, equivalent to <tt>QPoint(0,0) - p</tt>.
<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 )
</h3>
<p>
<p> Returns the QPoint formed by dividing both components of <em>p</em> by
<em>c</em>.
<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 )
</h3>
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
<p>
<p> Returns the QPoint formed by dividing both components of <em>p</em>
by <em>c</em>.
<p> Note that the result is truncated because points are held as
integers.
<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 )
</h3>
<p> Writes point <em>p</em> to the stream <em>s</em> and returns a reference to
the stream.
<p> <p>See also <a href="datastreamformat.html">Format of the QDataStream operators</a>.
<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 )
</h3>
<p>
<p> Returns TRUE if <em>p1</em> and <em>p2</em> are equal; otherwise returns FALSE.
<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 )
</h3>
<p> Reads a QPoint from the stream <em>s</em> into point <em>p</em> and returns a
reference to the stream.
<p> <p>See also <a href="datastreamformat.html">Format of the QDataStream operators</a>.
<!-- eof -->
<hr><p>
This file is part of the <a href="index.html">Qt toolkit</a>.
Copyright &copy; 1995-2007
<a href="http://www.trolltech.com/">Trolltech</a>. All Rights Reserved.<p><address><hr><div align=center>
<table width=100% cellspacing=0 border=0><tr>
<td>Copyright &copy; 2007
<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
<td align=right><div align=right>Qt 3.3.8</div>
</table></div></address></body>
</html>