libosmscout 1.1.1
Loading...
Searching...
No Matches
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
27
29
31
32#include <ostream>
33#include <string>
34#include <array>
35#include <type_traits>
36#include <tuple>
37
38namespace osmscout {
39
46 struct OSMSCOUT_API Pixel CLASS_FINAL
47 {
48 uint32_t x; // NOLINT
49 uint32_t y; // NOLINT
50
54 inline Pixel() = default;
55
56 Pixel(uint32_t x, uint32_t y)
57 :x(x),y(y)
58 {
59 // no code
60 }
61
62 bool operator==(const Pixel& other) const
63 {
64 return x==other.x && y==other.y;
65 }
66
67 bool operator!=(const Pixel& other) const
68 {
69 return y!=other.y || x!=other.x;
70 }
71
72 bool operator<(const Pixel& other) const
73 {
74 return std::tie(y, x) < std::tie(other.y, other.x);
75 }
76
82 uint64_t GetId() const
83 {
84 return InterleaveNumbers(x,y);
85 }
86
87 std::string GetDisplayText() const;
88
89 std::ostream& operator<<(std::ostream& stream) const
90 {
91 stream << GetDisplayText();
92 return stream;
93 }
94 };
95
101 class OSMSCOUT_API Vertex2D CLASS_FINAL
102 {
103 private:
104 std::array<double,2> coords;
105
106 public:
107 static const Vertex2D ZERO;
108
112 Vertex2D() = default;
113
114 Vertex2D(double x,
115 double y)
116 {
117 coords[0]=x;
118 coords[1]=y;
119 }
120
121 Vertex2D(const Vertex2D& other) = default;
122 Vertex2D(Vertex2D&& other) = default;
123
124 Vertex2D& operator=(const Vertex2D& other) = default;
125 Vertex2D& operator=(Vertex2D&& other) = default;
126
127 double GetX() const
128 {
129 return coords[0];
130 }
131
132 double GetY() const
133 {
134 return coords[1];
135 }
136
137 bool operator==(const Vertex2D& other) const
138 {
139 return coords[0]==other.coords[0] &&
140 coords[1]==other.coords[1];
141 }
142
143 bool operator<(const Vertex2D& other) const
144 {
145 return std::tie(coords[1], coords[0]) < std::tie(other.coords[1], other.coords[0]);
146 }
147
148 double DistanceTo(const Vertex2D &other) const {
149 double xDiff = coords[0] - other.coords[0];
150 double yDiff = coords[1] - other.coords[1];
151 return sqrt(xDiff*xDiff + yDiff*yDiff);
152 }
153 };
154
155 OSMSCOUT_API Vertex2D operator-(const Vertex2D &a, const Vertex2D &b);
156
157 OSMSCOUT_API Vertex2D operator+(const Vertex2D &a, const Vertex2D &b);
158
159 OSMSCOUT_API Vertex2D operator*(const Vertex2D &a, double scale);
160
161 // make sure that we may use std::memcpy on Vertex2D
162 static_assert(std::is_trivially_copyable_v<Vertex2D>);
163 static_assert(std::is_trivially_assignable_v<Vertex2D,Vertex2D>);
164
170 class OSMSCOUT_API Vertex3D CLASS_FINAL
171 {
172 private:
173 double x;
174 double y;
175 double z=0.0;
176
177 public:
181 Vertex3D() = default;
182
183 Vertex3D(const Vertex3D& other) = default;
184
185 Vertex3D(double x,
186 double y)
187 :x(x),
188 y(y)
189 {
190 // no code
191 }
192
193 double GetX() const
194 {
195 return x;
196 }
197
198 double GetY() const
199 {
200 return y;
201 }
202
203 double GetZ() const
204 {
205 return y;
206 }
207
208 void SetX(double x)
209 {
210 this->x=x;
211 }
212
213 void SetY(double y)
214 {
215 this->y=y;
216 }
217
218 void SetZ(double z)
219 {
220 this->z=z;
221 }
222
223 void Set(double x,
224 double y)
225 {
226 this->x=x;
227 this->y=y;
228 this->z=0;
229 }
230
231 void Set(double x,
232 double y,
233 double z)
234 {
235 this->x=x;
236 this->y=y;
237 this->z=z;
238 }
239
240 bool operator==(const Vertex3D& other) const
241 {
242 return x==other.x &&
243 y==other.y &&
244 z==other.z;
245 }
246
247 bool operator<(const Vertex3D& other) const
248 {
249 return std::tie(x, y, z) < std::tie(other.x, other.y, other.z);
250 }
251 };
252}
253
254#endif
#define CLASS_FINAL
Definition Compiler.h:26
#define OSMSCOUT_API
Definition CoreImportExport.h:45
Definition Area.h:88
bool operator<(const Vertex3D &other) const
Definition Pixel.h:247
Vertex2D & operator=(Vertex2D &&other)=default
Vertex2D(double x, double y)
Definition Pixel.h:114
bool operator==(const Pixel &other) const
Definition Pixel.h:62
Vertex2D(const Vertex2D &other)=default
double GetY() const
Definition Pixel.h:132
bool operator!=(const Pixel &other) const
Definition Pixel.h:67
Pixel(uint32_t x, uint32_t y)
Definition Pixel.h:56
std::vector< Coord > coords
Optional coordinates for coastline.
Definition GroundTile.h:99
Vertex3D(const Vertex3D &other)=default
uint64_t GetId() const
Definition Pixel.h:82
bool operator<(const Pixel &other) const
Definition Pixel.h:72
bool operator==(const Vertex2D &other) const
Definition Pixel.h:137
std::ostream & operator<<(std::ostream &stream) const
Definition Pixel.h:89
Vertex2D(Vertex2D &&other)=default
Vertex3D(double x, double y)
Definition Pixel.h:185
static const Vertex2D ZERO
Definition Pixel.h:107
Vertex2D & operator=(const Vertex2D &other)=default
uint32_t x
Definition Pixel.h:48
uint32_t y
Definition Pixel.h:49
bool operator<(const Vertex2D &other) const
Definition Pixel.h:143
double DistanceTo(const Vertex2D &other) const
Definition Pixel.h:148
void Set(double x, double y)
Definition Pixel.h:223
void SetY(double y)
Definition Pixel.h:213
double GetX() const
Definition Pixel.h:127
double GetZ() const
Definition Pixel.h:203
void Set(double x, double y, double z)
Definition Pixel.h:231
void SetX(double x)
Definition Pixel.h:208
void SetZ(double z)
Definition Pixel.h:218
bool operator==(const Vertex3D &other) const
Definition Pixel.h:240
std::string GetDisplayText() const
OSMSCOUT_API uint64_t InterleaveNumbers(uint32_t a, uint32_t b)
Definition Area.h:39
OSMSCOUT_API Vertex2D operator-(const Vertex2D &a, const Vertex2D &b)
OSMSCOUT_API Vertex2D operator+(const Vertex2D &a, const Vertex2D &b)
OSMSCOUT_API Vertex2D operator*(const Vertex2D &a, double scale)