1 // ----------------------------------------------------------------------------
2 // coordinate.h  --  Handling of longitude and latitude.
3 //
4 // Copyright (C) 2012
5 //		Remi Chateauneu, F4ECW
6 //
7 // This file is part of fldigi.
8 //
9 // Fldigi is free software: you can redistribute it and/or modify
10 // it under the terms of the GNU General Public License as published by
11 // the Free Software Foundation, either version 3 of the License, or
12 // (at your option) any later version.
13 //
14 // Fldigi is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 // GNU General Public License for more details.
18 //
19 // You should have received a copy of the GNU General Public License
20 // along with fldigi.  If not, see <http://www.gnu.org/licenses/>.
21 // ----------------------------------------------------------------------------
22 
23 #ifndef _COORDINATE_H
24 #define _COORDINATE_H
25 
26 #include <iostream>
27 
28 // Models a longitude or latitude.
29 class CoordinateT
30 {
31 	// Precision is: 360 * 3600 = 1296000, 21 bits. A float might be enough.
32 	double m_angle ;  // In decimal degrees, between -180.0 and 180.0.
33 	bool   m_is_lon ; // Longitude or latitude.
34 	// TODO: Consider adding a big offset to m_angle, instead of an extra flag.
35 
36 	void Check(void) const ;
37 
38 	void Init( char direction, double degrees );
39 public:
40 	CoordinateT(bool ll=true)
41 	: m_angle(0.0), m_is_lon(ll) {};
42 
43 	CoordinateT( double degrees, bool is_lon );
44 
45 	CoordinateT( char direction, double degrees );
46 
47 	CoordinateT( char direction, int degree, int minute, int second );
48 
angle(void)49 	double angle(void) const { return m_angle ; }
is_lon(void)50 	bool is_lon(void) const { return m_is_lon; }
51 
52 	// Specific for reading from the file of navtex or wmo stations.
53 	// Navtex: "57 06 N"
54 	// Wmo   : "69-36N", "013-27E", "009-25E"
55 	friend std::istream & operator>>( std::istream & istrm, CoordinateT & ref );
56 
57 	friend std::ostream & operator<<( std::ostream & ostrm, const CoordinateT & ref );
58 
59 	class Pair ;
60 }; // CoordinateT
61 
62 // Longitude , latitude.
63 class CoordinateT::Pair
64 {
65 	CoordinateT m_lon, m_lat ;
66 public:
Pair()67 	Pair() {}
68 
69 	Pair( const CoordinateT & coo1, const CoordinateT & coo2 );
70 
71 	Pair( double lon, double lat );
72 
73 	Pair( const std::string & locator );
74 
longitude()75 	CoordinateT longitude() const { return m_lon ; }
76 
latitude()77 	CoordinateT latitude() const { return m_lat ; }
78 
longitude()79 	CoordinateT & longitude() { return m_lon ; }
80 
latitude()81 	CoordinateT & latitude() { return m_lat ; }
82 
83 	double distance( const Pair & a ) const;
84 
85 	std::string locator() const ;
86 
87 	friend std::istream & operator>>( std::istream & istrm, Pair & ref );
88 
89 	friend std::ostream & operator<<( std::ostream & ostrm, const Pair & ref );
90 }; // CoordinateT::Pair
91 
92 
93 #endif // _COORDINATE_H
94