MCPcopy Create free account
hub / github.com/comaps/comaps / FormatLatLonAsDMSImpl

Function FormatLatLonAsDMSImpl

libs/platform/measurement_utils.cpp:98–139  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

96}
97
98std::string FormatLatLonAsDMSImpl(double value, char positive, char negative, int dac)
99{
100 using namespace base;
101
102 std::ostringstream sstream;
103 sstream << std::setfill('0');
104
105 // Degrees
106 double i;
107 double d = std::modf(std::fabs(value), &i);
108 sstream << std::setw(2) << i << "°";
109
110 // Minutes
111 d = std::modf(d * 60.0, &i);
112 sstream << std::setw(2) << i << "′";
113
114 // Seconds
115 d = d * 60.0;
116 if (dac == 0)
117 d = std::round(d);
118
119 d = std::modf(d, &i);
120 sstream << std::setw(2) << i;
121
122 if (dac > 0)
123 sstream << strings::to_string_dac(d, dac).substr(1);
124
125 sstream << "″";
126
127 // This condition is too heavy for production purposes (but more correct).
128 // if (std::round(value * 3600.0 * pow(10, dac)) != 0)
129 if (!AlmostEqualULPs(value, 0.0))
130 {
131 char postfix = positive;
132 if (value < 0.0)
133 postfix = negative;
134
135 sstream << postfix;
136 }
137
138 return sstream.str();
139}
140
141std::string FormatLatLonAsDMS(double lat, double lon, bool withComma, int dac)
142{

Callers 2

FormatLatLonAsDMSFunction · 0.85
FormatMercatorAsDMSFunction · 0.85

Calls 2

to_string_dacFunction · 0.85
AlmostEqualULPsFunction · 0.50

Tested by

no test coverage detected