<commit_before>//
// This file is part of the Marble Virtual Globe.
//
// This program is free software licensed under the GNU LGPL. You can
// find a copy of this license in LICENSE.txt in the top directory of
// the source code.
//
// Copyright 2013      <NAME>  <<EMAIL>>
//

// Local
#include "GnomonicProjection.h"
#include "AbstractProjection_p.h"

#include "MarbleDebug.h"

// Marble
#include "ViewportParams.h"
#include "GeoDataPoint.h"
#include "GeoDataLineString.h"
#include "GeoDataCoordinates.h"
#include "MarbleGlobal.h"
#include "AzimuthalProjection_p.h"

#include <qmath.h>

#define SAFE_DISTANCE

namespace Marble
{

class GnomonicProjectionPrivate : public AzimuthalProjectionPrivate
{
  public:
    explicit GnomonicProjectionPrivate( GnomonicProjection * parent );

    Q_DECLARE_PUBLIC( GnomonicProjection )
};

GnomonicProjection::GnomonicProjection()
    : AzimuthalProjection( new GnomonicProjectionPrivate( this ) )
{
    setMinLat( minValidLat() );
    setMaxLat( maxValidLat() );
}

GnomonicProjection::GnomonicProjection( GnomonicProjectionPrivate *dd )
        : AzimuthalProjection( dd )
{
    setMinLat( minValidLat() );
    setMaxLat( maxValidLat() );
}

GnomonicProjection::~GnomonicProjection()
{
}


GnomonicProjectionPrivate::GnomonicProjectionPrivate( GnomonicProjection * parent )
        : AzimuthalProjectionPrivate( parent )
{
}

QString GnomonicProjection::name() const
{
    return QObject::tr( "Gnomonic" );
}

QString GnomonicProjection::description() const
{
    return QObject::tr( "<p><b>Gnomonic Projection</b> (\"rectilinear\")</p><p>Applications: Used for displaying panorama photography. Also used for navigation, radio and seismic work.</p>" );
}

QIcon GnomonicProjection::icon() const
{
    return QIcon(":/icons/map-gnomonic.png");
}

qreal GnomonicProjection::clippingRadius() const
{
    return 1;
}

bool GnomonicProjection::screenCoordinates( const GeoDataCoordinates &coordinates,
                                             const ViewportParams *viewport,
                                             qreal &x, qreal &y, bool &globeHidesPoint ) const
{
    const qreal lambda = coordinates.longitude();
    const qreal phi = coordinates.latitude();
    const qreal lambdaPrime = viewport->centerLongitude();
    const qreal phi1 = viewport->centerLatitude();

    qreal cosC = qSin( phi1 ) * qSin( phi ) + qCos( phi1 ) * qCos( phi ) * qCos( lambda - lambdaPrime );

    // Prevent division by zero
    if (fabs(cosC) < 0.0001) {
        cosC = 0.0001;
    }

    // Let (x, y) be the position on the screen of the placemark..
    x = ( qCos( phi ) * qSin( lambda - lambdaPrime ) ) / cosC;
    y = ( qCos( phi1 ) * qSin( phi ) - qSin( phi1 ) * qCos( phi ) * qCos( lambda - lambdaPrime ) ) / cosC;

    x *= viewport->radius() / 2;
    y *= viewport->radius() / 2;

    const qint64  radius  = clippingRadius() * viewport->radius();

    if (x*x + y*y > radius * radius) {
        globeHidesPoint = true;
        return false;
    }

    globeHidesPoint = false;

    x += viewport->width() / 2;<commit_msg>Fix Gnomonic projection criterion for points on the lower hemisphere.<commit_after>//
// This file is part of the Marble Virtual Globe.
//
// This program is free software licensed under the GNU LGPL. You can
// find a copy of this license in LICENSE.txt in the top directory of
// the source code.
//
// Copyright 2013      <NAME>  <<EMAIL>>
//

// Local
#include "GnomonicProjection.h"
#include "AbstractProjection_p.h"

#include "MarbleDebug.h"

// Marble
#include "ViewportParams.h"
#include "GeoDataPoint.h"
#include "GeoDataLineString.h"
#include "GeoDataCoordinates.h"
#include "MarbleGlobal.h"
#include "AzimuthalProjection_p.h"

#include <qmath.h>

#define SAFE_DISTANCE

namespace Marble
{

class GnomonicProjectionPrivate : public AzimuthalProjectionPrivate
{
  public:
    explicit GnomonicProjectionPrivate( GnomonicProjection * parent );

    Q_DECLARE_PUBLIC( GnomonicProjection )
};

GnomonicProjection::GnomonicProjection()
    : AzimuthalProjection( new GnomonicProjectionPrivate( this ) )
{
    setMinLat( minValidLat() );
    setMaxLat( maxValidLat() );
}

GnomonicProjection::GnomonicProjection( GnomonicProjectionPrivate *dd )
        : AzimuthalProjection( dd )
{
    setMinLat( minValidLat() );
    setMaxLat( maxValidLat() );
}

GnomonicProjection::~GnomonicProjection()
{
}


GnomonicProjectionPrivate::GnomonicProjectionPrivate( GnomonicProjection * parent )
        : AzimuthalProjectionPrivate( parent )
{
}

QString GnomonicProjection::name() const
{
    return QObject::tr( "Gnomonic" );
}

QString GnomonicProjection::description() const
{
    return QObject::tr( "<p><b>Gnomonic Projection</b> (\"rectilinear\")</p><p>Applications: Used for displaying panorama photography. Also used for navigation, radio and seismic work.</p>" );
}

QIcon GnomonicProjection::icon() const
{
    return QIcon(":/icons/map-gnomonic.png");
}

qreal GnomonicProjection::clippingRadius() const
{
    return 1;
}

bool GnomonicProjection::screenCoordinates( const GeoDataCoordinates &coordinates,
                                             const ViewportParams *viewport,
                                             qreal &x, qreal &y, bool &globeHidesPoint ) const
{
    const qreal lambda = coordinates.longitude();
    const qreal phi = coordinates.latitude();
    const qreal lambdaPrime = viewport->centerLongitude();
    const qreal phi1 = viewport->centerLatitude();

    qreal cosC = qSin( phi1 ) * qSin( phi ) + qCos( phi1 ) * qCos( phi ) * qCos( lambda - lambdaPrime );

    if ( cosC <= 0) {
        globeHidesPoint = true;
        return false;
    }

    // Let (x, y) be the position on the screen of the placemark..
    x = ( qCos( phi ) * qSin( lambda - lambdaPrime ) ) / cosC;
    y = ( qCos( phi1 ) * qSin( phi ) - qSin( phi1 ) * qCos( phi ) * qCos( lambda - lambdaPrime ) ) / cosC;

    x *= viewport->radius() / 2;
    y *= viewport->radius() / 2;

    const qint64  radius  = clippingRadius() * viewport->radius();

    if (x*x + y*y > radius * radius) {
        globeHidesPoint = true;
        return false;
    }

    globeHidesPoint = false;

    x += viewport->width() / 2;
{'fraction_non_alphanumeric': 0.11957928802588996, 'fraction_numerical': 0.006634304207119741, 'mean_word_length': 3.3133286810886253, 'pattern_counts': {'":': 2, '<': 25, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5520194', 'n_tokens_mistral': 2118, 'n_tokens_neox': 2009, 'n_words': 506}