A library for working with phylogenetic and population genetic data.
v0.27.0
geo_coordinate.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_UTILS_TOOLS_GEODESY_GEO_COORDINATE_H_
2 #define GENESIS_UTILS_TOOLS_GEODESY_GEO_COORDINATE_H_
3 
4 /*
5  Genesis - A toolkit for working with phylogenetic data.
6  Copyright (C) 2014-2018 Lucas Czech and HITS gGmbH
7 
8  This program is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program. If not, see <http://www.gnu.org/licenses/>.
20 
21  Contact:
22  Lucas Czech <lucas.czech@h-its.org>
23  Exelixis Lab, Heidelberg Institute for Theoretical Studies
24  Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
25 */
26 
34 #include <stdexcept>
35 
36 namespace genesis {
37 namespace utils {
38 
39 // =================================================================================================
40 // Coordinate System Definitions
41 // =================================================================================================
42 
47 {
48 public:
49 
50  // -------------------------------------------------------------------------
51  // Constructor and Rule of Five
52  // -------------------------------------------------------------------------
53 
54  GeoCoordinate() = default;
55 
56  GeoCoordinate( double lat, double lon )
57  {
58  latitude( lat );
59  longitude( lon );
60  }
61 
62  ~GeoCoordinate() = default;
63 
64  GeoCoordinate( GeoCoordinate const& ) = default;
65  GeoCoordinate( GeoCoordinate&& ) = default;
66 
67  GeoCoordinate& operator= ( GeoCoordinate const& ) = default;
68  GeoCoordinate& operator= ( GeoCoordinate&& ) = default;
69 
70  // -------------------------------------------------------------------------
71  // Getters and Setters
72  // -------------------------------------------------------------------------
73 
77  double latitude() const
78  {
79  return latitude_;
80  }
81 
85  double longitude() const
86  {
87  return longitude_;
88  }
89 
93  GeoCoordinate& latitude( double value )
94  {
95  if( value < -90.0 || value > 90.0 ) {
96  throw std::invalid_argument( "Latitude has to be in range [ -90.0, 90.0 ]." );
97  }
98  latitude_ = value;
99  return *this;
100  }
101 
105  GeoCoordinate& longitude( double value )
106  {
107  if( value < -180.0 || value > 180.0 ) {
108  throw std::invalid_argument( "Longitude has to be in range [ -180.0, 180.0 ]." );
109  }
110  longitude_ = value;
111  return *this;
112  }
113 
114  // -------------------------------------------------------------------------
115  // Private Members
116  // -------------------------------------------------------------------------
117 
118 private:
119 
120  double latitude_;
121  double longitude_;
122 };
123 
124 } // namespace utils
125 } // namespace genesis
126 
127 #endif // include guard
genesis::utils::GeoCoordinate::GeoCoordinate
GeoCoordinate(double lat, double lon)
Definition: geo_coordinate.hpp:56
genesis::utils::GeoCoordinate
Geographical coordinates in degrees.
Definition: geo_coordinate.hpp:46
genesis::utils::GeoCoordinate::longitude
GeoCoordinate & longitude(double value)
Longitude, in range [ -180.0, 180.0 ].
Definition: geo_coordinate.hpp:105
genesis::utils::GeoCoordinate::GeoCoordinate
GeoCoordinate()=default
genesis::utils::GeoCoordinate::latitude
GeoCoordinate & latitude(double value)
Latitude, in range [ -90.0, 90.0 ].
Definition: geo_coordinate.hpp:93
genesis::utils::GeoCoordinate::~GeoCoordinate
~GeoCoordinate()=default
genesis
Container namespace for all symbols of genesis in order to keep them separate when used as a library.
Definition: placement/formats/edge_color.cpp:42
genesis::utils::GeoCoordinate::latitude
double latitude() const
Latitude, in range [ -90.0, 90.0 ].
Definition: geo_coordinate.hpp:77
genesis::utils::GeoCoordinate::operator=
GeoCoordinate & operator=(GeoCoordinate const &)=default
genesis::utils::GeoCoordinate::longitude
double longitude() const
Longitude, in range [ -180.0, 180.0 ].
Definition: geo_coordinate.hpp:85