From 274df71c0ad12628df89f9a8cf39c76c366072f1 Mon Sep 17 00:00:00 2001
From: thatcher <thatcher.christopher@gmail.com>
Date: Fri, 1 Mar 2013 08:42:06 -0500
Subject: [PATCH] refs #22 use Math.pow per houseofyin and memoize
 implementation of getLevelScale per acdha

---
 src/tilesource.js | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/src/tilesource.js b/src/tilesource.js
index 142609cb..51b0f03f 100644
--- a/src/tilesource.js
+++ b/src/tilesource.js
@@ -141,7 +141,19 @@ $.TileSource.prototype = {
      * @param {Number} level
      */
     getLevelScale: function( level ) {
-        return 1 / ( 1 << ( this.maxLevel - level ) );
+
+        // see https://github.com/openseadragon/openseadragon/issues/22
+        // we use the tilesources implementation of getLevelScale to generate
+        // a memoized re-implementation
+        var levelScaleCache = {},
+            i;
+        for( i = 0; i <= this.maxLevel; i++ ){
+            levelScaleCache[ i ] = 1 / Math.pow(2, this.maxLevel - i);
+        }
+        this.getLevelScale = function( _level ){
+            return levelScaleCache[ _level ];
+        };
+        return this.getLevelScale( level );
     },
 
     /**