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 
18 QwtPointPolar::QwtPointPolar( const QPointF &p )
19 {
20  d_radius = std::sqrt( qwtSqr( p.x() ) + qwtSqr( p.y() ) );
21  d_azimuth = std::atan2( p.y(), p.x() );
22 }
23 
28 void QwtPointPolar::setPoint( const QPointF &p )
29 {
30  d_radius = std::sqrt( qwtSqr( p.x() ) + qwtSqr( p.y() ) );
31  d_azimuth = std::atan2( p.y(), p.x() );
32 }
33 
42 QPointF QwtPointPolar::toPoint() const
43 {
44  if ( d_radius <= 0.0 )
45  return QPointF( 0.0, 0.0 );
46 
47  const double x = d_radius * std::cos( d_azimuth );
48  const double y = d_radius * std::sin( d_azimuth );
49 
50  return QPointF( x, y );
51 }
52 
64 bool QwtPointPolar::operator==( const QwtPointPolar &other ) const
65 {
66  return d_radius == other.d_radius && d_azimuth == other.d_azimuth;
67 }
68 
79 bool QwtPointPolar::operator!=( const QwtPointPolar &other ) const
80 {
81  return d_radius != other.d_radius || d_azimuth != other.d_azimuth;
82 }
83 
93 {
94  const double radius = qwtMaxF( d_radius, 0.0 );
95 
96  double azimuth = d_azimuth;
97  if ( azimuth < -2.0 * M_PI || azimuth >= 2 * M_PI )
98  azimuth = std::fmod( d_azimuth, 2 * M_PI );
99 
100  if ( azimuth < 0.0 )
101  azimuth += 2 * M_PI;
102 
103  return QwtPointPolar( azimuth, radius );
104 }
105 
106 #ifndef QT_NO_DEBUG_STREAM
107 
108 #include <qdebug.h>
109 
110 QDebug operator<<( QDebug debug, const QwtPointPolar &point )
111 {
112  debug.nospace() << "QwtPointPolar("
113  << point.azimuth() << "," << point.radius() << ")";
114 
115  return debug.space();
116 }
117 
118 #endif
119 
A point in polar coordinates.
bool operator!=(const QwtPointPolar &) const
QWT_CONSTEXPR float qwtMaxF(float a, float b)
Definition: qwt_math.h:123
double radius() const
Returns the radius.
double azimuth() const
Returns the azimuth.
void setPoint(const QPointF &)
QPointF toPoint() const
QDebug operator<<(QDebug debug, const QwtPointPolar &point)
#define M_PI
Definition: qwt_math.h:56
double qwtSqr(double x)
Return the square of a number.
Definition: qwt_math.h:191
bool operator==(const QwtPointPolar &) const
Compare 2 points.
QwtPointPolar normalized() const


plotjuggler
Author(s): Davide Faconti
autogenerated on Sun Dec 6 2020 03:48:10