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.
tqt3/doc/html/ntqpoint.html

379 lines
18 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>TQPoint 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>TQPoint Class Reference</h1>
<p>The TQPoint class defines a point in the plane.
<a href="#details">More...</a>
<p><tt>#include &lt;<a href="qpoint-h.html">ntqpoint.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="#TQPoint"><b>TQPoint</b></a> ()</li>
<li class=fn><a href="#TQPoint-2"><b>TQPoint</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>TQCOORD &amp; <a href="#rx"><b>rx</b></a> ()</li>
<li class=fn>TQCOORD &amp; <a href="#ry"><b>ry</b></a> ()</li>
<li class=fn>TQPoint &amp; <a href="#operator+-eq"><b>operator+=</b></a> ( const&nbsp;TQPoint&nbsp;&amp;&nbsp;p )</li>
<li class=fn>TQPoint &amp; <a href="#operator--eq"><b>operator-=</b></a> ( const&nbsp;TQPoint&nbsp;&amp;&nbsp;p )</li>
<li class=fn>TQPoint &amp; <a href="#operator*-eq"><b>operator*=</b></a> ( int&nbsp;c )</li>
<li class=fn>TQPoint &amp; <a href="#operator*-eq-2"><b>operator*=</b></a> ( double&nbsp;c )</li>
<li class=fn>TQPoint &amp; <a href="#operator/-eq"><b>operator/=</b></a> ( int&nbsp;c )</li>
<li class=fn>TQPoint &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;TQPoint&nbsp;&amp;&nbsp;p1, const&nbsp;TQPoint&nbsp;&amp;&nbsp;p2 )</li>
<li class=fn>bool <a href="#operator!-eq"><b>operator!=</b></a> ( const&nbsp;TQPoint&nbsp;&amp;&nbsp;p1, const&nbsp;TQPoint&nbsp;&amp;&nbsp;p2 )</li>
<li class=fn>const TQPoint <a href="#operator+"><b>operator+</b></a> ( const&nbsp;TQPoint&nbsp;&amp;&nbsp;p1, const&nbsp;TQPoint&nbsp;&amp;&nbsp;p2 )</li>
<li class=fn>const TQPoint <a href="#operator-"><b>operator-</b></a> ( const&nbsp;TQPoint&nbsp;&amp;&nbsp;p1, const&nbsp;TQPoint&nbsp;&amp;&nbsp;p2 )</li>
<li class=fn>const TQPoint <a href="#operator*"><b>operator*</b></a> ( const&nbsp;TQPoint&nbsp;&amp;&nbsp;p, int&nbsp;c )</li>
<li class=fn>const TQPoint <a href="#operator*-2"><b>operator*</b></a> ( int&nbsp;c, const&nbsp;TQPoint&nbsp;&amp;&nbsp;p )</li>
<li class=fn>const TQPoint <a href="#operator*-3"><b>operator*</b></a> ( const&nbsp;TQPoint&nbsp;&amp;&nbsp;p, double&nbsp;c )</li>
<li class=fn>const TQPoint <a href="#operator*-4"><b>operator*</b></a> ( double&nbsp;c, const&nbsp;TQPoint&nbsp;&amp;&nbsp;p )</li>
<li class=fn>const TQPoint <a href="#operator--2"><b>operator-</b></a> ( const&nbsp;TQPoint&nbsp;&amp;&nbsp;p )</li>
<li class=fn>const TQPoint <a href="#operator/"><b>operator/</b></a> ( const&nbsp;TQPoint&nbsp;&amp;&nbsp;p, int&nbsp;c )</li>
<li class=fn>const TQPoint <a href="#operator/-2"><b>operator/</b></a> ( const&nbsp;TQPoint&nbsp;&amp;&nbsp;p, double&nbsp;c )</li>
<li class=fn>TQDataStream &amp; <a href="#operator-lt-lt"><b>operator&lt;&lt;</b></a> ( TQDataStream&nbsp;&amp;&nbsp;s, const&nbsp;TQPoint&nbsp;&amp;&nbsp;p )</li>
<li class=fn>TQDataStream &amp; <a href="#operator-gt-gt"><b>operator&gt;&gt;</b></a> ( TQDataStream&nbsp;&amp;&nbsp;s, TQPoint&nbsp;&amp;&nbsp;p )</li>
</ul>
<hr><a name="details"></a><h2>Detailed Description</h2>
The TQPoint 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>TQCOORD</tt> (a 32-bit integer). The minimum
value of <tt>TQCOORD</tt> is <tt>TQCOORD_MIN</tt> (-2147483648) and the maximum
value is <tt>TQCOORD_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="#TQPoint">TQPoint</a>( 1, 0 );
p.rx()++;
</pre>
<p> A TQPoint can also be used as a vector. Addition and subtraction
of TQPoints are defined as for vectors (each component is added
separately). You can divide or multiply a TQPoint 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 TQPoint interpreted as a vector.
<p> Example:
<pre>
//TQPoint oldPos is defined somewhere else
MyWidget::mouseMoveEvent( <a href="qmouseevent.html">TQMouseEvent</a> *e )
{
TQPoint 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> TQPoints can be compared for equality or inequality, and they can
be written to and read from a TQStream.
<p> <p>See also <a href="ntqpointarray.html">TQPointArray</a>, <a href="ntqsize.html">TQSize</a>, <a href="ntqrect.html">TQRect</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="TQPoint"></a>TQPoint::TQPoint ()
</h3>
<p> Constructs a point with coordinates (0, 0) (<a href="#isNull">isNull</a>() returns TRUE).
<h3 class=fn><a name="TQPoint-2"></a>TQPoint::TQPoint ( 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>TQPoint::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>TQPoint::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="ntqpoint.html">TQPoint</a>&nbsp;&amp; <a name="operator*-eq"></a>TQPoint::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>
TQPoint p( -1, 4 );
p *= 2; // p becomes (-2,8)
</pre>
<h3 class=fn><a href="ntqpoint.html">TQPoint</a>&nbsp;&amp; <a name="operator*-eq-2"></a>TQPoint::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>
TQPoint 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="ntqpoint.html">TQPoint</a>&nbsp;&amp; <a name="operator+-eq"></a>TQPoint::operator+= ( const&nbsp;<a href="ntqpoint.html">TQPoint</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>
TQPoint p( 3, 7 );
TQPoint q( -1, 4 );
p += q; // p becomes (2,11)
</pre>
<h3 class=fn><a href="ntqpoint.html">TQPoint</a>&nbsp;&amp; <a name="operator--eq"></a>TQPoint::operator-= ( const&nbsp;<a href="ntqpoint.html">TQPoint</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>
TQPoint p( 3, 7 );
TQPoint q( -1, 4 );
p -= q; // p becomes (4,3)
</pre>
<h3 class=fn><a href="ntqpoint.html">TQPoint</a>&nbsp;&amp; <a name="operator/-eq"></a>TQPoint::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>
TQPoint p( -2, 8 );
p /= 2; // p becomes (-1,4)
</pre>
<h3 class=fn><a href="ntqpoint.html">TQPoint</a>&nbsp;&amp; <a name="operator/-eq-2"></a>TQPoint::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>
TQPoint 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>TQCOORD &amp; <a name="rx"></a>TQPoint::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>
TQPoint 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>TQCOORD &amp; <a name="ry"></a>TQPoint::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>
TQPoint 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>TQPoint::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>TQPoint::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>TQPoint::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>TQPoint::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="ntqpoint.html">TQPoint</a>&nbsp;&amp;&nbsp;p1, const&nbsp;<a href="ntqpoint.html">TQPoint</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="ntqpoint.html">TQPoint</a> <a name="operator*"></a>operator* ( const&nbsp;<a href="ntqpoint.html">TQPoint</a>&nbsp;&amp;&nbsp;p, int&nbsp;c )
</h3>
<p>
<p> Returns the TQPoint formed by multiplying both components of <em>p</em>
by <em>c</em>.
<h3 class=fn>const&nbsp;<a href="ntqpoint.html">TQPoint</a> <a name="operator*-2"></a>operator* ( int&nbsp;c, const&nbsp;<a href="ntqpoint.html">TQPoint</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 TQPoint formed by multiplying both components of <em>p</em>
by <em>c</em>.
<h3 class=fn>const&nbsp;<a href="ntqpoint.html">TQPoint</a> <a name="operator*-3"></a>operator* ( const&nbsp;<a href="ntqpoint.html">TQPoint</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 TQPoint 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="ntqpoint.html">TQPoint</a> <a name="operator*-4"></a>operator* ( double&nbsp;c, const&nbsp;<a href="ntqpoint.html">TQPoint</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 TQPoint 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="ntqpoint.html">TQPoint</a> <a name="operator+"></a>operator+ ( const&nbsp;<a href="ntqpoint.html">TQPoint</a>&nbsp;&amp;&nbsp;p1, const&nbsp;<a href="ntqpoint.html">TQPoint</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="ntqpoint.html">TQPoint</a> <a name="operator-"></a>operator- ( const&nbsp;<a href="ntqpoint.html">TQPoint</a>&nbsp;&amp;&nbsp;p1, const&nbsp;<a href="ntqpoint.html">TQPoint</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="ntqpoint.html">TQPoint</a> <a name="operator--2"></a>operator- ( const&nbsp;<a href="ntqpoint.html">TQPoint</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 TQPoint formed by changing the sign of both components
of <em>p</em>, equivalent to <tt>TQPoint(0,0) - p</tt>.
<h3 class=fn>const&nbsp;<a href="ntqpoint.html">TQPoint</a> <a name="operator/"></a>operator/ ( const&nbsp;<a href="ntqpoint.html">TQPoint</a>&nbsp;&amp;&nbsp;p, int&nbsp;c )
</h3>
<p>
<p> Returns the TQPoint formed by dividing both components of <em>p</em> by
<em>c</em>.
<h3 class=fn>const&nbsp;<a href="ntqpoint.html">TQPoint</a> <a name="operator/-2"></a>operator/ ( const&nbsp;<a href="ntqpoint.html">TQPoint</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 TQPoint 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="ntqdatastream.html">TQDataStream</a>&nbsp;&amp; <a name="operator-lt-lt"></a>operator&lt;&lt; ( <a href="ntqdatastream.html">TQDataStream</a>&nbsp;&amp;&nbsp;s, const&nbsp;<a href="ntqpoint.html">TQPoint</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 TQDataStream operators</a>.
<h3 class=fn>bool <a name="operator-eq-eq"></a>operator== ( const&nbsp;<a href="ntqpoint.html">TQPoint</a>&nbsp;&amp;&nbsp;p1, const&nbsp;<a href="ntqpoint.html">TQPoint</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="ntqdatastream.html">TQDataStream</a>&nbsp;&amp; <a name="operator-gt-gt"></a>operator&gt;&gt; ( <a href="ntqdatastream.html">TQDataStream</a>&nbsp;&amp;&nbsp;s, <a href="ntqpoint.html">TQPoint</a>&nbsp;&amp;&nbsp;p )
</h3>
<p> Reads a TQPoint 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 TQDataStream operators</a>.
<!-- eof -->
<hr><p>
This file is part of the <a href="index.html">TQt 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>TQt 3.3.8</div>
</table></div></address></body>
</html>