mirror of
https://github.com/openseadragon/openseadragon.git
synced 2024-11-25 06:36:11 +03:00
Clean up TileSource object when provided tileWidth/tileHeight for clarity. Add basic TileSource tests.
This commit is contained in:
parent
df7bd2e5ce
commit
e1e345a4bc
@ -191,11 +191,26 @@ $.TileSource = function( width, height, tileSize, tileOverlap, minLevel, maxLeve
|
|||||||
( options.width / options.height ) : 1;
|
( options.width / options.height ) : 1;
|
||||||
this.dimensions = new $.Point( options.width, options.height );
|
this.dimensions = new $.Point( options.width, options.height );
|
||||||
|
|
||||||
if ( options.tileSize ){
|
if ( this.tileSize ){
|
||||||
this._tileWidth = this._tileHeight = options.tileSize;
|
this._tileWidth = this._tileHeight = this.tileSize;
|
||||||
|
delete this.tileSize;
|
||||||
} else {
|
} else {
|
||||||
this._tileWidth = options.tileWidth ? options.tileWidth : 0;
|
if( this.tileWidth ){
|
||||||
this._tileHeight = options.tileHeight ? options.tileHeight: 0;
|
// We were passed tileWidth in options, but we want to rename it
|
||||||
|
// with a leading underscore to make clear that it is not safe to directly modify it
|
||||||
|
this._tileWidth = this.tileWidth;
|
||||||
|
delete this.tileWidth;
|
||||||
|
} else {
|
||||||
|
this._tileWidth = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( this.tileHeight ){
|
||||||
|
// See note above about renaming this.tileWidth
|
||||||
|
this._tileHeight = this.tileHeight;
|
||||||
|
delete this.tileHeight;
|
||||||
|
} else {
|
||||||
|
this._tileHeight = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.tileOverlap = options.tileOverlap ? options.tileOverlap : 0;
|
this.tileOverlap = options.tileOverlap ? options.tileOverlap : 0;
|
||||||
@ -230,7 +245,7 @@ $.TileSource.prototype = /** @lends OpenSeadragon.TileSource.prototype */{
|
|||||||
* Return the tileWidth for a given level.
|
* Return the tileWidth for a given level.
|
||||||
* Subclasses should override this if tileWidth can be different at different levels
|
* Subclasses should override this if tileWidth can be different at different levels
|
||||||
* such as in IIIFTileSource. Code should use this function rather than reading
|
* such as in IIIFTileSource. Code should use this function rather than reading
|
||||||
* from .tileWidth directly.
|
* from ._tileWidth directly.
|
||||||
* @function
|
* @function
|
||||||
* @param {Number} level
|
* @param {Number} level
|
||||||
*/
|
*/
|
||||||
@ -245,7 +260,7 @@ $.TileSource.prototype = /** @lends OpenSeadragon.TileSource.prototype */{
|
|||||||
* Return the tileHeight for a given level.
|
* Return the tileHeight for a given level.
|
||||||
* Subclasses should override this if tileHeight can be different at different levels
|
* Subclasses should override this if tileHeight can be different at different levels
|
||||||
* such as in IIIFTileSource. Code should use this function rather than reading
|
* such as in IIIFTileSource. Code should use this function rather than reading
|
||||||
* from .tileHeight directly.
|
* from ._tileHeight directly.
|
||||||
* @function
|
* @function
|
||||||
* @param {Number} level
|
* @param {Number} level
|
||||||
*/
|
*/
|
||||||
|
51
test/modules/tilesource.js
Normal file
51
test/modules/tilesource.js
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
/* global module, ok, equal, start, test, testLog, Util */
|
||||||
|
(function() {
|
||||||
|
|
||||||
|
module('TileSource', {
|
||||||
|
setup: function() {
|
||||||
|
testLog.reset();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
test("should set sane tile size defaults", function() {
|
||||||
|
var source = new OpenSeadragon.TileSource();
|
||||||
|
|
||||||
|
equal(source.getTileWidth(), 0, "getTileWidth() should return 0 if not provided a size");
|
||||||
|
equal(source.getTileHeight(), 0, "getTileHeight() should return 0 if not provided a size");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("providing tileSize", function(){
|
||||||
|
var tileSize = 256,
|
||||||
|
source = new OpenSeadragon.TileSource({
|
||||||
|
tileSize: tileSize
|
||||||
|
});
|
||||||
|
|
||||||
|
equal(source.tileSize, undefined, "tileSize should not be set on the tileSource");
|
||||||
|
equal(source.getTileWidth(), tileSize, "getTileWidth() should equal tileSize");
|
||||||
|
equal(source.getTileHeight(), tileSize, "getTileHeight() should equal tileSize");
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
test("providing tileWidth and tileHeight", function(){
|
||||||
|
var tileWidth = 256,
|
||||||
|
tileHeight = 512,
|
||||||
|
source = new OpenSeadragon.TileSource({
|
||||||
|
tileWidth: tileWidth,
|
||||||
|
tileHeight: tileHeight
|
||||||
|
});
|
||||||
|
|
||||||
|
equal(source._tileWidth, tileWidth, "tileWidth option should set _tileWidth");
|
||||||
|
equal(source._tileHeight, tileHeight, "tileHeight option should set _tileHeight");
|
||||||
|
equal(source.tileWidth, undefined, "tileWidth should be renamed _tileWidth");
|
||||||
|
equal(source.tileHeight, undefined, "tileHeight should be renamed _tileHeight");
|
||||||
|
equal(source.getTileWidth(), tileWidth, "getTileWidth() should equal tileWidth");
|
||||||
|
equal(source.getTileHeight(), tileHeight, "getTileHeight() should equal tileHeight");
|
||||||
|
});
|
||||||
|
|
||||||
|
test('getTileSize() deprecation', function() {
|
||||||
|
var source = new OpenSeadragon.TileSource();
|
||||||
|
Util.testDeprecation(source, 'getTileSize');
|
||||||
|
});
|
||||||
|
|
||||||
|
}());
|
@ -36,6 +36,7 @@
|
|||||||
<script src="/test/modules/tiledimage.js"></script>
|
<script src="/test/modules/tiledimage.js"></script>
|
||||||
<script src="/test/modules/tilecache.js"></script>
|
<script src="/test/modules/tilecache.js"></script>
|
||||||
<script src="/test/modules/referencestrip.js"></script>
|
<script src="/test/modules/referencestrip.js"></script>
|
||||||
|
<script src="/test/modules/tilesource.js"></script>
|
||||||
<script src="/test/modules/tilesourcecollection.js"></script>
|
<script src="/test/modules/tilesourcecollection.js"></script>
|
||||||
<script src="/test/modules/spring.js"></script>
|
<script src="/test/modules/spring.js"></script>
|
||||||
<!-- The navigator tests are the slowest (for now; hopefully they can be sped up)
|
<!-- The navigator tests are the slowest (for now; hopefully they can be sped up)
|
||||||
|
Loading…
Reference in New Issue
Block a user