예제 #1
0
void MercatorProjectionTest::setInvalidRadius()
{
    ViewportParams viewport;
    viewport.setProjection( Mercator );
    viewport.setRadius( 0 );
    qreal lon, lat;
    viewport.geoCoordinates( 23, 42, lon, lat );
}
예제 #2
0
bool AbstractGeoPolygonGraphicsItem::configurePainter(GeoPainter *painter, const ViewportParams &viewport) const
{
    QPen currentPen = painter->pen();
    GeoDataStyle::ConstPtr style = this->style();
    if (!style) {
        painter->setPen( QPen() ); // "style-less" polygons: a 1px black solid line
    }
    else {
        const GeoDataPolyStyle& polyStyle = style->polyStyle();

        if (polyStyle.outline()) {
            const GeoDataLineStyle& lineStyle = style->lineStyle();

            // To save performance we avoid making changes to the painter's pen.
            // So we first take a copy of the actual painter pen, make changes to it
            // and only if the resulting pen is different from the actual pen
            // we replace the painter's pen with our new pen.

            // We want to avoid the mandatory detach in QPen::setColor(),
            // so we carefully check whether applying the setter is needed
            currentPen.setColor(lineStyle.paintedColor());
            currentPen.setWidthF(lineStyle.width());
            currentPen.setCapStyle(lineStyle.capStyle());
            currentPen.setStyle(lineStyle.penStyle());

            if (painter->pen().color() != currentPen.color()) {
                painter->setPen(currentPen);
            }
        }
        else {
            // polygons without outline: Qt::NoPen (not drawn)
            if (currentPen.style() != Qt::NoPen) {
                painter->setPen(Qt::NoPen);
            }
        }

        if (!polyStyle.fill()) {            
            painter->setBrush(Qt::transparent);
        }
        else {
            const QColor paintedColor = polyStyle.paintedColor();
            if (painter->brush().color() != paintedColor ||
                painter->brush().style() != polyStyle.brushStyle()) {
                if (!polyStyle.texturePath().isEmpty() || !polyStyle.textureImage().isNull()) {
                    GeoDataCoordinates coords = latLonAltBox().center();
                    qreal x, y;
                    viewport.screenCoordinates(coords, x, y);
                    QBrush brush(texture(polyStyle.texturePath(), paintedColor));
                    painter->setBrush(brush);
                    painter->setBrushOrigin(QPoint(x,y));
                }
                else {
                    painter->setBrush(QBrush(paintedColor, polyStyle.brushStyle()));
                }
            }
        }
    }

    return true;
}
예제 #3
0
void MercatorProjectionTest::screenCoordinatesValidLat()
{
    QFETCH( qreal, lon );
    QFETCH( qreal, lat );
    QFETCH( bool, validLat );

    const GeoDataCoordinates coordinates( lon, lat, 0, GeoDataCoordinates::Degree );

    ViewportParams viewport;
    viewport.setProjection( Mercator );
    viewport.setRadius( 360 / 4 ); // for easy mapping of lon <-> x
    viewport.centerOn( 0.0, 0.0 );
    viewport.setSize( QSize( 360, 361 ) ); // TODO: check why height == 360 doesn't hold

    {
        qreal x;
        qreal y;

        const bool retval = viewport.screenCoordinates( lon * DEG2RAD, lat * DEG2RAD, x, y );

        QVERIFY( retval == validLat );
    }

    {
        qreal x;
        qreal y;
        bool globeHidesPoint = true;

        const bool retval = viewport.screenCoordinates( coordinates, x, y, globeHidesPoint );

        QVERIFY( retval == validLat );
        QVERIFY( !globeHidesPoint );
    }

    QVERIFY( viewport.currentProjection()->repeatableX() );

    {
        qreal x[2];
        qreal y;
        int pointRepeatNum = 1000;
        bool globeHidesPoint = true;

        const bool retval = viewport.screenCoordinates( coordinates, x, y, pointRepeatNum, QSizeF( 0, 0 ), globeHidesPoint );

        QVERIFY( retval == validLat );
        QCOMPARE( pointRepeatNum, 1 );
        QVERIFY( !globeHidesPoint );
    }
}
예제 #4
0
void MercatorProjectionTest::screenCoordinatesOfCenter_data()
{
    ViewportParams mercator;
    mercator.setProjection( Mercator );

    QTest::addColumn<qreal>( "lon" );
    QTest::addColumn<qreal>( "lat" );

    addRow() << 0.0 << 0.0;

    addRow() << -180.0 << 0.0;
    addRow() <<  180.0 << 0.0;

    addRow() << -360.0 << 0.0;
    addRow() <<  360.0 << 0.0;

    addRow() << -540.0 << 0.0;
    addRow() <<  540.0 << 0.0;

    addRow() << 0.0 << mercator.currentProjection()->minValidLat() * RAD2DEG;
    addRow() << 0.0 << mercator.currentProjection()->maxValidLat() * RAD2DEG;

    addRow() << -180.0 << mercator.currentProjection()->minValidLat() * RAD2DEG;
    addRow() << -180.0 << mercator.currentProjection()->maxValidLat() * RAD2DEG;

    addRow() <<  180.0 << mercator.currentProjection()->minValidLat() * RAD2DEG;
    addRow() <<  180.0 << mercator.currentProjection()->maxValidLat() * RAD2DEG;

    // FIXME: the following tests should succeed
#if 0
    addRow() << -541.0 << 0.0;
    addRow() <<  541.0 << 0.0;

    addRow() << -1000000.0 << 0.0;
    addRow() <<  1000000.0 << 0.0;
#endif
}
예제 #5
0
void StereographicProjectionTest::screenCoordinatesOfCenter()
{
    QFETCH( QPoint, screenCoordinates );
    QFETCH( GeoDataCoordinates, expected );

    ViewportParams viewport;
    viewport.setProjection( Stereographic );
    viewport.setRadius( 180 / 4 ); // for easy mapping of lon <-> x
    viewport.setSize( QSize( 20, 20 ) );
    viewport.centerOn( 0 * DEG2RAD, 90 * DEG2RAD );

    {
        qreal lon, lat;
        const bool retval = viewport.geoCoordinates( screenCoordinates.x(), screenCoordinates.y(), lon, lat, GeoDataCoordinates::Degree );

        QVERIFY( retval ); // we want valid coordinates
        QFUZZYCOMPARE( lon, expected.longitude( GeoDataCoordinates::Degree ), 0.0001  );
        QFUZZYCOMPARE( lat, expected.latitude( GeoDataCoordinates::Degree ), 0.0001  );
    }
}
예제 #6
0
void MercatorProjectionTest::screenCoordinatesOfCenter()
{
    QFETCH( qreal, lon );
    QFETCH( qreal, lat );

    const GeoDataCoordinates coordinates( lon, lat, 0, GeoDataCoordinates::Degree );

    ViewportParams viewport;
    viewport.setProjection( Mercator );
    viewport.setRadius( 360 / 4 ); // for easy mapping of lon <-> x
    viewport.setSize( QSize( 2, 2 ) );
    viewport.centerOn( lon * DEG2RAD, lat * DEG2RAD );

    {
        qreal x;
        qreal y;

        const bool retval = viewport.screenCoordinates( lon * DEG2RAD, lat * DEG2RAD, x, y );

        QVERIFY( retval ); // FIXME: this should fail for lon < -180 || 180 < lon
        QCOMPARE( x, lon - viewport.centerLongitude() * RAD2DEG + 1.0 );
        QCOMPARE( y, 1.0 );
    }

    {
        qreal x;
        qreal y;
        bool globeHidesPoint = true;

        const bool retval = viewport.screenCoordinates( coordinates, x, y, globeHidesPoint );

        QVERIFY( retval ); // FIXME: this should fail for lon < -180 || 180 < lon
        QVERIFY( !globeHidesPoint );
        QCOMPARE( x, lon - viewport.centerLongitude() * RAD2DEG + 1.0 );
        QCOMPARE( y, 1.0 );
    }

    QVERIFY( viewport.currentProjection()->repeatableX() );

    {
        qreal x[2];
        qreal y;
        int pointRepeatNum = 1000;
        bool globeHidesPoint = true;

        const bool retval = viewport.screenCoordinates( coordinates, x, y, pointRepeatNum, QSizeF( 0, 0 ), globeHidesPoint );

        QVERIFY( retval );
        QCOMPARE( pointRepeatNum, 1 );
        QVERIFY( !globeHidesPoint );
        QCOMPARE( x[0], 1.0 );
        QCOMPARE( y, 1.0 );
    }
}