qwt_point_polar.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. /*! \file */
  10. #ifndef _QWT_POINT_POLAR_H_
  11. #define _QWT_POINT_POLAR_H_ 1
  12. #include "qwt_global.h"
  13. #include <qpoint.h>
  14. #ifndef QT_NO_DEBUG_STREAM
  15. #include <qdebug.h>
  16. #endif
  17. /*!
  18. \brief A point in polar coordinates
  19. In polar coordinates a point is determined by an angle and a distance.
  20. See http://en.wikipedia.org/wiki/Polar_coordinate_system
  21. */
  22. class QWT_EXPORT QwtPointPolar
  23. {
  24. public:
  25. QwtPointPolar();
  26. QwtPointPolar( double azimuth, double radius );
  27. QwtPointPolar( const QwtPointPolar & );
  28. QwtPointPolar( const QPointF & );
  29. void setPoint( const QPointF & );
  30. QPointF toPoint() const;
  31. bool isValid() const;
  32. bool isNull() const;
  33. double radius() const;
  34. double azimuth() const;
  35. double &rRadius();
  36. double &rAzimuth();
  37. void setRadius( double );
  38. void setAzimuth( double );
  39. bool operator==( const QwtPointPolar & ) const;
  40. bool operator!=( const QwtPointPolar & ) const;
  41. QwtPointPolar normalized() const;
  42. private:
  43. double d_azimuth;
  44. double d_radius;
  45. };
  46. /*!
  47. Constructs a null point, with a radius and azimuth set to 0.0.
  48. \sa QPointF::isNull
  49. */
  50. inline QwtPointPolar::QwtPointPolar():
  51. d_azimuth( 0.0 ),
  52. d_radius( 0.0 )
  53. {
  54. }
  55. /*!
  56. Constructs a point with coordinates specified by radius and azimuth.
  57. \param azimuth Azimuth
  58. \param radius Radius
  59. */
  60. inline QwtPointPolar::QwtPointPolar( double azimuth, double radius ):
  61. d_azimuth( azimuth ),
  62. d_radius( radius )
  63. {
  64. }
  65. /*!
  66. Constructs a point using the values of the point specified.
  67. \param other Other point
  68. */
  69. inline QwtPointPolar::QwtPointPolar( const QwtPointPolar &other ):
  70. d_azimuth( other.d_azimuth ),
  71. d_radius( other.d_radius )
  72. {
  73. }
  74. //! Returns true if radius() >= 0.0
  75. inline bool QwtPointPolar::isValid() const
  76. {
  77. return d_radius >= 0.0;
  78. }
  79. //! Returns true if radius() >= 0.0
  80. inline bool QwtPointPolar::isNull() const
  81. {
  82. return d_radius == 0.0;
  83. }
  84. //! Returns the radius.
  85. inline double QwtPointPolar::radius() const
  86. {
  87. return d_radius;
  88. }
  89. //! Returns the azimuth.
  90. inline double QwtPointPolar::azimuth() const
  91. {
  92. return d_azimuth;
  93. }
  94. //! Returns the radius.
  95. inline double &QwtPointPolar::rRadius()
  96. {
  97. return d_radius;
  98. }
  99. //! Returns the azimuth.
  100. inline double &QwtPointPolar::rAzimuth()
  101. {
  102. return d_azimuth;
  103. }
  104. //! Sets the radius to radius.
  105. inline void QwtPointPolar::setRadius( double radius )
  106. {
  107. d_radius = radius;
  108. }
  109. //! Sets the atimuth to atimuth.
  110. inline void QwtPointPolar::setAzimuth( double azimuth )
  111. {
  112. d_azimuth = azimuth;
  113. }
  114. #ifndef QT_NO_DEBUG_STREAM
  115. QWT_EXPORT QDebug operator<<( QDebug, const QwtPointPolar & );
  116. #endif
  117. #endif