1 #ifndef OSMIUM_OSM_LOCATION_HPP 2 #define OSMIUM_OSM_LOCATION_HPP 57 std::range_error(what) {
61 std::range_error(what) {
91 static constexpr int32_t undefined_coordinate = 2147483647;
93 static constexpr
int coordinate_precision = 10000000;
96 return static_cast<int32_t
>(std::round(c * coordinate_precision));
100 return static_cast<double>(c) / coordinate_precision;
107 m_x(undefined_coordinate),
108 m_y(undefined_coordinate) {
116 constexpr
Location(
const int32_t x,
const int32_t y) noexcept :
126 constexpr
Location(
const int64_t x,
const int64_t y) noexcept :
127 m_x(static_cast<int32_t>(x)),
128 m_y(static_cast<int32_t>(y)) {
135 m_x(double_to_fix(lon)),
136 m_y(double_to_fix(lat)) {
149 explicit constexpr
operator bool() const noexcept {
150 return m_x != undefined_coordinate && m_y != undefined_coordinate;
157 constexpr
bool valid() const noexcept {
158 return m_x >= -180 * coordinate_precision
159 && m_x <= 180 * coordinate_precision
160 && m_y >= -90 * coordinate_precision
161 && m_y <= 90 * coordinate_precision;
164 constexpr int32_t
x() const noexcept {
168 constexpr int32_t
y() const noexcept {
191 return fix_to_double(m_x);
198 return fix_to_double(m_x);
210 return fix_to_double(m_y);
217 return fix_to_double(m_y);
221 m_x = double_to_fix(lon);
226 m_y = double_to_fix(lat);
230 template <
typename T>
233 *iterator++ = separator;
243 return lhs.x() == rhs.x() && lhs.y() == rhs.y();
247 return ! (lhs == rhs);
256 return (lhs.x() == rhs.x() && lhs.y() < rhs.y()) || lhs.x() < rhs.x();
264 return ! (rhs < lhs);
268 return ! (lhs < rhs);
274 template <
typename TChar,
typename TTraits>
275 inline std::basic_ostream<TChar, TTraits>& operator<<(std::basic_ostream<TChar, TTraits>& out,
const osmium::Location& location) {
278 location.
as_string(std::ostream_iterator<char>(out),
',');
281 out <<
"(undefined,undefined)";
290 return location.
x() ^ location.
y();
295 size_t h = location.
x();
297 return h ^ location.
y();
308 #pragma clang diagnostic push 309 #pragma clang diagnostic ignored "-Wmismatched-tags" 316 return osmium::detail::hash<sizeof(size_t)>(location);
320 #pragma clang diagnostic pop 325 #endif // OSMIUM_OSM_LOCATION_HPP double lat_without_check() const
Definition: location.hpp:216
static int32_t double_to_fix(const double c) noexcept
Definition: location.hpp:95
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:220
Definition: reader_iterator.hpp:39
constexpr Location(const int64_t x, const int64_t y) noexcept
Definition: location.hpp:126
constexpr Location(const int32_t x, const int32_t y) noexcept
Definition: location.hpp:116
T double2string(T iterator, double value, int precision)
Definition: double.hpp:59
constexpr bool valid() const noexcept
Definition: location.hpp:157
double lat() const
Definition: location.hpp:206
size_t operator()(const osmium::Location &location) const noexcept
Definition: location.hpp:315
bool operator<(const Changeset &lhs, const Changeset &rhs)
Definition: changeset.hpp:438
double lon_without_check() const
Definition: location.hpp:197
Namespace for everything in the Osmium library.
Definition: assembler.hpp:66
Definition: location.hpp:54
int32_t m_y
Definition: location.hpp:83
constexpr int32_t y() const noexcept
Definition: location.hpp:168
invalid_location(const std::string &what)
Definition: location.hpp:56
T as_string(T iterator, const char separator) const
Definition: location.hpp:231
Location & set_lat(double lat) noexcept
Definition: location.hpp:225
Location & set_y(const int32_t y) noexcept
Definition: location.hpp:177
Definition: location.hpp:80
int32_t m_x
Definition: location.hpp:82
Location & set_x(const int32_t x) noexcept
Definition: location.hpp:172
bool operator>=(const Changeset &lhs, const Changeset &rhs)
Definition: changeset.hpp:450
double lon() const
Definition: location.hpp:187
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:164
static constexpr double fix_to_double(const int32_t c) noexcept
Definition: location.hpp:99
Location(const double lon, const double lat)
Definition: location.hpp:134
bool operator!=(const Changeset &lhs, const Changeset &rhs)
Definition: changeset.hpp:431
size_t result_type
Definition: location.hpp:314
constexpr Location() noexcept
Definition: location.hpp:106