libosmscout  1.1.1
Pixel.h
Go to the documentation of this file.
1 #ifndef OSMSCOUT_PIXEL_H
2 #define OSMSCOUT_PIXEL_H
3 
4 /*
5  This source is part of the libosmscout library
6  Copyright (C) 2013 Tim Teulings
7 
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Lesser General Public
10  License as published by the Free Software Foundation; either
11  version 2.1 of the License, or (at your option) any later version.
12 
13  This library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public
19  License along with this library; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22 
24 
26 #include <osmscout/system/Math.h>
27 
28 #include <osmscout/util/Number.h>
29 
31 
32 #include <string>
33 #include <array>
34 #include <type_traits>
35 #include <tuple>
36 
37 namespace osmscout {
38 
45  struct OSMSCOUT_API Pixel CLASS_FINAL
46  {
47  uint32_t x; // NOLINT
48  uint32_t y; // NOLINT
49 
53  inline Pixel() = default;
54 
55  Pixel(uint32_t x, uint32_t y)
56  :x(x),y(y)
57  {
58  // no code
59  }
60 
61  bool operator==(const Pixel& other) const
62  {
63  return x==other.x && y==other.y;
64  }
65 
66  bool operator!=(const Pixel& other) const
67  {
68  return y!=other.y || x!=other.x;
69  }
70 
71  bool operator<(const Pixel& other) const
72  {
73  return std::tie(y, x) < std::tie(other.y, other.x);
74  }
75 
81  uint64_t GetId() const
82  {
83  return InterleaveNumbers(x,y);
84  }
85 
86  std::string GetDisplayText() const;
87 
88  std::ostream& operator<<(std::ostream& stream) const
89  {
90  stream << GetDisplayText();
91  return stream;
92  }
93  };
94 
100  class OSMSCOUT_API Vertex2D CLASS_FINAL
101  {
102  private:
103  std::array<double,2> coords;
104 
105  public:
109  Vertex2D() = default;
110 
111  Vertex2D(double x,
112  double y)
113  {
114  coords[0]=x;
115  coords[1]=y;
116  }
117 
118  Vertex2D(const Vertex2D& other) = default;
119  Vertex2D(Vertex2D&& other) = default;
120 
121  Vertex2D& operator=(const Vertex2D& other) = default;
122  Vertex2D& operator=(Vertex2D&& other) = default;
123 
124  void SetX(double x)
125  {
126  coords[0]=x;
127  }
128 
129  void SetY(double y)
130  {
131  coords[1]=y;
132  }
133 
134  void Set(double x,
135  double y)
136  {
137  coords[0]=x;
138  coords[1]=y;
139  }
140 
141  double GetX() const
142  {
143  return coords[0];
144  }
145 
146  double GetY() const
147  {
148  return coords[1];
149  }
150 
151  bool operator==(const Vertex2D& other) const
152  {
153  return coords[0]==other.coords[0] &&
154  coords[1]==other.coords[1];
155  }
156 
157  bool operator<(const Vertex2D& other) const
158  {
159  return std::tie(coords[1], coords[0]) < std::tie(other.coords[1], other.coords[0]);
160  }
161 
162  double DistanceTo(const Vertex2D &other) const {
163  double xDiff = coords[0] - other.coords[0];
164  double yDiff = coords[1] - other.coords[1];
165  return sqrt(xDiff*xDiff + yDiff*yDiff);
166  }
167  };
168 
169  // make sure that we may use std::memcpy on Vertex2D
170  static_assert(std::is_trivially_copyable<Vertex2D>::value);
171  static_assert(std::is_trivially_assignable<Vertex2D,Vertex2D>::value);
172 
178  class OSMSCOUT_API Vertex3D CLASS_FINAL
179  {
180  private:
181  double x;
182  double y;
183  double z=0.0;
184 
185  public:
189  Vertex3D() = default;
190 
191  Vertex3D(const Vertex3D& other) = default;
192 
193  Vertex3D(double x,
194  double y)
195  :x(x),
196  y(y)
197  {
198  // no code
199  }
200 
201  double GetX() const
202  {
203  return x;
204  }
205 
206  double GetY() const
207  {
208  return y;
209  }
210 
211  double GetZ() const
212  {
213  return y;
214  }
215 
216  void SetX(double x)
217  {
218  this->x=x;
219  }
220 
221  void SetY(double y)
222  {
223  this->y=y;
224  }
225 
226  void SetZ(double z)
227  {
228  this->z=z;
229  }
230 
231  void Set(double x,
232  double y)
233  {
234  this->x=x;
235  this->y=y;
236  this->z=0;
237  }
238 
239  void Set(double x,
240  double y,
241  double z)
242  {
243  this->x=x;
244  this->y=y;
245  this->z=z;
246  }
247 
248  bool operator==(const Vertex3D& other) const
249  {
250  return x==other.x &&
251  y==other.y &&
252  z==other.z;
253  }
254 
255  bool operator<(const Vertex3D& other) const
256  {
257  return std::tie(x, y, z) < std::tie(other.x, other.y, other.z);
258  }
259  };
260 }
261 
262 #endif
void Set(double x, double y)
Definition: Pixel.h:134
Vertex3D(double x, double y)
Definition: Pixel.h:193
void Set(double x, double y, double z)
Definition: Pixel.h:239
Pixel(uint32_t x, uint32_t y)
Definition: Pixel.h:55
bool operator==(const Vertex2D &other) const
Definition: Pixel.h:151
std::ostream & operator<<(std::ostream &stream) const
Definition: Pixel.h:88
uint32_t x
Definition: Pixel.h:47
void SetX(double x)
Definition: Pixel.h:124
Vertex2D(double x, double y)
Definition: Pixel.h:111
bool operator<(const Vertex2D &other) const
Definition: Pixel.h:157
OSMSCOUT_API uint64_t InterleaveNumbers(uint32_t a, uint32_t b)
Definition: Area.h:38
double GetX() const
Definition: Pixel.h:141
#define CLASS_FINAL
Definition: Compiler.h:26
#define OSMSCOUT_API
Definition: CoreImportExport.h:45
void SetY(double y)
Definition: Pixel.h:129
uint64_t GetId() const
Definition: Pixel.h:81
double DistanceTo(const Vertex2D &other) const
Definition: Pixel.h:162
bool operator==(const Pixel &other) const
Definition: Pixel.h:61
uint32_t y
Definition: Pixel.h:48
bool operator<(const Pixel &other) const
Definition: Pixel.h:71
bool operator==(const Vertex3D &other) const
Definition: Pixel.h:248
bool operator<(const Vertex3D &other) const
Definition: Pixel.h:255
double GetY() const
Definition: Pixel.h:146
bool operator!=(const Pixel &other) const
Definition: Pixel.h:66
void SetZ(double z)
Definition: Pixel.h:226
double GetZ() const
Definition: Pixel.h:211