MapXL / route-me

Automatically exported from code.google.com/p/route-me
0 stars 0 forks source link

Tile positioning errors #128

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
When using overlays, we observed positioning errors where the tile positions 
were randomly off 
by a small amount (uniformly, no gaps); the overlay's position was stable and 
correct.

What is the expected output? What do you see instead?
Map tiles and overlay in sync. Should be able to drag and zoom the map without 
random 
misalignment (jitter).

What subversion release are you using? Does the behavior occur on the
simulator, a real iPhone/iPod Touch, or both?

r173. Occurs on simulator and device.

Analysis:
I tracked this down to a loss of precision in two places, one in our custom 
code, the other in 
route-me. The route-me bug is in RMTileImageSet.m, lines 210-211:

 screenLocation.origin.x = bounds.origin.x + (t.x - (rect.origin.offset.x + rect.origin.tile.x)) * 
pixelsPerTile;
 screenLocation.origin.y = bounds.origin.y + (t.y - (rect.origin.offset.y + rect.origin.tile.y)) * 
pixelsPerTile;

Here an integer (rect.origin.tile.x) and a single precision fractional part  
(rect.origin.offset.x) are 
added, producing a single-precision float with lost precision in the fraction. 
The larger the 
integer part, the more loss of precision. This is subtracted from the rounded 
integer part, 
effectively removing the integer component, leaving a degraded fraction. Most 
results I observed 
had a fraction of either .0 or .5.

Solution
A simple regrouping of terms solves the problem by subtracting the integer 
parts before 
combining with the fraction:

screenLocation.origin.x = bounds.origin.x + ((t.x - rect.origin.tile.x) - 
rect.origin.offset.x) * 
pixelsPerTile;
screenLocation.origin.y = bounds.origin.y + ((t.y - rect.origin.tile.y) - 
rect.origin.offset.y) * 
pixelsPerTile;

Original issue reported on code.google.com by david.d....@gmail.com on 8 Jan 2010 at 12:04

GoogleCodeExporter commented 8 years ago
Thanks for the analysis and the solution.
I commited the correction.

Original comment by vladimir...@gmail.com on 9 Feb 2010 at 10:01