[Marble-commits] KDE/kdeedu/marble/src/lib
Jens-Michael Hoffmann
jensmh at gmx.de
Mon Apr 26 12:28:46 CEST 2010
SVN commit 1118973 by jmhoffmann:
TileCoordsPyramid: improve accuracy of tile coordinates and tiles count calculations.
Use bottom level coordinates for calculations instead of top level coordinates,
so we don't loose information.
M +30 -28 DownloadRegionDialog.cpp
M +14 -14 TileCoordsPyramid.cpp
M +1 -1 TileCoordsPyramid.h
--- trunk/KDE/kdeedu/marble/src/lib/DownloadRegionDialog.cpp #1118972:1118973
@@ -221,44 +221,46 @@
int const visibleLevelX2 = qMax( westX, eastX );
int const visibleLevelY2 = qMax( northY, southY );
- mDebug() << "visible level pixel coords (x1/y1/x2/y2):"
+ mDebug() << "visible level pixel coords (level/x1/y1/x2/y2):" << d->m_originatingTileLevel
<< visibleLevelX1 << visibleLevelY1 << visibleLevelX2 << visibleLevelY2;
- int topLevelX1, topLevelY1, topLevelX2, topLevelY2;
+ int bottomLevelX1, bottomLevelY1, bottomLevelX2, bottomLevelY2;
// the pixel coords calculated above are referring to the originating ("visible") tile level,
- // if the top level is now a different level, we have to take it into account
- if ( d->m_originatingTileLevel > d->m_tileLevelRangeWidget->topLevel() ) {
- int const deltaLevel = d->m_originatingTileLevel - d->m_tileLevelRangeWidget->topLevel();
- topLevelX1 = visibleLevelX1 >> deltaLevel;
- topLevelY1 = visibleLevelY1 >> deltaLevel;
- topLevelX2 = visibleLevelX2 >> deltaLevel;
- topLevelY2 = visibleLevelY2 >> deltaLevel;
+ // if the bottom level is a different level, we have to take it into account
+ if ( d->m_originatingTileLevel > d->m_tileLevelRangeWidget->bottomLevel() ) {
+ int const deltaLevel = d->m_originatingTileLevel - d->m_tileLevelRangeWidget->bottomLevel();
+ bottomLevelX1 = visibleLevelX1 >> deltaLevel;
+ bottomLevelY1 = visibleLevelY1 >> deltaLevel;
+ bottomLevelX2 = visibleLevelX2 >> deltaLevel;
+ bottomLevelY2 = visibleLevelY2 >> deltaLevel;
}
- else if ( d->m_originatingTileLevel < d->m_tileLevelRangeWidget->topLevel() ) {
- int const deltaLevel = d->m_tileLevelRangeWidget->topLevel() - d->m_originatingTileLevel;
- topLevelX1 = visibleLevelX1 << deltaLevel;
- topLevelY1 = visibleLevelY1 << deltaLevel;
- topLevelX2 = visibleLevelX2 << deltaLevel;
- topLevelY2 = visibleLevelY2 << deltaLevel;
+ else if ( d->m_originatingTileLevel < d->m_tileLevelRangeWidget->bottomLevel() ) {
+ int const deltaLevel = d->m_tileLevelRangeWidget->bottomLevel() - d->m_originatingTileLevel;
+ bottomLevelX1 = visibleLevelX1 << deltaLevel;
+ bottomLevelY1 = visibleLevelY1 << deltaLevel;
+ bottomLevelX2 = visibleLevelX2 << deltaLevel;
+ bottomLevelY2 = visibleLevelY2 << deltaLevel;
}
else {
- topLevelX1 = visibleLevelX1;
- topLevelY1 = visibleLevelY1;
- topLevelX2 = visibleLevelX2;
- topLevelY2 = visibleLevelY2;
+ bottomLevelX1 = visibleLevelX1;
+ bottomLevelY1 = visibleLevelY1;
+ bottomLevelX2 = visibleLevelX2;
+ bottomLevelY2 = visibleLevelY2;
}
- mDebug() << "top level pixel coords: (x1/y1/x2/y2):"
- << topLevelX1 << topLevelY1 << topLevelX2 << topLevelY2;
+ mDebug() << "bottom level pixel coords (level/x1/y1/x2/y2):"
+ << d->m_tileLevelRangeWidget->bottomLevel()
+ << bottomLevelX1 << bottomLevelY1 << bottomLevelX2 << bottomLevelY2;
TileCoordsPyramid coordsPyramid( d->m_tileLevelRangeWidget->topLevel(),
d->m_tileLevelRangeWidget->bottomLevel() );
- QRect topLevelTileCoords;
- topLevelTileCoords.setCoords( topLevelX1 / tileWidth,
- topLevelY1 / tileHeight,
- topLevelX2 / tileWidth + ( topLevelX2 % tileWidth > 0 ? 1 : 0 ),
- topLevelY2 / tileHeight + ( topLevelY2 % tileHeight > 0 ? 1 : 0 ));
- mDebug() << "top level tile coords: (x1/y1/size):" << topLevelTileCoords;
- coordsPyramid.setTopLevelCoords( topLevelTileCoords );
+ QRect bottomLevelTileCoords;
+ bottomLevelTileCoords.setCoords
+ ( bottomLevelX1 / tileWidth,
+ bottomLevelY1 / tileHeight,
+ bottomLevelX2 / tileWidth + ( bottomLevelX2 % tileWidth > 0 ? 1 : 0 ),
+ bottomLevelY2 / tileHeight + ( bottomLevelY2 % tileHeight > 0 ? 1 : 0 ));
+ mDebug() << "bottom level tile coords: (x1/y1/size):" << bottomLevelTileCoords;
+ coordsPyramid.setBottomLevelCoords( bottomLevelTileCoords );
mDebug() << "tiles count:" << coordsPyramid.tilesCount();
return coordsPyramid;
}
--- trunk/KDE/kdeedu/marble/src/lib/TileCoordsPyramid.cpp #1118972:1118973
@@ -25,7 +25,7 @@
int m_topLevel;
int m_bottomLevel;
- QRect m_topLevelCoords;
+ QRect m_bottomLevelCoords;
};
TileCoordsPyramid::Private::Private( int const topLevel, int const bottomLevel )
@@ -68,21 +68,21 @@
return d->m_bottomLevel;
}
-void TileCoordsPyramid::setTopLevelCoords( QRect const & coords )
+void TileCoordsPyramid::setBottomLevelCoords( QRect const & coords )
{
- d->m_topLevelCoords = coords;
+ d->m_bottomLevelCoords = coords;
}
QRect TileCoordsPyramid::coords( int const level ) const
{
Q_ASSERT( d->m_topLevel <= level && level <= d->m_bottomLevel );
- int topX1, topY1, topX2, topY2;
- d->m_topLevelCoords.getCoords( &topX1, &topY1, &topX2, &topY2 );
- int const deltaLevel = level - d->m_topLevel;
- int const x1 = topX1 << deltaLevel;
- int const y1 = topY1 << deltaLevel;
- int const x2 = (( topX2 + 1 ) << deltaLevel ) -1;
- int const y2 = (( topY2 + 1 ) << deltaLevel ) -1;
+ int bottomX1, bottomY1, bottomX2, bottomY2;
+ d->m_bottomLevelCoords.getCoords( &bottomX1, &bottomY1, &bottomX2, &bottomY2 );
+ int const deltaLevel = d->m_bottomLevel - level;
+ int const x1 = bottomX1 >> deltaLevel;
+ int const y1 = bottomY1 >> deltaLevel;
+ int const x2 = bottomX2 >> deltaLevel;
+ int const y2 = bottomY2 >> deltaLevel;
QRect result;
result.setCoords( x1, y1, x2, y2 );
return result;
@@ -90,11 +90,11 @@
qint64 TileCoordsPyramid::tilesCount() const
{
- qint64 const topLevelTilesCount = d->m_topLevelCoords.width() * d->m_topLevelCoords.height();
- int const levels = d->m_bottomLevel - d->m_topLevel + 1;
qint64 result = 0;
- for ( int i = 0; i < levels; ++i )
- result += topLevelTilesCount << ( 2 * i );
+ for ( int level = d->m_topLevel; level <= d->m_bottomLevel; ++level ) {
+ QRect const levelCoords = coords( level );
+ result += levelCoords.width() * levelCoords.height();
+ }
return result;
}
--- trunk/KDE/kdeedu/marble/src/lib/TileCoordsPyramid.h #1118972:1118973
@@ -30,7 +30,7 @@
int topLevel() const;
int bottomLevel() const;
- void setTopLevelCoords( QRect const & coords );
+ void setBottomLevelCoords( QRect const & coords );
QRect coords( int const level ) const;
qint64 tilesCount() const;
More information about the Marble-commits
mailing list