]> git.mxchange.org Git - simgear.git/blobdiff - simgear/math/SGGeod.hxx
Canvas: fix element mouse hit detection with OSG 3.3.2.
[simgear.git] / simgear / math / SGGeod.hxx
index 63d0993558eaa4c474e4f51a2d1e1c4947530c88..8eddbe92ba5f10c2fb9f20765c96ad9085dd8cf6 100644 (file)
 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 // Library General Public License for more details.
 //
-// You should have received a copy of the GNU Library General Public
-// License along with this library; if not, write to the
-// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-// Boston, MA  02111-1307, USA.
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 //
 
 #ifndef SGGeod_H
@@ -28,13 +27,6 @@ class SGGeod {
 public:
   /// Default constructor, initializes the instance to lat = lon = elev = 0
   SGGeod(void);
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
-  /// Note that this conversion is relatively expensive to compute
-  SGGeod(const SGGeoc& geoc);
-
-  SGGeod(const SGVec3<double>& cart);
 
   /// Factory from angular values in radians and elevation is 0
   static SGGeod fromRad(double lon, double lat);
@@ -48,6 +40,17 @@ public:
   static SGGeod fromRadM(double lon, double lat, double elevation);
   /// Factory from angular values in degrees and elevation in m
   static SGGeod fromDegM(double lon, double lat, double elevation);
+  /// Factory from an other SGGeod and a different elevation in m
+  static SGGeod fromGeodM(const SGGeod& geod, double elevation);
+  /// Factory from an other SGGeod and a different elevation in ft
+  static SGGeod fromGeodFt(const SGGeod& geod, double elevation);
+  /// Factory to convert position from a cartesian position assumed to be
+  /// in wgs84 measured in meters
+  /// Note that this conversion is relatively expensive to compute
+  static SGGeod fromCart(const SGVec3<double>& cart);
+  /// Factory to convert position from a geocentric position
+  /// Note that this conversion is relatively expensive to compute
+  static SGGeod fromGeoc(const SGGeoc& geoc);
 
   /// Return the geodetic longitude in radians
   double getLongitudeRad(void) const;
@@ -79,13 +82,20 @@ public:
   /// Set the geodetic elevation from the argument given in feet
   void setElevationFt(double elevation);
 
+  /// Compare two geodetic positions for equality
+  bool operator == ( const SGGeod & other ) const;
+
+  /// check the Geod contains sane values (finite, inside appropriate
+  /// ranges for lat/lon)
+  bool isValid() const;
 private:
   /// This one is private since construction is not unique if you do
   /// not know the units of the arguments. Use the factory methods for
   /// that purpose
   SGGeod(double lon, double lat, double elevation);
 
-  /// The actual data, angles in degree, elevation in meters
+  //// FIXME: wrong comment!
+  /// The actual data, angles in degrees, elevation in meters
   /// The rationale for storing the values in degrees is that most code places
   /// in flightgear/terragear use degrees as a nativ input and output value.
   /// The places where it makes sense to use radians is when we convert
@@ -109,20 +119,6 @@ SGGeod::SGGeod(double lon, double lat, double elevation) :
 {
 }
 
-inline
-SGGeod::SGGeod(const SGVec3<double>& cart)
-{
-  SGGeodesy::SGCartToGeod(cart, *this);
-}
-
-inline
-SGGeod::SGGeod(const SGGeoc& geoc)
-{
-  SGVec3<double> cart;
-  SGGeodesy::SGGeocToCart(geoc, cart);
-  SGGeodesy::SGCartToGeod(cart, *this);
-}
-
 inline
 SGGeod
 SGGeod::fromRad(double lon, double lat)
@@ -193,6 +189,40 @@ SGGeod::fromDegM(double lon, double lat, double elevation)
 #endif
 }
 
+inline
+SGGeod
+SGGeod::fromGeodM(const SGGeod& geod, double elevation)
+{
+  return SGGeod(geod._lon, geod._lat, elevation);
+}
+
+inline
+SGGeod
+SGGeod::fromGeodFt(const SGGeod& geod, double elevation)
+{
+  return SGGeod(geod._lon, geod._lat, elevation*SG_FEET_TO_METER);
+}
+
+inline
+SGGeod
+SGGeod::fromCart(const SGVec3<double>& cart)
+{
+  SGGeod geod;
+  SGGeodesy::SGCartToGeod(cart, geod);
+  return geod;
+}
+
+inline
+SGGeod
+SGGeod::fromGeoc(const SGGeoc& geoc)
+{
+  SGVec3<double> cart;
+  SGGeodesy::SGGeocToCart(geoc, cart);
+  SGGeod geod;
+  SGGeodesy::SGCartToGeod(cart, geod);
+  return geod;
+}
+
 inline
 double
 SGGeod::getLongitudeRad(void) const
@@ -309,6 +339,32 @@ SGGeod::setElevationFt(double elevation)
   _elevation = elevation*SG_FEET_TO_METER;
 }
 
+inline
+bool
+SGGeod::operator == ( const SGGeod & other ) const
+{
+  return _lon == other._lon &&
+         _lat == other._lat &&
+         _elevation == other._elevation;
+}
+
+inline
+bool
+SGGeod::isValid() const
+{
+  if (SGMiscd::isNaN(_lon))
+      return false;
+  if (SGMiscd::isNaN(_lat))
+      return false;
+#ifdef SG_GEOD_NATIVE_DEGREE
+  return (_lon >= -180.0) && (_lon <= 180.0) &&
+  (_lat >= -90.0) && (_lat <= 90.0);
+#else
+  return (_lon >= -SGD_PI) && (_lon <= SGD_PI) &&
+  (_lat >= -SGD_PI_2) && (_lat <= SGD_PI_2);
+#endif
+}
+
 /// Output to an ostream
 template<typename char_type, typename traits_type>
 inline