OpenSceneGraph 3.6.5
GeographicLocation
Go to the documentation of this file.
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2004 Robert Osfield
2 *
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.
7 *
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.
12*/
13
14#ifndef OSGSIM_GEOGRAPHICLOCATION
15#define OSGSIM_GEOGRAPHICLOCATION 1
16
17#include <osg/Math>
18#include <osg/Referenced>
19
20#include <ostream>
21
22namespace osgSim {
23
27
29{
30 public:
31
32 GeographicLocation() { _v[0]=0.; _v[1]=0.; }
33 GeographicLocation( double lat, double lon ) { _v[0]=lat; _v[1]=lon; }
34
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
38 {
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;
42 else return false;
43 }
44
45 inline double* ptr() { return _v; }
46 inline const double* ptr() const { return _v; }
47
48 inline void set( double lat, double lon ) { _v[0]=lat; _v[1]=lon; }
49
50 inline double& latitude() { return _v[0]; }
51 inline double& longitude() { return _v[1]; }
52
53 inline double latitude() const { return _v[0]; }
54 inline double longitude() const { return _v[1]; }
55
56 inline bool valid() const { return !isNaN(); }
57 inline bool isNaN() const { return osg::isNaN(_v[0]) || osg::isNaN(_v[1]); }
58
60 inline const GeographicLocation operator+( const GeographicLocation& rhs) const
61 {
62 return GeographicLocation(_v[0]+rhs._v[0], _v[1]+rhs._v[1]);
63 }
64
66 inline const GeographicLocation operator-( const GeographicLocation& rhs) const
67 {
68 return GeographicLocation(_v[0]-rhs._v[0], _v[1]-rhs._v[1]);
69 }
70
71 friend inline std::ostream& operator << (std::ostream& output, const GeographicLocation& loc)
72 {
73 output << loc._v[0] << " " << loc._v[1];
74 return output; // to enable cascading
75 }
76
77 private:
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...
81 double _v[2];
82
83}; // end of class GeographicLocation
84
85} // end of namespace osgSim
86
87#endif
bool isNaN(float v)
Definition Math:133
The osgSim library is a NodeKit that extends the core scene graph to support nodes and drawables that...
Definition BlinkSequence:27
Base class for providing reference counted objects.
Definition Referenced:44
const GeographicLocation operator-(const GeographicLocation &rhs) const
binary vector subtract
Definition GeographicLocation:66
double * ptr()
Definition GeographicLocation:45
double latitude() const
Definition GeographicLocation:53
friend std::ostream & operator<<(std::ostream &output, const GeographicLocation &loc)
Definition GeographicLocation:71
double & latitude()
Definition GeographicLocation:50
GeographicLocation()
Definition GeographicLocation:32
const GeographicLocation operator+(const GeographicLocation &rhs) const
binary vector add
Definition GeographicLocation:60
bool operator==(const GeographicLocation &v) const
Definition GeographicLocation:35
void set(double lat, double lon)
Definition GeographicLocation:48
bool operator<(const GeographicLocation &v) const
Definition GeographicLocation:37
const double * ptr() const
Definition GeographicLocation:46
bool isNaN() const
Definition GeographicLocation:57
double & longitude()
Definition GeographicLocation:51
double longitude() const
Definition GeographicLocation:54
bool operator!=(const GeographicLocation &v) const
Definition GeographicLocation:36
bool valid() const
Definition GeographicLocation:56
GeographicLocation(double lat, double lon)
Definition GeographicLocation:33

osg logo
Generated at Sun Jul 20 2025 00:00:00 for the OpenSceneGraph by doxygen 1.14.0.