<commit_before>#include "SimpleMapImage.h"

#include "InterpolationMethod.h"

#include <cmath>

SimpleMapImage::SimpleMapImage( QString const & fileName )
    : m_image( fileName ),
      m_mapWidthPixel( m_image.width() ),
      m_mapHeightPixel( m_image.height() )
{
    if ( m_image.isNull() )
        qFatal( "Invalid image '%s'", fileName.toStdString().c_str() );
}

QRgb SimpleMapImage::pixel( double const lonRad,  double const latRad )
{
    double const x = lonRadToPixelX( lonRad );
    double const y = latRadToPixelY( latRad );
    return m_interpolationMethod->interpolate( x, y );
}

QRgb SimpleMapImage::pixel( int const x, int const y )
{
    return m_image.pixel( x, m_mapHeightPixel - y );
}

void SimpleMapImage::setInterpolationMethod( InterpolationMethod * const interpolationMethod )
{
    m_interpolationMethod = interpolationMethod;
    m_interpolationMethod->setMapImage( this );
}

inline double SimpleMapImage::lonRadToPixelX( double const lonRad ) const
{
    return static_cast<double>( m_mapWidthPixel ) / ( 2.0 * M_PI ) * lonRad
            + 0.5 * static_cast<double>( m_mapWidthPixel );
}

inline double SimpleMapImage::latRadToPixelY( double const latRad ) const
{
    return static_cast<double>( m_mapHeightPixel ) / M_PI * latRad
            + 0.5 * static_cast<double>( m_mapHeightPixel );
}
<commit_msg>mapreproject: Fix invalid arguments for QImage::pixel.<commit_after>#include "SimpleMapImage.h"

#include "InterpolationMethod.h"

#include <cmath>

SimpleMapImage::SimpleMapImage( QString const & fileName )
    : m_image( fileName ),
      m_mapWidthPixel( m_image.width() ),
      m_mapHeightPixel( m_image.height() )
{
    if ( m_image.isNull() )
        qFatal( "Invalid image '%s'", fileName.toStdString().c_str() );
}

QRgb SimpleMapImage::pixel( double const lonRad,  double const latRad )
{
    double const x = lonRadToPixelX( lonRad );
    double const y = latRadToPixelY( latRad );
    return m_interpolationMethod->interpolate( x, y );
}

QRgb SimpleMapImage::pixel( int const x, int const y )
{
    return m_image.pixel( x, m_mapHeightPixel - y - 1 );
}

void SimpleMapImage::setInterpolationMethod( InterpolationMethod * const interpolationMethod )
{
    m_interpolationMethod = interpolationMethod;
    m_interpolationMethod->setMapImage( this );
}

inline double SimpleMapImage::lonRadToPixelX( double const lonRad ) const
{
    return static_cast<double>( m_mapWidthPixel ) / ( 2.0 * M_PI ) * lonRad
            + 0.5 * static_cast<double>( m_mapWidthPixel );
}

inline double SimpleMapImage::latRadToPixelY( double const latRad ) const
{
    return static_cast<double>( m_mapHeightPixel ) / M_PI * latRad
            + 0.5 * static_cast<double>( m_mapHeightPixel );
}

{'fraction_non_alphanumeric': 0.11037770443711038, 'fraction_numerical': 0.004767143381004767, 'mean_word_length': 4.186311787072244, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3383620', 'n_tokens_mistral': 885, 'n_tokens_neox': 887, 'n_words': 202}