Qwt User's Guide 6.1.0

- Main Page
- Related Pages
- Classes

All Classes Functions Variables Typedefs Enumerations Enumerator Pages
qwt_point_polar.h
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
28 class QWT_EXPORT QwtPointPolar
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
65 inline QwtPointPolar::QwtPointPolar():
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
87 inline QwtPointPolar::QwtPointPolar( const QwtPointPolar &other ):
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