Skip to content

Commit c943d7f

Browse files
committed
fix off by 1 error in tile calcs
1 parent f187a04 commit c943d7f

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ abaculus.tileList = function(z, s, center, tileSize) {
7373
y = center.y,
7474
w = center.w,
7575
h = center.h;
76-
var dimensions = {x: w, y: h};
76+
var dimensions = {x: w - 1, y: h - 1};
7777
var size = tileSize || 256;
7878
var ts = Math.floor(size * s);
7979

test/test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,27 @@ describe('create list of tile coordinates', function() {
144144
var coords = printer.tileList(zoom, scale, center);
145145
assert.deepEqual(JSON.stringify(coords), JSON.stringify(expectedCoords));
146146
});
147+
it('should avoid extranious images', function() {
148+
var zoom = 11,
149+
scale = 1,
150+
width = 256,
151+
height = 256,
152+
center = { w: width, h: height, x: 118912, y: 214912 };
147153

154+
var expectedCoords = {
155+
tiles: [
156+
{ z: 11, x: 464, y: 839, px: 0, py: 0},
157+
// {z: 11, x: 464, y: 840, px: 0, py: 256 },
158+
// { z: 11, x: 465, y: 839, px: 256, py: 0 },
159+
// { z: 11, x: 465, y: 840, px: 256, py: 256 }
160+
],
161+
dimensions: {x: width, y: height},
162+
center: { row: 839, column: 464, zoom: 11 },
163+
scale: scale
164+
};
165+
var coords = printer.tileList(zoom, scale, center);
166+
assert.deepEqual(JSON.stringify(coords), JSON.stringify(expectedCoords));
167+
});
148168
it('should return a tiles object with correct coords when image is much bigger than world', function() {
149169
var zoom = 1,
150170
scale = 1,

0 commit comments

Comments
 (0)