RMTile.c
1.56 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
70
71
/*
* Tile.c
* RouteMe
*
* Created by Joseph Gentle on 9/09/08.
* Copyright 2008 __MyCompanyName__. All rights reserved.
*
*/
#include "RMTile.h"
#import <math.h>
uint64_t RMTileHash(RMTile tile)
{
uint64_t accumulator = 0;
for (int i = 0; i < tile.zoom; i++) {
accumulator |= ((uint64_t)tile.x & (1LL<<i)) << i;
accumulator |= ((uint64_t)tile.y & (1LL<<i)) << (i+1);
}
accumulator |= 1LL<<(tile.zoom * 2);
return accumulator;
}
RMTile RMTileDummy()
{
RMTile t;
t.x = -1;
t.y = -1;
t.zoom = -1;
return t;
}
char RMTileIsDummy(RMTile tile)
{
return tile.x == -1 && tile.y == -1 && tile.zoom == -1;
}
char RMTilesEqual(RMTile one, RMTile two)
{
return (one.x == two.x) && (one.y == two.y) && (one.zoom == two.zoom);
}
// Round the rectangle to whole numbers of tiles
RMTileRect RMTileRectRound(RMTileRect rect)
{
rect.size.width = ceilf(rect.size.width + rect.origin.offset.x);
rect.size.height = ceilf(rect.size.height + rect.origin.offset.y);
rect.origin.offset.x = 0;
rect.origin.offset.y = 0;
return rect;
}
/*
// Calculate and return the intersection of two rectangles
TileRect TileRectIntersection(TileRect one, TileRect two)
{
TileRect intersection;
// NSCAssert (one.origin.tile.zoom != two.origin.tile.zoom, @"Intersecting tiles do not have matching zoom");
intersection.origin.tile.x = maxi(one.origin.tile.x, two.origin.tile.x);
intersection.origin.tile.y = maxi(one.origin.tile.y, two.origin.tile.y);
return intersection;
}
// Calculate and return the union of two rectangles
TileRect TileRectUnion(TileRect one, TileRect two);*/