Use Math.round instead of Math.floor and Math.ceil for overlay placement.

This commit is contained in:
Antoine Vandecreme 2015-10-09 14:15:54 -04:00
parent eba50af8fd
commit 2c73b0fb44
3 changed files with 13 additions and 12 deletions

View File

@ -29,6 +29,7 @@ OPENSEADRAGON CHANGELOG
* Fix for Chrome (v45) issue that key is sometimes undefined outside of the for-in loop (#730)
* World.removeAll now cancels any in-flight image loads; same for Viewer.open and Viewer.close (#734)
* Optimized adding large numbers of items to the world with collectionMode (#735)
* Fix overlays position (use rounding instead of flooring and ceiling)
2.0.0:

View File

@ -250,8 +250,8 @@
this.adjust( position, size );
position = position.apply( Math.floor );
size = size.apply( Math.ceil );
position = position.apply( Math.round );
size = size.apply( Math.round );
// rotate the position of the overlay
// TODO only rotate overlays if in canvas mode

View File

@ -241,20 +241,20 @@
var viewport = viewer.viewport;
var expPosition = viewport.imageToViewerElementCoordinates(
new OpenSeadragon.Point( 13, 120 ) ).apply( Math.floor );
new OpenSeadragon.Point( 13, 120 ) ).apply( Math.round );
var actPosition = $( "#overlay" ).position();
equal( actPosition.left, expPosition.x, "X position mismatch " + contextMessage );
equal( actPosition.top, expPosition.y, "Y position mismatch " + contextMessage );
var zoom = viewport.viewportToImageZoom( viewport.getZoom( true ) );
var expectedWidth = Math.ceil( 124 * zoom );
var expectedHeight = Math.ceil( 132 * zoom );
var expectedWidth = Math.round( 124 * zoom );
var expectedHeight = Math.round( 132 * zoom );
equal( $( "#overlay" ).width(), expectedWidth, "Width mismatch " + contextMessage );
equal( $( "#overlay" ).height( ), expectedHeight, "Height mismatch " + contextMessage );
expPosition = viewport.imageToViewerElementCoordinates(
new OpenSeadragon.Point( 400, 500 ) ).apply( Math.floor );
new OpenSeadragon.Point( 400, 500 ) ).apply( Math.round );
actPosition = $( "#fixed-overlay" ).position();
equal( actPosition.left, expPosition.x, "Fixed overlay X position mismatch " + contextMessage );
equal( actPosition.top, expPosition.y, "Fixed overlay Y position mismatch " + contextMessage );
@ -305,7 +305,7 @@
var viewport = viewer.viewport;
var expPosition = viewport.viewportToViewerElementCoordinates(
new OpenSeadragon.Point( 0.2, 0.1 ) ).apply( Math.floor );
new OpenSeadragon.Point( 0.2, 0.1 ) ).apply( Math.round );
var actPosition = $( "#overlay" ).position();
equal( actPosition.left, expPosition.x, "X position mismatch " + contextMessage );
equal( actPosition.top, expPosition.y, "Y position mismatch " + contextMessage );
@ -317,7 +317,7 @@
expPosition = viewport.viewportToViewerElementCoordinates(
new OpenSeadragon.Point( 0.5, 0.6 ) ).apply( Math.floor );
new OpenSeadragon.Point( 0.5, 0.6 ) ).apply( Math.round );
actPosition = $( "#fixed-overlay" ).position();
equal( actPosition.left, expPosition.x, "Fixed overlay X position mismatch " + contextMessage );
equal( actPosition.top, expPosition.y, "Fixed overlay Y position mismatch " + contextMessage );
@ -373,7 +373,7 @@
var viewport = viewer.viewport;
var expPosition = viewport.viewportToViewerElementCoordinates(
new OpenSeadragon.Point( 0.2, 0.1 ) ).apply( Math.floor );
new OpenSeadragon.Point( 0.2, 0.1 ) ).apply( Math.round );
var actPosition = $( "#overlay" ).position();
equal( actPosition.left, expPosition.x, "X position mismatch " + contextMessage );
equal( actPosition.top, expPosition.y, "Y position mismatch " + contextMessage );
@ -384,7 +384,7 @@
var expPosition = viewport.viewportToViewerElementCoordinates(
new OpenSeadragon.Point( 0.5, 0.6 ) )
.apply( Math.floor )
.apply( Math.round )
.plus( expectedOffset );
var actPosition = $( "#fixed-overlay" ).position();
equal( actPosition.left, expPosition.x, "Fixed overlay X position mismatch " + contextMessage );
@ -447,7 +447,7 @@
var expPosition = viewport.viewportToViewerElementCoordinates(
new OpenSeadragon.Point( 0.5, 0.6 ) )
.apply( Math.floor )
.apply( Math.round )
.plus( expectedOffset );
var actPosition = $( "#fixed-overlay" ).position();
equal( actPosition.left, expPosition.x, "Fixed overlay X position mismatch " + contextMessage );
@ -501,7 +501,7 @@
var expPosition = viewport.viewportToViewerElementCoordinates(
new OpenSeadragon.Point( 0.5, 0.6 ) )
.apply( Math.floor )
.apply( Math.round )
.plus( expectedOffset );
var actPosition = $( "#fixed-overlay" ).position();
equal( actPosition.left, expPosition.x, "Fixed overlay X position mismatch " + contextMessage );