Qwt User's Guide 6.3.0
Loading...
Searching...
No Matches
qwt_point_polar.cpp
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
14static QwtPointPolar qwtPointToPolar( const QPointF& point )
15{
16 return QwtPointPolar( point );
17}
18
19#endif
20
21namespace
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
45{
46 m_radius = std::sqrt( qwtSqr( p.x() ) + qwtSqr( p.y() ) );
47 m_azimuth = std::atan2( p.y(), p.x() );
48}
49
54void 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
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
90bool QwtPointPolar::operator==( const QwtPointPolar& other ) const
91{
92 return m_radius == other.m_radius && m_azimuth == other.m_azimuth;
93}
94
105bool 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
136QDebug 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
A point in polar coordinates.
double radius() const
Returns the radius.
double azimuth() const
Returns the azimuth.
QPointF toPoint() const
void setPoint(const QPointF &)
bool operator!=(const QwtPointPolar &) const
QwtPointPolar normalized() const
bool operator==(const QwtPointPolar &) const
Compare 2 points.