Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "qwt_point_polar.h"
00010 #include "qwt_math.h"
00011
00012 #if QT_VERSION < 0x040601
00013 #define qAtan2(y, x) ::atan2(y, x)
00014 #endif
00015
00022 QwtPointPolar::QwtPointPolar( const QPointF &p )
00023 {
00024 d_radius = qSqrt( qwtSqr( p.x() ) + qwtSqr( p.y() ) );
00025 d_azimuth = qAtan2( p.y(), p.x() );
00026 }
00027
00032 void QwtPointPolar::setPoint( const QPointF &p )
00033 {
00034 d_radius = qSqrt( qwtSqr( p.x() ) + qwtSqr( p.y() ) );
00035 d_azimuth = qAtan2( p.y(), p.x() );
00036 }
00037
00046 QPointF QwtPointPolar::toPoint() const
00047 {
00048 if ( d_radius <= 0.0 )
00049 return QPointF( 0.0, 0.0 );
00050
00051 const double x = d_radius * qCos( d_azimuth );
00052 const double y = d_radius * qSin( d_azimuth );
00053
00054 return QPointF( x, y );
00055 }
00056
00068 bool QwtPointPolar::operator==( const QwtPointPolar &other ) const
00069 {
00070 return d_radius == other.d_radius && d_azimuth == other.d_azimuth;
00071 }
00072
00083 bool QwtPointPolar::operator!=( const QwtPointPolar &other ) const
00084 {
00085 return d_radius != other.d_radius || d_azimuth != other.d_azimuth;
00086 }
00087
00096 QwtPointPolar QwtPointPolar::normalized() const
00097 {
00098 const double radius = qMax( d_radius, 0.0 );
00099
00100 double azimuth = d_azimuth;
00101 if ( azimuth < -2.0 * M_PI || azimuth >= 2 * M_PI )
00102 azimuth = ::fmod( d_azimuth, 2 * M_PI );
00103
00104 if ( azimuth < 0.0 )
00105 azimuth += 2 * M_PI;
00106
00107 return QwtPointPolar( azimuth, radius );
00108 }
00109
00110 #ifndef QT_NO_DEBUG_STREAM
00111
00112 QDebug operator<<( QDebug debug, const QwtPointPolar &point )
00113 {
00114 debug.nospace() << "QwtPointPolar("
00115 << point.azimuth() << "," << point.radius() << ")";
00116
00117 return debug.space();
00118 }
00119
00120 #endif
00121