CYCLUS
Loading...
Searching...
No Matches
position.h
Go to the documentation of this file.
1#ifndef CYCLUS_SRC_TOOLKIT_POSITION_H_
2#define CYCLUS_SRC_TOOLKIT_POSITION_H_
3#define CYCLUS_DECIMAL_SECOND_MULTIPLIER 3600
4
5#include <string>
6
7#include "cyclus.h"
8
9namespace cyclus {
10namespace toolkit {
11
12/// @class Position
13/// The Position class is a basic class that stores the geographic location of
14/// each
15/// agent in latitude and longitude and follows the ISO
16/// 6709 standard. Allows string expression of Position objects as specified in
17/// ANNEX H of ISO 6709 found here: 'https://www.iso.org/standard/39242.html'
18/// or a quick simplified version found here
19/// 'https://en.wikipedia.org/wiki/ISO_6709'
20///
21/// Brief Description of ISO 6709:
22/// 1. Latitude comes before Longitude
23/// 2. North latitude is positive
24/// 3. East longitude is positive
25/// 4. Fraction of degrees (decimal values) is prefered in digital data
26/// exchange.
27///
28/// The class is adapted from 'https://github.com/jaime-olivares/coordinate'
29/// under the MIT License.
30///
31/// Copyright (c) 2015 Jaime Olivares
32///
33/// Permission is hereby granted, free of charge, to any person obtaining a
34/// copy of this software and associated documentation files (the "Software")
35/// , to deal in the Software without restriction, including without
36/// limitation the rights to use, copy, modify, merge, publish, distribute,
37/// sublicense, and/or sell copies of the Software, and to permit persons to
38/// whom the Software is furnished to do so, subject to the following
39/// conditions:
40///
41/// The above copyright notice and this permission notice shall be included
42/// in all copies or substantial portions of the Software.
43///
44/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
45/// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
46/// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
47/// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
48/// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
49/// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
50/// USE OR OTHER DEALINGS IN THE SOFTWARE.
51///
52/// Longitude and Latitude is stored as seconds of degrees. This was also
53/// adapted from 'https://github.com/jaime-olivares/coordinate'. This, according
54/// to the jaime-olivares, allows the coordinate elements such as degrees,
55/// minutes, and seconds to "remain on the integral portion of values, with the
56/// exception of decimal of seconds, avoiding loss of precision." This is
57/// calculated by multiplying decimal degrees by 3600.
58/// example: 05.2169 -> 18780.84
59
60class Position {
61 public:
67
68 /// The default constructor for Position. This will creat an object with
69 /// lat=0, and long=0.
70 Position();
71
72 /// Position constructor with latitude and longditude as degrees as a double
73 /// point precision floating point.
74 /// @param deciaml_lat latitude expressed in degrees as a double.
75 /// @param decimal_lon longditude expressed in degrees as a double.
76 Position(double decimal_lat, double decimal_lon);
77
78 /// The default destructor for Position
79 ~Position();
80
81 /// Returns the current latitude.
82 /// @return decimal representation of latitude.
83 double latitude() const;
84
85 /// Returns the current longitude.
86 /// @return decimal representation of longitude.
87 double longitude() const;
88
89 /// Sets a new latitude
90 /// @param lat latitude expressed in decimal degrees.
91 void latitude(double lat);
92
93 /// Sets a new longitude
94 /// @param lon longitude expressed in decimal degrees.
95 void longitude(double lon);
96
97 /// Sets a new latitude and longitude
98 /// @param lat latitude, and lon longitude expressed in decimal degrees.
99 void set_position(double lat, double lon);
100
101 /// Returns the distance (in km) between this Position object and the target
102 /// Position object.
103 /// @param target the Position object some distnace away from the current one
104 /// @return distance between this and target in kilometers
105 double Distance(Position target) const;
106
107 /// Converts Position location into a string expression that follows ISO 6709
108 /// Annex
109 /// H. Function can be passed without any parameters for degrees format.
110 /// @param return_format_
111 /// @parblock_
112 /// The format of output. Options are 'Position::StringFormat::DEGREES',
113 /// 'Position::StringFormat::DEGREES_
114 /// MINUTES_',
115 /// 'Position::StringFormat::DEGREES_
116 /// MINUTES_
117 /// _ SECONDS':
118 ///
119 /// Position::StringFormat::DEGREES :return in degrees
120 /// format
121 /// Position::StringFormat::DEGREES_MINUTES :return in degrees
122 /// and minutes format
123 /// Position::StringFormat::DEGREES_MINUTES_SECONDS:return in degrees
124 /// minutes seconds
125 /// format
126 /// @endparblock
127 /// @return String representation of the Position object that complies with
128 /// ISO6709 Annex H
129 std::string ToString(
131
132 void RecordPosition(Agent* agent);
133
134 private:
135 /// Latitude is stored as seconds of degree. Explanation and example is
136 /// available above in class documentation
137 double latitude_;
138
139 /// Longitude is stored as seconds of degree.
140 double longitude_;
141
142 /// @brief Catch for Invalid Latitude
143 static constexpr double kInvalidLatitude =
144 std::numeric_limits<double>::quiet_NaN();
145
146 /// @brief Catch for Invalid Longitude
147 static constexpr double kInvalidLongitude =
148 std::numeric_limits<double>::quiet_NaN();
149
150 /// Checks if the decimal degree of longitude is within acceptable range.
151 /// The acceptable range is between -180 and 180 (inclusive).
152 /// @param lat latitude expressed in decimal degrees.
153 /// @return bool (true if valid, false otherwise)
154 bool ValidLongitude(double lon);
155
156 /// @brief Checks if the decimal degree of latitude is within acceptable
157 /// range. The acceptable range is between -90 and 90 (inclusive).
158 /// @param lat latitude expressed in decimal degrees.
159 /// @return bool (true if valid, false otherwise)
160 bool ValidLatitude(double lat);
161
162 /// Sets the precision for double values.
163 /// @param value that requires change of precision
164 /// @param precision the number decimal places wanted
165 /// @return value with the number of decimal places (precision) as defined
166 double SetPrecision(double value, double precision) const;
167
168 /// Formats longitude for toString function
169 /// @param mode
170 /// @parblock
171 /// The format of output. Options are '1', '2' or '3' :
172 ///
173 /// 1: return in degrees format
174 /// 2: return in degrees and minutes format
175 /// 3: return in degrees minutes seconds format
176 /// @endparblock
177 /// @param lon longitude of the object
178 /// @return partially formatted string
179 std::string ToStringHelperLon(int mode, double lon) const;
180
181 /// Formats latitude for toString function
182 /// @param mode
183 /// @parblock
184 /// The format of output. Options are '1', '2' or '3' :
185 ///
186 /// 1: return in degrees format
187 /// 2: return in degrees and minutes format
188 /// 3: return in degrees minutes seconds format
189 /// @endparblock
190 /// @param lat latitude of the object
191 /// @return partially formatted string
192 std::string ToStringHelperLat(int mode, double lat) const;
193
194 /// Adds "+" or "-" sign for the ToStringHelperLon/Lat function
195 /// @param value longitude or latitude of the object
196 /// @returns "+" or "-" for the ToString function
197 std::string ToStringHelper(double value) const;
198
199 /// Formats longitude and latitude in degrees and minutes for the
200 /// ToStringHelperLon/Lat function
201 /// @param value longitude or latitude of the object
202 /// @return formatted string representation of longiiiitude or latitude
203 std::string ToStringHelperDM(double value) const;
204
205 /// Formats longitude and latitude in degrees minutes and seconds for the
206 /// ToStringHelperLon/Lat function
207 /// @param value longitude or latitude of the object
208 /// @return formatted string representation of longiiiitude or latitude
209 std::string ToStringHelperDMS(double value) const;
210};
211
212} // namespace toolkit
213} // namespace cyclus
214
215#endif // CYCLUS_SRC_TOOLKIT_POSITION_H_
The abstract base class used by all types of agents that live and interact in a simulation.
Definition agent.h:50
The Position class is a basic class that stores the geographic location of each agent in latitude and...
Definition position.h:60
double Distance(Position target) const
Returns the distance (in km) between this Position object and the target Position object.
Definition position.cc:83
double longitude() const
Returns the current longitude.
Definition position.cc:24
~Position()
The default destructor for Position.
Definition position.cc:18
Position()
The default constructor for Position.
Definition position.cc:11
void RecordPosition(Agent *agent)
Definition position.cc:59
void set_position(double lat, double lon)
Sets a new latitude and longitude.
Definition position.cc:54
std::string ToString(Position::StringFormat format=StringFormat::DEGREES) const
Converts Position location into a string expression that follows ISO 6709 Annex H.
Definition position.cc:101
double latitude() const
Returns the current latitude.
Definition position.cc:20
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or....
Definition agent.cc:14