qwt_point_3d.h 4.0 KB

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