1 #ifndef OSMIUM_OSM_LOCATION_HPP 2 #define OSMIUM_OSM_LOCATION_HPP 57 std::range_error(what) {
61 std::range_error(what) {
68 constexpr
const int coordinate_precision = 10000000;
72 inline int32_t string_to_location_coordinate(
const char* str) {
73 const char* full = str;
86 if (*str >=
'0' && *str <=
'9') {
94 if (*str >=
'0' && *str <=
'9') {
95 result = result * 10 + *str -
'0';
99 if (*str >=
'0' && *str <=
'9') {
100 result = result * 10 + *str -
'0';
115 for (; scale > 0 && *str >=
'0' && *str <=
'9'; --scale, ++str) {
116 result = result * 10 + (*str -
'0');
120 if (scale == 0 && *str >=
'5' && *str <=
'9') {
126 while (*str >=
'0' && *str <=
'9') {
137 for (; scale > 0; --scale) {
141 return result * sign;
145 throw invalid_location{std::string{
"wrong format for coordinate: '"} + full +
"'"};
149 template <
typename T>
150 inline T append_location_coordinate_to_string(T iterator, int32_t value) {
162 *t++ = char(v % 10) +
'0';
171 if (value >= coordinate_precision) {
172 if (value >= 10 * coordinate_precision) {
173 if (value >= 100 * coordinate_precision) {
184 const char* tn = temp;
185 while (tn < t && *tn ==
'0') {
227 static constexpr int32_t undefined_coordinate = 2147483647;
230 return static_cast<int32_t
>(std::round(c * detail::coordinate_precision));
234 return static_cast<double>(c) / detail::coordinate_precision;
241 m_x(undefined_coordinate),
242 m_y(undefined_coordinate) {
250 constexpr
Location(
const int32_t x,
const int32_t y) noexcept :
260 constexpr
Location(
const int64_t x,
const int64_t y) noexcept :
261 m_x(static_cast<int32_t>(x)),
262 m_y(static_cast<int32_t>(y)) {
269 m_x(double_to_fix(lon)),
270 m_y(double_to_fix(lat)) {
283 explicit constexpr
operator bool() const noexcept {
284 return m_x != undefined_coordinate && m_y != undefined_coordinate;
291 constexpr
bool valid() const noexcept {
292 return m_x >= -180 * detail::coordinate_precision
293 && m_x <= 180 * detail::coordinate_precision
294 && m_y >= -90 * detail::coordinate_precision
295 && m_y <= 90 * detail::coordinate_precision;
298 constexpr int32_t
x() const noexcept {
302 constexpr int32_t
y() const noexcept {
325 return fix_to_double(m_x);
332 return fix_to_double(m_x);
344 return fix_to_double(m_y);
351 return fix_to_double(m_y);
355 m_x = double_to_fix(lon);
360 m_y = double_to_fix(lat);
365 m_x = detail::string_to_location_coordinate(str);
370 m_y = detail::string_to_location_coordinate(str);
374 template <
typename T>
375 T
as_string(T iterator,
const char separator =
',')
const {
379 iterator = detail::append_location_coordinate_to_string(iterator, x());
380 *iterator++ = separator;
381 return detail::append_location_coordinate_to_string(iterator, y());
390 return lhs.x() == rhs.x() && lhs.y() == rhs.y();
394 return ! (lhs == rhs);
403 return (lhs.x() == rhs.x() && lhs.y() < rhs.y()) || lhs.x() < rhs.x();
411 return ! (rhs < lhs);
415 return ! (lhs < rhs);
421 template <
typename TChar,
typename TTraits>
422 inline std::basic_ostream<TChar, TTraits>& operator<<(std::basic_ostream<TChar, TTraits>& out,
const osmium::Location& location) {
425 location.
as_string(std::ostream_iterator<char>(out),
',');
428 out <<
"(undefined,undefined)";
437 return location.
x() ^ location.
y();
442 size_t h = location.
x();
444 return h ^ location.
y();
455 #pragma clang diagnostic push 456 #pragma clang diagnostic ignored "-Wmismatched-tags" 463 return osmium::detail::hash<sizeof(size_t)>(location);
467 #pragma clang diagnostic pop 472 #endif // OSMIUM_OSM_LOCATION_HPP double lat_without_check() const
Definition: location.hpp:350
static int32_t double_to_fix(const double c) noexcept
Definition: location.hpp:229
bool operator<=(const Changeset &lhs, const Changeset &rhs)
Definition: changeset.hpp:446
constexpr bool operator==(const Box &lhs, const Box &rhs) noexcept
Definition: box.hpp:222
Location & set_lon(double lon) noexcept
Definition: location.hpp:354
Definition: reader_iterator.hpp:39
constexpr Location(const int64_t x, const int64_t y) noexcept
Definition: location.hpp:260
constexpr Location(const int32_t x, const int32_t y) noexcept
Definition: location.hpp:250
constexpr bool valid() const noexcept
Definition: location.hpp:291
double lat() const
Definition: location.hpp:340
T as_string(T iterator, const char separator= ',') const
Definition: location.hpp:375
size_t operator()(const osmium::Location &location) const noexcept
Definition: location.hpp:462
bool operator<(const Changeset &lhs, const Changeset &rhs)
Definition: changeset.hpp:438
double lon_without_check() const
Definition: location.hpp:331
Namespace for everything in the Osmium library.
Definition: assembler.hpp:66
Definition: location.hpp:54
int32_t m_y
Definition: location.hpp:219
constexpr int32_t y() const noexcept
Definition: location.hpp:302
invalid_location(const std::string &what)
Definition: location.hpp:56
Location & set_lat(double lat) noexcept
Definition: location.hpp:359
Location & set_y(const int32_t y) noexcept
Definition: location.hpp:311
Location & set_lat(const char *str) noexcept
Definition: location.hpp:369
Definition: location.hpp:216
int32_t m_x
Definition: location.hpp:218
Location & set_x(const int32_t x) noexcept
Definition: location.hpp:306
bool operator>=(const Changeset &lhs, const Changeset &rhs)
Definition: changeset.hpp:450
double lon() const
Definition: location.hpp:321
Location & set_lon(const char *str) noexcept
Definition: location.hpp:364
bool operator>(const Changeset &lhs, const Changeset &rhs)
Definition: changeset.hpp:442
invalid_location(const char *what)
Definition: location.hpp:60
constexpr int32_t x() const noexcept
Definition: location.hpp:298
static constexpr double fix_to_double(const int32_t c) noexcept
Definition: location.hpp:233
Location(const double lon, const double lat)
Definition: location.hpp:268
bool operator!=(const Changeset &lhs, const Changeset &rhs)
Definition: changeset.hpp:431
size_t result_type
Definition: location.hpp:461
constexpr Location() noexcept
Definition: location.hpp:240