qwt_point_polar.cpp
Go to the documentation of this file.
1 /******************************************************************************
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 >= 0x050200
13 
14 static QwtPointPolar qwtPointToPolar( const QPointF& point )
15 {
16  return QwtPointPolar( point );
17 }
18 
19 #endif
20 
21 namespace
22 {
23  static const struct RegisterQwtPointPolar
24  {
25  inline RegisterQwtPointPolar()
26  {
27  qRegisterMetaType< QwtPointPolar >();
28 
29 #if QT_VERSION >= 0x050200
30  QMetaType::registerConverter< QPointF, QwtPointPolar >( qwtPointToPolar );
31  QMetaType::registerConverter< QwtPointPolar, QPointF >( &QwtPointPolar::toPoint );
32 #endif
33  }
34 
35  } qwtRegisterQwtPointPolar;
36 }
37 
44 QwtPointPolar::QwtPointPolar( const QPointF& p )
45 {
46  m_radius = std::sqrt( qwtSqr( p.x() ) + qwtSqr( p.y() ) );
47  m_azimuth = std::atan2( p.y(), p.x() );
48 }
49 
54 void QwtPointPolar::setPoint( const QPointF& p )
55 {
56  m_radius = std::sqrt( qwtSqr( p.x() ) + qwtSqr( p.y() ) );
57  m_azimuth = std::atan2( p.y(), p.x() );
58 }
59 
68 QPointF QwtPointPolar::toPoint() const
69 {
70  if ( m_radius <= 0.0 )
71  return QPointF( 0.0, 0.0 );
72 
73  const double x = m_radius * std::cos( m_azimuth );
74  const double y = m_radius * std::sin( m_azimuth );
75 
76  return QPointF( x, y );
77 }
78 
90 bool QwtPointPolar::operator==( const QwtPointPolar& other ) const
91 {
92  return m_radius == other.m_radius && m_azimuth == other.m_azimuth;
93 }
94 
105 bool QwtPointPolar::operator!=( const QwtPointPolar& other ) const
106 {
107  return m_radius != other.m_radius || m_azimuth != other.m_azimuth;
108 }
109 
119 {
120  const double radius = qwtMaxF( m_radius, 0.0 );
121 
122  double azimuth = m_azimuth;
123  if ( azimuth < -2.0 * M_PI || azimuth >= 2 * M_PI )
124  azimuth = std::fmod( m_azimuth, 2 * M_PI );
125 
126  if ( azimuth < 0.0 )
127  azimuth += 2 * M_PI;
128 
129  return QwtPointPolar( azimuth, radius );
130 }
131 
132 #ifndef QT_NO_DEBUG_STREAM
133 
134 #include <qdebug.h>
135 
136 QDebug operator<<( QDebug debug, const QwtPointPolar& point )
137 {
138  debug.nospace() << "QwtPointPolar("
139  << point.azimuth() << "," << point.radius() << ")";
140 
141  return debug.space();
142 }
143 
144 #endif
145 
qwtSqr
double qwtSqr(double x)
Return the square of a number.
Definition: qwt_math.h:195
QwtPointPolar::normalized
QwtPointPolar normalized() const
Definition: qwt_point_polar.cpp:118
QwtPointPolar::m_radius
double m_radius
Definition: qwt_point_polar.h:57
mqtt_test_proto.x
x
Definition: mqtt_test_proto.py:34
qwt_math.h
QwtPointPolar
A point in polar coordinates.
Definition: qwt_point_polar.h:28
mqtt_test_proto.y
y
Definition: mqtt_test_proto.py:35
operator<<
QDebug operator<<(QDebug debug, const QwtPointPolar &point)
Definition: qwt_point_polar.cpp:136
M_PI
#define M_PI
Definition: qwt_math.h:56
QwtPointPolar::azimuth
double azimuth() const
Returns the azimuth.
Definition: qwt_point_polar.h:108
qwtMaxF
QWT_CONSTEXPR float qwtMaxF(float a, float b)
Definition: qwt_math.h:127
QwtPointPolar::toPoint
QPointF toPoint() const
Definition: qwt_point_polar.cpp:68
qwt_point_polar.h
QwtPointPolar::operator!=
bool operator!=(const QwtPointPolar &) const
Definition: qwt_point_polar.cpp:105
QwtPointPolar::m_azimuth
double m_azimuth
Definition: qwt_point_polar.h:56
QwtPointPolar::setPoint
void setPoint(const QPointF &)
Definition: qwt_point_polar.cpp:54
QwtPointPolar::radius
double radius() const
Returns the radius.
Definition: qwt_point_polar.h:102
QwtPointPolar::operator==
bool operator==(const QwtPointPolar &) const
Compare 2 points.
Definition: qwt_point_polar.cpp:90
QwtPointPolar::QwtPointPolar
QwtPointPolar()
Definition: qwt_point_polar.h:71


plotjuggler
Author(s): Davide Faconti
autogenerated on Sun Aug 11 2024 02:24:24