<commit_before>//
// This file is part of the Marble Desktop 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 2008      <NAME>   <<EMAIL>>
//


#include "GeoDataLineString.h"

#include <QtCore/QDebug>

namespace Marble
{

class GeoDataLineStringPrivate
{
 public:
    GeoDataLineStringPrivate( TessellationFlags f )
         : m_dirtyBox( true ),
           m_tessellationFlags( f )
    {
    }

    bool         m_dirtyBox; // tells whether there have been changes to the
                             // GeoDataPoints since the LatLonAltBox has 
                             // been calculated. Saves performance. 
    TessellationFlags m_tessellationFlags;
};

GeoDataLineString::GeoDataLineString( GeoDataObject *parent, TessellationFlags f )
  : QVector<GeoDataCoordinates*>(),
    GeoDataGeometry( parent ), 
    d( new GeoDataLineStringPrivate( f ) )
{
}

GeoDataLineString::GeoDataLineString( const GeoDataLineString & other )
  : QVector<GeoDataCoordinates*>( other ), GeoDataGeometry( other ),
    d( new GeoDataLineStringPrivate( *other.d ) )
{
}

GeoDataLineString& GeoDataLineString::operator=( const GeoDataLineString & rhs )
{
    // FIXME: check for self assignment is not needed imho, discuss if we
    // check nevertheless.
    *d = *rhs.d;
    return *this;
}

GeoDataLineString::~GeoDataLineString()
{
#ifdef DEBUG_GEODATA
    qDebug() << "delete Linestring";
#endif
    delete d;
//    FIXME: Ownership
//    qDeleteAll(*this);
}

bool GeoDataLineString::isClosed() const
{
    return false;
}

bool GeoDataLineString::tessellate() const
{
    return d->m_tessellationFlags.testFlag(Tessellate);
}

void GeoDataLineString::setTessellate( bool tessellate )
{
    // According to the KML reference the tesselation of line strings in Google Earth 
    // is generally done along great circles. However for subsequent points that share 
    // the same latitude the latitude circles are followed. Our Tesselate and RespectLatitude
    // Flags provide this behaviour. For true polygons the latitude circles don't get considered. 

    if ( tessellate ) {
        d->m_tessellationFlags |= Tessellate; 
        d->m_tessellationFlags |= RespectLatitudeCircle; 
    } else {
        d->m_tessellationFlags ^= Tessellate; 
        d->m_tessellationFlags ^= RespectLatitudeCircle; 
    }
}

TessellationFlags GeoDataLineString::tessellationFlags() const
{
    return d->m_tessellationFlags;
}

void GeoDataLineString::setTessellationFlags( TessellationFlags f )
{
    d->m_tessellationFlags = f;
}

GeoDataLatLonAltBox GeoDataLineString::latLonAltBox() const
{
    if (d->m_dirtyBox) {
        return GeoDataLatLonAltBox::fromLineString( *this );
    }
    d->m_dirtyBox = false;

    return GeoDataLatLonAltBox();
}


void GeoDataLineString::append ( GeoDataCoordinates* value )
{
    d->m_dirtyBox = true;
    QVector<GeoDataCoordinates*>::append( value );
}

void GeoDataLineString::clear()
{
    d->m_dirtyBox = true;
// possible leakage
    QVector<GeoDataCoordinates*>::clear();
}

QVector<GeoDataCoordinates*>::Iterator GeoDataLineString::erase ( QVector<GeoDataCoordinates*>::Iterator pos )
{
    d->m_dirtyBox = true;
    return QVector<GeoDataCoordinates*>::erase( pos );<commit_msg>Fix caching of the LatLonAltBox<commit_after>//
// This file is part of the Marble Desktop 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 2008      <NAME>   <<EMAIL>>
//


#include "GeoDataLineString.h"

#include <QtCore/QDebug>

namespace Marble
{

class GeoDataLineStringPrivate
{
 public:
    GeoDataLineStringPrivate( TessellationFlags f )
         : m_dirtyBox( true ),
           m_tessellationFlags( f ),
           m_latLonAltBox()
    {
    }

    GeoDataLatLonAltBox m_latLonAltBox;

    bool         m_dirtyBox; // tells whether there have been changes to the
                             // GeoDataPoints since the LatLonAltBox has 
                             // been calculated. Saves performance. 
    TessellationFlags m_tessellationFlags;
};

GeoDataLineString::GeoDataLineString( GeoDataObject *parent, TessellationFlags f )
  : QVector<GeoDataCoordinates*>(),
    GeoDataGeometry( parent ), 
    d( new GeoDataLineStringPrivate( f ) )
{
}

GeoDataLineString::GeoDataLineString( const GeoDataLineString & other )
  : QVector<GeoDataCoordinates*>( other ), GeoDataGeometry( other ),
    d( new GeoDataLineStringPrivate( *other.d ) )
{
}

GeoDataLineString& GeoDataLineString::operator=( const GeoDataLineString & rhs )
{
    // FIXME: check for self assignment is not needed imho, discuss if we
    // check nevertheless.
    *d = *rhs.d;
    return *this;
}

GeoDataLineString::~GeoDataLineString()
{
#ifdef DEBUG_GEODATA
    qDebug() << "delete Linestring";
#endif
    delete d;
//    FIXME: Ownership
//    qDeleteAll(*this);
}

bool GeoDataLineString::isClosed() const
{
    return false;
}

bool GeoDataLineString::tessellate() const
{
    return d->m_tessellationFlags.testFlag(Tessellate);
}

void GeoDataLineString::setTessellate( bool tessellate )
{
    // According to the KML reference the tesselation of line strings in Google Earth 
    // is generally done along great circles. However for subsequent points that share 
    // the same latitude the latitude circles are followed. Our Tesselate and RespectLatitude
    // Flags provide this behaviour. For true polygons the latitude circles don't get considered. 

    if ( tessellate ) {
        d->m_tessellationFlags |= Tessellate; 
        d->m_tessellationFlags |= RespectLatitudeCircle; 
    } else {
        d->m_tessellationFlags ^= Tessellate; 
        d->m_tessellationFlags ^= RespectLatitudeCircle; 
    }
}

TessellationFlags GeoDataLineString::tessellationFlags() const
{
    return d->m_tessellationFlags;
}

void GeoDataLineString::setTessellationFlags( TessellationFlags f )
{
    d->m_tessellationFlags = f;
}

GeoDataLatLonAltBox GeoDataLineString::latLonAltBox() const
{
    if (d->m_dirtyBox) {
        d->m_latLonAltBox = GeoDataLatLonAltBox::fromLineString( *this );
        d->m_dirtyBox = false;
    }

    return d->m_latLonAltBox;
}


void GeoDataLineString::append ( GeoDataCoordinates* value )
{
    d->m_dirtyBox = true;
    QVector<GeoDataCoordinates*>::append( value );
}

void GeoDataLineString::clear()
{
    d->m_dirtyBox = true;
// possible leakage
    QVector<GeoDataCoordinates*>::clear();
}

QVector<GeoDataCoordinates*>::Iterator GeoDataLineString::erase ( QVector<GeoDataCoordinates*>::Iterator pos )
{
    d->m_dirtyBox = true;
    return QVector<GeoDataCoordinates*>::erase( pos );
{'fraction_non_alphanumeric': 0.09886547811993517, 'fraction_numerical': 0.0011787240312361867, 'mean_word_length': 3.4864507600793124, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 51, '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': '3942924', 'n_tokens_mistral': 2255, 'n_tokens_neox': 2107, 'n_words': 527}