File indexing completed on 2025-01-05 03:59:37
0001 /* 0002 SPDX-FileCopyrightText: 2005-2007 Torsten Rahn <tackat@kde.org> 0003 SPDX-FileCopyrightText: 2007 Inge Wallin <ingwa@kde.org> 0004 SPDX-FileCopyrightText: 2008 Patrick Spendrin <ps_ml@gmx.de> 0005 SPDX-FileCopyrightText: 2008 Jens-Michael Hoffmann <jensmh@gmx.de> 0006 0007 SPDX-License-Identifier: LGPL-2.0-or-later 0008 */ 0009 0010 #include "TileLoaderHelper.h" 0011 0012 #include <cmath> 0013 0014 #include "MarbleGlobal.h" 0015 0016 #include "digikam_debug.h" 0017 0018 namespace Marble 0019 { 0020 0021 int TileLoaderHelper::levelToRow( int levelZeroRows, int level ) 0022 { 0023 if ( level < 0 ) { 0024 qCDebug(DIGIKAM_MARBLE_LOG) << QString::fromUtf8( "TileLoaderHelper::levelToRow(): Invalid level: %1" ) 0025 .arg( level ); 0026 return 0; 0027 } 0028 return levelZeroRows << level; 0029 } 0030 0031 int TileLoaderHelper::levelToColumn( int levelZeroColumns, int level ) 0032 { 0033 if ( level < 0 ) { 0034 qCDebug(DIGIKAM_MARBLE_LOG) << QString::fromUtf8( "TileLoaderHelper::levelToColumn(): Invalid level: %1" ) 0035 .arg( level ); 0036 return 0; 0037 } 0038 return levelZeroColumns << level; 0039 } 0040 0041 int TileLoaderHelper::rowToLevel( int levelZeroRows, int row ) 0042 { 0043 if ( row < levelZeroRows ) { 0044 qCDebug(DIGIKAM_MARBLE_LOG) << QString::fromUtf8( "TileLoaderHelper::rowToLevel(): Invalid number of rows: %1" ) 0045 .arg( row ); 0046 return 0; 0047 } 0048 return (int)( std::log( (qreal)(row / levelZeroRows) ) / std::log( (qreal)2.0 ) ); 0049 } 0050 0051 int TileLoaderHelper::columnToLevel( int levelZeroColumns, int column ) 0052 { 0053 if ( column < levelZeroColumns ) { 0054 qCDebug(DIGIKAM_MARBLE_LOG) << QString::fromUtf8( "TileLoaderHelper::columnToLevel(): Invalid number of columns: %1" ) 0055 .arg( column ); 0056 return 0; 0057 } 0058 return (int)( std::log( (qreal)(column / levelZeroColumns) ) / std::log( (qreal)2.0 ) ); 0059 } 0060 0061 }