Libosmium  2.6.0
Fast and flexible C++ library for working with OpenStreetMap data
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
coordinates.hpp
Go to the documentation of this file.
1 #ifndef OSMIUM_GEOM_COORDINATES_HPP
2 #define OSMIUM_GEOM_COORDINATES_HPP
3 
4 /*
5 
6 This file is part of Osmium (http://osmcode.org/libosmium).
7 
8 Copyright 2013-2016 Jochen Topf <jochen@topf.org> and others (see README).
9 
10 Boost Software License - Version 1.0 - August 17th, 2003
11 
12 Permission is hereby granted, free of charge, to any person or organization
13 obtaining a copy of the software and accompanying documentation covered by
14 this license (the "Software") to use, reproduce, display, distribute,
15 execute, and transmit the Software, and to prepare derivative works of the
16 Software, and to permit third-parties to whom the Software is furnished to
17 do so, all subject to the following:
18 
19 The copyright notices in the Software and this entire statement, including
20 the above license grant, this restriction and the following disclaimer,
21 must be included in all copies of the Software, in whole or in part, and
22 all derivative works of the Software, unless such copies or derivative
23 works are solely in the form of machine-executable object code generated by
24 a source language processor.
25 
26 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28 FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
29 SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
30 FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
31 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
32 DEALINGS IN THE SOFTWARE.
33 
34 */
35 
36 #include <iosfwd>
37 #include <string>
38 
39 #include <osmium/osm/location.hpp>
40 #include <osmium/util/double.hpp>
41 
42 namespace osmium {
43 
44  namespace geom {
45 
46  struct Coordinates {
47 
48  double x;
49  double y;
50 
51  explicit Coordinates(double cx, double cy) noexcept : x(cx), y(cy) {
52  }
53 
54  Coordinates(const osmium::Location& location) : x(location.lon()), y(location.lat()) {
55  }
56 
57  void append_to_string(std::string& s, const char infix, int precision) const {
58  osmium::util::double2string(s, x, precision);
59  s += infix;
60  osmium::util::double2string(s, y, precision);
61  }
62 
63  void append_to_string(std::string& s, const char prefix, const char infix, const char suffix, int precision) const {
64  s += prefix;
65  append_to_string(s, infix, precision);
66  s += suffix;
67  }
68 
69  }; // struct coordinates
70 
76  inline bool operator==(const Coordinates& lhs, const Coordinates& rhs) noexcept {
77 #pragma GCC diagnostic push
78 #pragma GCC diagnostic ignored "-Wfloat-equal"
79  return lhs.x == rhs.x && lhs.y == rhs.y;
80 #pragma GCC diagnostic pop
81  }
82 
83  inline bool operator!=(const Coordinates& lhs, const Coordinates& rhs) noexcept {
84  return ! operator==(lhs, rhs);
85  }
86 
87  template <typename TChar, typename TTraits>
88  inline std::basic_ostream<TChar, TTraits>& operator<<(std::basic_ostream<TChar, TTraits>& out, const Coordinates& c) {
89  return out << '(' << c.x << ',' << c.y << ')';
90  }
91 
92  } // namespace geom
93 
94 } // namespace osmium
95 
96 #endif // OSMIUM_GEOM_COORDINATES_HPP
double y
Definition: coordinates.hpp:49
T double2string(T iterator, double value, int precision)
Definition: double.hpp:59
Namespace for everything in the Osmium library.
Definition: assembler.hpp:59
Definition: coordinates.hpp:46
void append_to_string(std::string &s, const char infix, int precision) const
Definition: coordinates.hpp:57
void append_to_string(std::string &s, const char prefix, const char infix, const char suffix, int precision) const
Definition: coordinates.hpp:63
Definition: location.hpp:79
bool operator!=(const Coordinates &lhs, const Coordinates &rhs) noexcept
Definition: coordinates.hpp:83
double x
Definition: coordinates.hpp:48
Coordinates(double cx, double cy) noexcept
Definition: coordinates.hpp:51
Coordinates(const osmium::Location &location)
Definition: coordinates.hpp:54
bool operator==(const Coordinates &lhs, const Coordinates &rhs) noexcept
Definition: coordinates.hpp:76