qwt_point_polar.h
Go to the documentation of this file.
1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
2  * Qwt Widget Library
3  * Copyright (C) 1997 Josef Wilgen
4  * Copyright (C) 2002 Uwe Rathmann
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the Qwt License, Version 1.0
8  *****************************************************************************/
9 
11 #ifndef _QWT_POINT_POLAR_H_
12 #define _QWT_POINT_POLAR_H_ 1
13 
14 #include "qwt_global.h"
15 #include "qwt_math.h"
16 #include <qpoint.h>
17 #ifndef QT_NO_DEBUG_STREAM
18 #include <qdebug.h>
19 #endif
20 
29 {
30 public:
31  QwtPointPolar();
32  QwtPointPolar( double azimuth, double radius );
33  QwtPointPolar( const QwtPointPolar & );
34  QwtPointPolar( const QPointF & );
35 
36  void setPoint( const QPointF & );
37  QPointF toPoint() const;
38 
39  bool isValid() const;
40  bool isNull() const;
41 
42  double radius() const;
43  double azimuth() const;
44 
45  double &rRadius();
46  double &rAzimuth();
47 
48  void setRadius( double );
49  void setAzimuth( double );
50 
51  bool operator==( const QwtPointPolar & ) const;
52  bool operator!=( const QwtPointPolar & ) const;
53 
54  QwtPointPolar normalized() const;
55 
56 private:
57  double d_azimuth;
58  double d_radius;
59 };
60 
66  d_azimuth( 0.0 ),
67  d_radius( 0.0 )
68 {
69 }
70 
77 inline QwtPointPolar::QwtPointPolar( double azimuth, double radius ):
78  d_azimuth( azimuth ),
79  d_radius( radius )
80 {
81 }
82 
88  d_azimuth( other.d_azimuth ),
89  d_radius( other.d_radius )
90 {
91 }
92 
94 inline bool QwtPointPolar::isValid() const
95 {
96  return d_radius >= 0.0;
97 }
98 
100 inline bool QwtPointPolar::isNull() const
101 {
102  return d_radius == 0.0;
103 }
104 
106 inline double QwtPointPolar::radius() const
107 {
108  return d_radius;
109 }
110 
112 inline double QwtPointPolar::azimuth() const
113 {
114  return d_azimuth;
115 }
116 
118 inline double &QwtPointPolar::rRadius()
119 {
120  return d_radius;
121 }
122 
124 inline double &QwtPointPolar::rAzimuth()
125 {
126  return d_azimuth;
127 }
128 
130 inline void QwtPointPolar::setRadius( double radius )
131 {
132  d_radius = radius;
133 }
134 
136 inline void QwtPointPolar::setAzimuth( double azimuth )
137 {
138  d_azimuth = azimuth;
139 }
140 
141 #ifndef QT_NO_DEBUG_STREAM
142 QWT_EXPORT QDebug operator<<( QDebug, const QwtPointPolar & );
143 #endif
144 
145 inline QPoint qwtPolar2Pos( const QPoint &pole,
146  double radius, double angle )
147 {
148  const double x = pole.x() + radius * qCos( angle );
149  const double y = pole.y() - radius * qSin( angle );
150 
151  return QPoint( qRound( x ), qRound( y ) );
152 }
153 
154 inline QPoint qwtDegree2Pos( const QPoint &pole,
155  double radius, double angle )
156 {
157  return qwtPolar2Pos( pole, radius, angle / 180.0 * M_PI );
158 }
159 
160 inline QPointF qwtPolar2Pos( const QPointF &pole,
161  double radius, double angle )
162 {
163  const double x = pole.x() + radius * qCos( angle );
164  const double y = pole.y() - radius * qSin( angle );
165 
166  return QPointF( x, y);
167 }
168 
169 inline QPointF qwtDegree2Pos( const QPointF &pole,
170  double radius, double angle )
171 {
172  return qwtPolar2Pos( pole, radius, angle / 180.0 * M_PI );
173 }
174 
175 inline QPointF qwtFastPolar2Pos( const QPointF &pole,
176  double radius, double angle )
177 {
178 #if QT_VERSION < 0x040601
179  const double x = pole.x() + radius * ::cos( angle );
180  const double y = pole.y() - radius * ::sin( angle );
181 #else
182  const double x = pole.x() + radius * qFastCos( angle );
183  const double y = pole.y() - radius * qFastSin( angle );
184 #endif
185 
186  return QPointF( x, y);
187 }
188 
189 inline QPointF qwtFastDegree2Pos( const QPointF &pole,
190  double radius, double angle )
191 {
192  return qwtFastPolar2Pos( pole, radius, angle / 180.0 * M_PI );
193 }
194 
195 inline QwtPointPolar qwtFastPos2Polar( const QPointF &pos )
196 {
197  return QwtPointPolar( qwtFastAtan2( pos.y(), pos.x() ),
198  qSqrt( qwtSqr( pos.x() ) + qwtSqr( pos.y() ) ) );
199 }
200 
201 #endif
void setAzimuth(double)
Sets the atimuth to atimuth.
A point in polar coordinates.
double & rRadius()
Returns the radius.
#define QWT_EXPORT
Definition: qwt_global.h:38
QPoint qwtPolar2Pos(const QPoint &pole, double radius, double angle)
bool operator==(optional< T > const &x, optional< T > const &y)
Definition: optional.hpp:854
QPointF qwtFastPolar2Pos(const QPointF &pole, double radius, double angle)
double radius() const
Returns the radius.
void setRadius(double)
Sets the radius to radius.
bool isNull() const
Returns true if radius() >= 0.0.
double azimuth() const
Returns the azimuth.
TFSIMD_FORCE_INLINE const tfScalar & y() const
QwtPointPolar qwtFastPos2Polar(const QPointF &pos)
#define qFastSin(x)
#define qFastCos(x)
TFSIMD_FORCE_INLINE Vector3 normalized() const
QPointF qwtFastDegree2Pos(const QPointF &pole, double radius, double angle)
double & rAzimuth()
Returns the azimuth.
TFSIMD_FORCE_INLINE const tfScalar & x() const
bool isValid() const
Returns true if radius() >= 0.0.
QPoint qwtDegree2Pos(const QPoint &pole, double radius, double angle)
QWT_EXPORT QDebug operator<<(QDebug, const QwtPointPolar &)
double qwtSqr(double x)
Return the square of a number.
Definition: qwt_math.h:88
double qwtFastAtan2(double y, double x)
Approximation of arc tangent ( error below 0,005 radians )
Definition: qwt_math.h:106
bool operator!=(optional< T > const &x, optional< T > const &y)
Definition: optional.hpp:859


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