qwt_point_3d.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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_3D_H
  11. #define QWT_POINT_3D_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 QwtPoint3D class defines a 3D point in double coordinates
  19. */
  20. class QWT_EXPORT QwtPoint3D
  21. {
  22. public:
  23. QwtPoint3D();
  24. QwtPoint3D( double x, double y, double z );
  25. QwtPoint3D( const QwtPoint3D & );
  26. QwtPoint3D( const QPointF & );
  27. bool isNull() const;
  28. double x() const;
  29. double y() const;
  30. double z() const;
  31. double &rx();
  32. double &ry();
  33. double &rz();
  34. void setX( double x );
  35. void setY( double y );
  36. void setZ( double y );
  37. QPointF toPoint() const;
  38. bool operator==( const QwtPoint3D & ) const;
  39. bool operator!=( const QwtPoint3D & ) const;
  40. private:
  41. double d_x;
  42. double d_y;
  43. double d_z;
  44. };
  45. Q_DECLARE_TYPEINFO(QwtPoint3D, Q_MOVABLE_TYPE);
  46. #ifndef QT_NO_DEBUG_STREAM
  47. QWT_EXPORT QDebug operator<<( QDebug, const QwtPoint3D & );
  48. #endif
  49. /*!
  50. Constructs a null point.
  51. \sa isNull()
  52. */
  53. inline QwtPoint3D::QwtPoint3D():
  54. d_x( 0.0 ),
  55. d_y( 0.0 ),
  56. d_z( 0.0 )
  57. {
  58. }
  59. //! Constructs a point with coordinates specified by x, y and z.
  60. inline QwtPoint3D::QwtPoint3D( double x, double y, double z = 0.0 ):
  61. d_x( x ),
  62. d_y( y ),
  63. d_z( z )
  64. {
  65. }
  66. /*!
  67. Copy constructor.
  68. Constructs a point using the values of the point specified.
  69. */
  70. inline QwtPoint3D::QwtPoint3D( const QwtPoint3D &other ):
  71. d_x( other.d_x ),
  72. d_y( other.d_y ),
  73. d_z( other.d_z )
  74. {
  75. }
  76. /*!
  77. Constructs a point with x and y coordinates from a 2D point,
  78. and a z coordinate of 0.
  79. */
  80. inline QwtPoint3D::QwtPoint3D( const QPointF &other ):
  81. d_x( other.x() ),
  82. d_y( other.y() ),
  83. d_z( 0.0 )
  84. {
  85. }
  86. /*!
  87. \return True if the point is null; otherwise returns false.
  88. A point is considered to be null if x, y and z-coordinates
  89. are equal to zero.
  90. */
  91. inline bool QwtPoint3D::isNull() const
  92. {
  93. return d_x == 0.0 && d_y == 0.0 && d_z == 0.0;
  94. }
  95. //! \return The x-coordinate of the point.
  96. inline double QwtPoint3D::x() const
  97. {
  98. return d_x;
  99. }
  100. //! \return The y-coordinate of the point.
  101. inline double QwtPoint3D::y() const
  102. {
  103. return d_y;
  104. }
  105. //! \return The z-coordinate of the point.
  106. inline double QwtPoint3D::z() const
  107. {
  108. return d_z;
  109. }
  110. //! \return A reference to the x-coordinate of the point.
  111. inline double &QwtPoint3D::rx()
  112. {
  113. return d_x;
  114. }
  115. //! \return A reference to the y-coordinate of the point.
  116. inline double &QwtPoint3D::ry()
  117. {
  118. return d_y;
  119. }
  120. //! \return A reference to the z-coordinate of the point.
  121. inline double &QwtPoint3D::rz()
  122. {
  123. return d_z;
  124. }
  125. //! Sets the x-coordinate of the point to the value specified by x.
  126. inline void QwtPoint3D::setX( double x )
  127. {
  128. d_x = x;
  129. }
  130. //! Sets the y-coordinate of the point to the value specified by y.
  131. inline void QwtPoint3D::setY( double y )
  132. {
  133. d_y = y;
  134. }
  135. //! Sets the z-coordinate of the point to the value specified by z.
  136. inline void QwtPoint3D::setZ( double z )
  137. {
  138. d_z = z;
  139. }
  140. /*!
  141. \return 2D point, where the z coordinate is dropped.
  142. */
  143. inline QPointF QwtPoint3D::toPoint() const
  144. {
  145. return QPointF( d_x, d_y );
  146. }
  147. //! \return True, if this point and other are equal; otherwise returns false.
  148. inline bool QwtPoint3D::operator==( const QwtPoint3D &other ) const
  149. {
  150. return ( d_x == other.d_x ) && ( d_y == other.d_y ) && ( d_z == other.d_z );
  151. }
  152. //! \return True if this rect and other are different; otherwise returns false.
  153. inline bool QwtPoint3D::operator!=( const QwtPoint3D &other ) const
  154. {
  155. return !operator==( other );
  156. }
  157. #endif