source: ntrip/trunk/BNC/qwt/qwt_point_polar.h@ 10359

Last change on this file since 10359 was 9383, checked in by stoecker, 4 years ago

update to qwt verion 6.1.1 to fix build with newer Qt5

File size: 4.2 KB
RevLine 
[4271]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
10/*! \file */
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
21/*!
22 \brief A point in polar coordinates
23
24 In polar coordinates a point is determined by an angle and a distance.
25 See http://en.wikipedia.org/wiki/Polar_coordinate_system
26*/
27
28class QWT_EXPORT QwtPointPolar
29{
30public:
31 QwtPointPolar();
32 QwtPointPolar( double azimuth, double radius );
33 QwtPointPolar( const QPointF & );
34
35 void setPoint( const QPointF & );
36 QPointF toPoint() const;
37
38 bool isValid() const;
39 bool isNull() const;
40
41 double radius() const;
42 double azimuth() const;
43
44 double &rRadius();
45 double &rAzimuth();
46
47 void setRadius( double );
48 void setAzimuth( double );
49
50 bool operator==( const QwtPointPolar & ) const;
51 bool operator!=( const QwtPointPolar & ) const;
52
53 QwtPointPolar normalized() const;
54
[4331]55 double _value; // Change by LM
56
[4271]57private:
58 double d_azimuth;
59 double d_radius;
60};
61
62/*!
63 Constructs a null point, with a radius and azimuth set to 0.0.
[8127]64 \sa QPointF::isNull()
[4271]65*/
66inline QwtPointPolar::QwtPointPolar():
67 d_azimuth( 0.0 ),
68 d_radius( 0.0 )
69{
70}
71
72/*!
73 Constructs a point with coordinates specified by radius and azimuth.
74
75 \param azimuth Azimuth
76 \param radius Radius
77*/
78inline QwtPointPolar::QwtPointPolar( double azimuth, double radius ):
79 d_azimuth( azimuth ),
80 d_radius( radius )
81{
82}
83
84//! Returns true if radius() >= 0.0
85inline bool QwtPointPolar::isValid() const
86{
87 return d_radius >= 0.0;
88}
89
90//! Returns true if radius() >= 0.0
91inline bool QwtPointPolar::isNull() const
92{
93 return d_radius == 0.0;
94}
95
96//! Returns the radius.
97inline double QwtPointPolar::radius() const
98{
99 return d_radius;
100}
101
102//! Returns the azimuth.
103inline double QwtPointPolar::azimuth() const
104{
105 return d_azimuth;
106}
107
108//! Returns the radius.
109inline double &QwtPointPolar::rRadius()
110{
111 return d_radius;
112}
113
114//! Returns the azimuth.
115inline double &QwtPointPolar::rAzimuth()
116{
117 return d_azimuth;
118}
119
120//! Sets the radius to radius.
121inline void QwtPointPolar::setRadius( double radius )
122{
123 d_radius = radius;
124}
125
126//! Sets the atimuth to atimuth.
127inline void QwtPointPolar::setAzimuth( double azimuth )
128{
129 d_azimuth = azimuth;
130}
131
132#ifndef QT_NO_DEBUG_STREAM
133QWT_EXPORT QDebug operator<<( QDebug, const QwtPointPolar & );
134#endif
135
136inline QPoint qwtPolar2Pos( const QPoint &pole,
137 double radius, double angle )
138{
139 const double x = pole.x() + radius * qCos( angle );
140 const double y = pole.y() - radius * qSin( angle );
141
142 return QPoint( qRound( x ), qRound( y ) );
143}
144
145inline QPoint qwtDegree2Pos( const QPoint &pole,
146 double radius, double angle )
147{
148 return qwtPolar2Pos( pole, radius, angle / 180.0 * M_PI );
149}
150
151inline QPointF qwtPolar2Pos( const QPointF &pole,
152 double radius, double angle )
153{
154 const double x = pole.x() + radius * qCos( angle );
155 const double y = pole.y() - radius * qSin( angle );
156
157 return QPointF( x, y);
158}
159
160inline QPointF qwtDegree2Pos( const QPointF &pole,
161 double radius, double angle )
162{
163 return qwtPolar2Pos( pole, radius, angle / 180.0 * M_PI );
164}
165
166inline QPointF qwtFastPolar2Pos( const QPointF &pole,
167 double radius, double angle )
168{
169#if QT_VERSION < 0x040601
170 const double x = pole.x() + radius * ::cos( angle );
171 const double y = pole.y() - radius * ::sin( angle );
172#else
173 const double x = pole.x() + radius * qFastCos( angle );
174 const double y = pole.y() - radius * qFastSin( angle );
175#endif
176
177 return QPointF( x, y);
178}
179
180inline QPointF qwtFastDegree2Pos( const QPointF &pole,
181 double radius, double angle )
[9383]182{
[4271]183 return qwtFastPolar2Pos( pole, radius, angle / 180.0 * M_PI );
[9383]184}
[4271]185
[8127]186inline QwtPointPolar qwtFastPos2Polar( const QPointF &pos )
187{
188 return QwtPointPolar( qwtFastAtan2( pos.y(), pos.x() ),
189 qSqrt( qwtSqr( pos.x() ) + qwtSqr( pos.y() ) ) );
190}
191
[9383]192#endif
Note: See TracBrowser for help on using the repository browser.