Fix wrapping.

This commit is contained in:
Antoine Vandecreme 2016-10-23 22:25:16 +02:00
parent 77310b0229
commit a9b60057ea
2 changed files with 19 additions and 13 deletions

View File

@ -1058,16 +1058,12 @@ function updateLevel(tiledImage, haveDrawn, drawLevel, level, levelOpacity,
resetCoverage(tiledImage.coverage, level); resetCoverage(tiledImage.coverage, level);
if (tiledImage.wrapHorizontal) { if (!tiledImage.wrapHorizontal) {
topLeftTile.x -= 1; // left invisible column (othervise we will have empty space after scroll at left)
} else {
// Adjust for floating point error // Adjust for floating point error
topLeftTile.x = Math.max(topLeftTile.x, 0); topLeftTile.x = Math.max(topLeftTile.x, 0);
bottomRightTile.x = Math.min(bottomRightTile.x, numberOfTiles.x - 1); bottomRightTile.x = Math.min(bottomRightTile.x, numberOfTiles.x - 1);
} }
if (tiledImage.wrapVertical) { if (!tiledImage.wrapVertical) {
topLeftTile.y -= 1; // top invisible row (othervise we will have empty space after scroll at top)
} else {
// Adjust for floating point error // Adjust for floating point error
topLeftTile.y = Math.max(topLeftTile.y, 0); topLeftTile.y = Math.max(topLeftTile.y, 0);
bottomRightTile.y = Math.min(bottomRightTile.y, numberOfTiles.y - 1); bottomRightTile.y = Math.min(bottomRightTile.y, numberOfTiles.y - 1);
@ -1078,12 +1074,15 @@ function updateLevel(tiledImage, haveDrawn, drawLevel, level, levelOpacity,
for (var x = topLeftTile.x; x <= bottomRightTile.x; x++) { for (var x = topLeftTile.x; x <= bottomRightTile.x; x++) {
for (var y = topLeftTile.y; y <= bottomRightTile.y; y++) { for (var y = topLeftTile.y; y <= bottomRightTile.y; y++) {
// Optimisation disabled with wrapping because getTileBounds does not
// work correctly with x and y outside of the number of tiles
if (!tiledImage.wrapHorizontal && !tiledImage.wrapVertical) {
var tileBounds = tiledImage.source.getTileBounds(level, x, y); var tileBounds = tiledImage.source.getTileBounds(level, x, y);
if (drawArea.intersection(tileBounds) === null) { if (drawArea.intersection(tileBounds) === null) {
// This tile is outside of the viewport, no need to draw it // This tile is outside of the viewport, no need to draw it
continue; continue;
} }
}
best = updateTile( best = updateTile(
tiledImage, tiledImage,

View File

@ -346,10 +346,17 @@ $.TileSource.prototype = {
*/ */
getTileAtPoint: function(level, point) { getTileAtPoint: function(level, point) {
var widthScaled = this.dimensions.x * this.getLevelScale(level); var widthScaled = this.dimensions.x * this.getLevelScale(level);
var pixelX = point.x * widthScaled; var pixelX = $.positiveModulo(point.x, 1) * widthScaled;
var pixelY = point.y * widthScaled; var pixelY = $.positiveModulo(point.y, 1 / this.aspectRatio) * widthScaled;
var x = Math.floor(pixelX / this.getTileWidth()); var x = Math.floor(pixelX / this.getTileWidth());
var y = Math.floor(pixelY / this.getTileHeight()); var y = Math.floor(pixelY / this.getTileHeight());
// Fix for wrapping
var numTiles = this.getNumTiles(level);
x += numTiles.x * Math.floor(point.x);
y += numTiles.y * Math.floor(point.y * this.aspectRatio);
return new $.Point(x, y); return new $.Point(x, y);
}, },