-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTileRange.h
More file actions
69 lines (59 loc) · 1.63 KB
/
TileRange.h
File metadata and controls
69 lines (59 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#pragma once
// Disable long identifiers warning
#pragma warning(disable : 4786)
#include "TileKey.h"
/**
* Represents a range (rectangle) of tiles for a specific zoom level and style
*
* Left will be larger then right when international date line is visible.
* Left and right being equal means complete span (from East to West) is visible.
*/
class TileRange {
public:
std::string styleUrlTemplate;
int zoomLevel;
int left;
int right;
int top;
int bottom;
TileRange(std::string styleUrlTemplate, int zoomLevel, int xMin, int xMax, int yMin, int yMax)
: styleUrlTemplate(styleUrlTemplate), zoomLevel(zoomLevel), left(xMin), right(xMax), top(yMin), bottom(yMax) {
maxExtend = 1 << zoomLevel;
if (xMax < 0) {
throw "Invalid rectangle (xMax was negative).";
}
if (yMax < 0 || yMax > maxExtend) {
throw "Invalid rectangle (yMax) for this zoom level.";
}
// Normalize complete x range spans
if (xMin == xMax || xMax - xMin >= maxExtend) {
left = 0;
right = 0;
} else {
left = left % maxExtend;
right = right % maxExtend;
}
};
bool contains(const TileKey& tile) const {
if (tile.zoomLevel != zoomLevel || tile.styleUrlTemplate != styleUrlTemplate) {
return false;
}
if (tile.x < 0 || tile.y < 0 || tile.x >= maxExtend || tile.y >= maxExtend) {
throw "Invalid TileKey encountered.";
}
if (tile.y < top || tile.y > bottom) {
return false;
}
if (left <= right) {
if (left == right) {
// complete extend
return true;
}
return tile.x >= left && tile.x < right;
} else {
return (tile.x >= left && tile.x < maxExtend) || (tile.x < right);
}
}
private:
int maxExtend;
};