Advertisement
Guest User

GeoDataCoordinates_p.h

a guest
May 15th, 2012
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.82 KB | None | 0 0
  1. //
  2. // This file is part of the Marble Virtual Globe.
  3. //
  4. // This program is free software licensed under the GNU LGPL. You can
  5. // find a copy of this license in LICENSE.txt in the top directory of
  6. // the source code.
  7. //
  8. // Copyright 2008 Patrick Spendrin <ps_ml@gmx.de>
  9. //
  10.  
  11. #ifndef MARBLE_GEODATACOORDINATES_P_H
  12. #define MARBLE_GEODATACOORDINATES_P_H
  13.  
  14. #include "Quaternion.h"
  15. #include <QtCore/QAtomicInt>
  16.  
  17. #include "MarbleClock.h"
  18.  
  19. namespace Marble
  20. {
  21.  
  22. class GeoDataCoordinatesPrivate
  23. {
  24. public:
  25. /*
  26. * if this ctor is called there exists exactly one GeoDataCoordinates object
  27. * with this data.
  28. * changes will be made in the GeoDataCoordinates class
  29. * ref must be called ref as qAtomicAssign used in GeoDataCoordinates::operator=
  30. * needs this name. Maybe we can rename it to our scheme later on.
  31. */
  32. GeoDataCoordinatesPrivate()
  33. : m_lon( 0 ),
  34. m_lat( 0 ),
  35. m_altitude( 0 ),
  36. m_detail( 0 ),
  37. ref( 0 ),
  38. type( 0 ),
  39. m_clock( 0 )
  40. {
  41. }
  42.  
  43. /*
  44. * if this ctor is called there exists exactly one GeoDataCoordinates object
  45. * with this data.
  46. * changes will be made in the GeoDataCoordinates class
  47. * ref must be called ref as qAtomicAssign used in GeoDataCoordinates::operator=
  48. * needs this name. Maybe we can rename it to our scheme later on.
  49. */
  50. GeoDataCoordinatesPrivate( qreal _lon, qreal _lat, qreal _alt,
  51. GeoDataCoordinates::Unit unit,
  52. int _detail )
  53. : m_altitude( _alt ),
  54. m_detail( _detail ),
  55. ref( 0 )
  56. {
  57. switch( unit ){
  58. default:
  59. case GeoDataCoordinates::Radian:
  60. m_q = Quaternion::fromSpherical( _lon, _lat );
  61. m_lon = _lon;
  62. m_lat = _lat;
  63. break;
  64. case GeoDataCoordinates::Degree:
  65. m_q = Quaternion::fromSpherical( _lon * DEG2RAD , _lat * DEG2RAD );
  66. m_lon = _lon * DEG2RAD;
  67. m_lat = _lat * DEG2RAD;
  68. break;
  69. }
  70. }
  71.  
  72. /*
  73. * this constructor is needed as Quaternion doesn't define a copy ctor
  74. * initialize the reference with the value of the other
  75. */
  76. GeoDataCoordinatesPrivate( const GeoDataCoordinatesPrivate &other )
  77. : m_q( Quaternion::fromSpherical( other.m_lon, other.m_lat ) ),
  78. m_lon( other.m_lon ),
  79. m_lat( other.m_lat ),
  80. m_altitude( other.m_altitude ),
  81. m_detail( other.m_detail ),
  82. ref( 0 )
  83. {
  84. }
  85.  
  86. /*
  87. * return this instead of &other
  88. */
  89. GeoDataCoordinatesPrivate& operator=( const GeoDataCoordinatesPrivate &other )
  90. {
  91. m_lon = other.m_lon;
  92. m_lat = other.m_lat;
  93. m_altitude = other.m_altitude;
  94. m_detail = other.m_detail;
  95. m_q = other.m_q;
  96. ref = 0;
  97. return *this;
  98. }
  99.  
  100. bool operator==( const GeoDataCoordinatesPrivate &rhs ) const;
  101. bool operator!=( const GeoDataCoordinatesPrivate &rhs ) const;
  102.  
  103. Quaternion m_q;
  104. qreal m_lon;
  105. qreal m_lat;
  106. qreal m_altitude; // in meters above sea level
  107. int m_detail;
  108. QAtomicInt ref;
  109.  
  110. int type;
  111. MarbleClock* m_clock;
  112. };
  113.  
  114. inline bool GeoDataCoordinatesPrivate::operator==( const GeoDataCoordinatesPrivate &rhs ) const
  115. {
  116. // do not compare the m_detail member as it does not really belong to
  117. // GeoDataCoordinates and should be removed
  118. return m_lon == rhs.m_lon && m_lat == rhs.m_lat && m_altitude == rhs.m_altitude;
  119. }
  120.  
  121. inline bool GeoDataCoordinatesPrivate::operator!=( const GeoDataCoordinatesPrivate &rhs ) const
  122. {
  123. // do not compare the m_detail member as it does not really belong to
  124. // GeoDataCoordinates and should be removed
  125. return ! (*this == rhs);
  126. }
  127.  
  128. }
  129.  
  130. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement