1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2004 Robert Osfield
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
14#ifndef OSGSIM_GEOGRAPHICLOCATION
15#define OSGSIM_GEOGRAPHICLOCATION 1
18#include <osg/Referenced>
24/** Stores a double precision geographic location, latitude and longitude.
25 Derived from Referenced so it can be used as an osg::Object userData.
28class GeographicLocation : public osg::Referenced
32 GeographicLocation() { _v[0]=0.; _v[1]=0.; }
33 GeographicLocation( double lat, double lon ) { _v[0]=lat; _v[1]=lon; }
35 inline bool operator == ( const GeographicLocation& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1]; }
36 inline bool operator != ( const GeographicLocation& v) const { return _v[0]!=v._v[0] || _v[1]!=v._v[1]; }
37 inline bool operator < ( const GeographicLocation& v) const
39 if (_v[0]<v._v[0]) return true;
40 else if (_v[0]>v._v[0]) return false;
41 else if (_v[1]<v._v[1]) return true;
45 inline double* ptr() { return _v; }
46 inline const double* ptr() const { return _v; }
48 inline void set( double lat, double lon ) { _v[0]=lat; _v[1]=lon; }
50 inline double& latitude() { return _v[0]; }
51 inline double& longitude() { return _v[1]; }
53 inline double latitude() const { return _v[0]; }
54 inline double longitude() const { return _v[1]; }
56 inline bool valid() const { return !isNaN(); }
57 inline bool isNaN() const { return osg::isNaN(_v[0]) || osg::isNaN(_v[1]); }
60 inline const GeographicLocation operator+( const GeographicLocation& rhs) const
62 return GeographicLocation(_v[0]+rhs._v[0], _v[1]+rhs._v[1]);
65 /// binary vector subtract
66 inline const GeographicLocation operator-( const GeographicLocation& rhs) const
68 return GeographicLocation(_v[0]-rhs._v[0], _v[1]-rhs._v[1]);
71 friend inline std::ostream& operator << (std::ostream& output, const GeographicLocation& loc)
73 output << loc._v[0] << " " << loc._v[1];
74 return output; // to enable cascading
78 // Note the convention is to store lat in _v[0] and lon in _v[1].
79 // This is contrary to typical X-Y convention. Who decided lat should come
80 // before lon anyway? I'd like a word with him...
83}; // end of class GeographicLocation
85} // end of namespace osgSim