From ce45e34265d27de835ae40e6b486deb14f70c6ba Mon Sep 17 00:00:00 2001
From: filak <filak@users.noreply.github.com>
Date: Mon, 26 Sep 2022 17:26:43 +0200
Subject: [PATCH] Update iiiftilesource.js

---
 src/iiiftilesource.js | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/iiiftilesource.js b/src/iiiftilesource.js
index d1331cd3..44acbb36 100644
--- a/src/iiiftilesource.js
+++ b/src/iiiftilesource.js
@@ -134,7 +134,7 @@ $.IIIFTileSource = function( options ){
 
     if (!options.maxLevel && !this.emulateLegacyImagePyramid) {
         if (!this.scale_factors) {
-            options.maxLevel = Number(Math.ceil(Math.log(Math.max(this.width, this.height), 2)));
+            options.maxLevel = Number(Math.round(Math.log(Math.max(this.width, this.height), 2)));
         } else {
             var maxScaleFactor = Math.max.apply(null, this.scale_factors);
             options.maxLevel = Math.round(Math.log(maxScaleFactor) * Math.LOG2E);
@@ -377,8 +377,8 @@ $.extend( $.IIIFTileSource.prototype, $.TileSource.prototype, /** @lends OpenSea
             scale = Math.pow( 0.5, this.maxLevel - level ),
 
             //# image dimensions at this level
-            levelWidth = Math.ceil( this.width * scale ),
-            levelHeight = Math.ceil( this.height * scale ),
+            levelWidth = Math.round( this.width * scale ),
+            levelHeight = Math.round( this.height * scale ),
 
             //## iiif region
             tileWidth,
@@ -398,8 +398,8 @@ $.extend( $.IIIFTileSource.prototype, $.TileSource.prototype, /** @lends OpenSea
 
         tileWidth = this.getTileWidth(level);
         tileHeight = this.getTileHeight(level);
-        iiifTileSizeWidth = Math.ceil( tileWidth / scale );
-        iiifTileSizeHeight = Math.ceil( tileHeight / scale );
+        iiifTileSizeWidth = Math.round( tileWidth / scale );
+        iiifTileSizeHeight = Math.round( tileHeight / scale );
         if (this.version === 1) {
             iiifQuality = "native." + this.tileFormat;
         } else {
@@ -426,8 +426,8 @@ $.extend( $.IIIFTileSource.prototype, $.TileSource.prototype, /** @lends OpenSea
             } else {
                 iiifRegion = [ iiifTileX, iiifTileY, iiifTileW, iiifTileH ].join( ',' );
             }
-            iiifSizeW = Math.ceil( iiifTileW * scale );
-            iiifSizeH = Math.ceil( iiifTileH * scale );
+            iiifSizeW = Math.round( iiifTileW * scale );
+            iiifSizeH = Math.round( iiifTileH * scale );
             if ( this.version === 2 && iiifSizeW === this.width ) {
                 iiifSize = "full";
             } else if ( this.version === 3 && iiifSizeW === this.width && iiifSizeH === this.height ) {