29 if (!ValidLatitude(lat)) {
30 latitude_ = kInvalidLatitude;
31 std::stringstream msg;
32 msg <<
"The provided latitude (" << lat
33 <<
") is outside the acceptable range "
34 <<
"[-90, 90]. Latitude has been set to " << latitude_;
42 if (!ValidLongitude(lon)) {
43 longitude_ = kInvalidLongitude;
44 std::stringstream msg;
45 msg <<
"The provided longitude (" << lon
46 <<
") is outside the acceptable range "
47 <<
"[-180, 180]. Longitude has been set to " << longitude_;
69bool Position::ValidLatitude(
double lat) {
70 if (lat > 90 || lat < -90) {
76bool Position::ValidLongitude(
double lon) {
77 if (lon > 180 || lon < -180) {
84 double earth_radius = 6372.8;
85 double curr_longitude = this->
longitude() * M_PI / 180;
86 double curr_latitude = this->
latitude() * M_PI / 180;
87 double tarlongitude = target.
longitude() * M_PI / 180;
88 double tarlatitude = target.
latitude() * M_PI / 180;
89 double dlong = tarlongitude - curr_longitude;
90 double dlat = tarlatitude - curr_latitude;
92 double half_chord_length_sq = pow(sin(dlat / 2), 2) + pow(sin(dlong / 2), 2) *
96 double angular_distance =
97 2 * atan2(sqrt(half_chord_length_sq), sqrt(1 - half_chord_length_sq));
98 return earth_radius * angular_distance;
102 std::stringstream lat_string;
103 std::stringstream lon_string;
108 lat_string << ToStringHelperLat(format, lat);
109 lon_string << ToStringHelperLon(format, lon);
112 lat_string << ToStringHelperLat(format, lat);
113 lon_string << ToStringHelperLon(format, lon);
116 lat_string << ToStringHelperLat(format, lat);
117 lon_string << ToStringHelperLon(format, lon);
120 return lat_string.str() + lon_string.str() +
"/";
123double Position::SetPrecision(
double value,
double precision)
const {
124 if (precision == 0) {
127 return (floor((value * pow(10, precision) + 0.5)) / pow(10, precision));
130std::string Position::ToStringHelperLat(
int mode,
double lat)
const {
131 std::stringstream lat_string;
133 lat_string << ToStringHelper(lat);
135 lat = modf(lat, &lat_int);
136 if (((
int)lat_int) / 10 == 0) {
141 lat_string << std::setprecision(7) << fabs(lat_int + lat);
144 lat_string << abs((
int)lat_int) << ToStringHelperDM(lat);
147 lat_string << abs((
int)lat_int) << ToStringHelperDMS(lat);
150 return lat_string.str();
153std::string Position::ToStringHelperLon(
int mode,
double lon)
const {
154 std::stringstream lon_string;
156 lon_string << ToStringHelper(lon);
157 lon = modf(lon, &lon_int);
158 if (((
int)lon_int) / 100 == 0) {
159 if (((
int)lon_int) / 10 == 0) {
166 lon_string << std::setprecision(7) << fabs(lon_int + lon);
169 lon_string << abs((
int)lon_int) << ToStringHelperDM(lon);
172 lon_string << abs((
int)lon_int) << ToStringHelperDMS(lon);
175 return lon_string.str();
178std::string Position::ToStringHelper(
double value)
const {
179 std::stringstream temp;
188std::string Position::ToStringHelperDM(
double value)
const {
189 std::stringstream temp;
190 value = fabs(value) * 60;
191 if (((
int)fabs(value)) / 10 == 0) {
194 temp << std::setprecision(5) << value;
199std::string Position::ToStringHelperDMS(
double value)
const {
200 std::stringstream temp;
202 value = fabs(value) * 60;
203 value = modf(value, &value_int);
204 if (((
int)value_int) / 10 == 0) {
207 temp << fabs(value_int);
209 if ((
int)fabs(value) / 10 == 0) {
212 temp << std::setprecision(1) << std::fixed << value;
The abstract base class used by all types of agents that live and interact in a simulation.
const std::string prototype() const
Returns the agent's prototype.
std::string spec()
The string representation of the agent spec that uniquely identifies the concrete agent class/module.
Context * context() const
Returns this agent's simulation context.
virtual const int id() const
The agent instance's unique ID within a simulation.
Datum * NewDatum(std::string title)
See Recorder::NewDatum documentation.
Datum * AddVal(const char *field, boost::spirit::hold_any val, std::vector< int > *shape=NULL)
Add an arbitrary field-value pair to the datum.
void Record()
Record this datum to its Recorder.
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or....
void Warn(const std::string &msg)
Issue a warning with the approriate message, accoring to the current warning settings.
#define CYCLUS_DECIMAL_SECOND_MULTIPLIER