qwt_point_polar.cpp
Go to the documentation of this file.
1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
2  * QwtPolar Widget Library
3  * Copyright (C) 2008 Uwe Rathmann
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the Qwt License, Version 1.0
7  *****************************************************************************/
8 
9 #include "qwt_point_polar.h"
10 #include "qwt_math.h"
11 
12 #if QT_VERSION < 0x040601
13 #define qAtan2(y, x) ::atan2(y, x)
14 #endif
15 
22 QwtPointPolar::QwtPointPolar( const QPointF &p )
23 {
24  d_radius = qSqrt( qwtSqr( p.x() ) + qwtSqr( p.y() ) );
25  d_azimuth = qAtan2( p.y(), p.x() );
26 }
27 
32 void QwtPointPolar::setPoint( const QPointF &p )
33 {
34  d_radius = qSqrt( qwtSqr( p.x() ) + qwtSqr( p.y() ) );
35  d_azimuth = qAtan2( p.y(), p.x() );
36 }
37 
46 QPointF QwtPointPolar::toPoint() const
47 {
48  if ( d_radius <= 0.0 )
49  return QPointF( 0.0, 0.0 );
50 
51  const double x = d_radius * qCos( d_azimuth );
52  const double y = d_radius * qSin( d_azimuth );
53 
54  return QPointF( x, y );
55 }
56 
68 bool QwtPointPolar::operator==( const QwtPointPolar &other ) const
69 {
70  return d_radius == other.d_radius && d_azimuth == other.d_azimuth;
71 }
72 
83 bool QwtPointPolar::operator!=( const QwtPointPolar &other ) const
84 {
85  return d_radius != other.d_radius || d_azimuth != other.d_azimuth;
86 }
87 
97 {
98  const double radius = qMax( d_radius, 0.0 );
99 
100  double azimuth = d_azimuth;
101  if ( azimuth < -2.0 * M_PI || azimuth >= 2 * M_PI )
102  azimuth = ::fmod( d_azimuth, 2 * M_PI );
103 
104  if ( azimuth < 0.0 )
105  azimuth += 2 * M_PI;
106 
107  return QwtPointPolar( azimuth, radius );
108 }
109 
110 #ifndef QT_NO_DEBUG_STREAM
111 
112 QDebug operator<<( QDebug debug, const QwtPointPolar &point )
113 {
114  debug.nospace() << "QwtPointPolar("
115  << point.azimuth() << "," << point.radius() << ")";
116 
117  return debug.space();
118 }
119 
120 #endif
121 
A point in polar coordinates.
bool operator!=(const QwtPointPolar &) const
double radius() const
Returns the radius.
double azimuth() const
Returns the azimuth.
TFSIMD_FORCE_INLINE const tfScalar & y() const
void setPoint(const QPointF &)
QPointF toPoint() const
QDebug operator<<(QDebug debug, const QwtPointPolar &point)
TFSIMD_FORCE_INLINE const tfScalar & x() const
double qwtSqr(double x)
Return the square of a number.
Definition: qwt_math.h:88
bool operator==(const QwtPointPolar &) const
Compare 2 points.
#define qAtan2(y, x)
QwtPointPolar normalized() const


plotjuggler
Author(s): Davide Faconti
autogenerated on Sat Jul 6 2019 03:44:17