File: MercatorProjectionTest.cpp

package info (click to toggle)
marble 4%3A25.08.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 159,996 kB
  • sloc: cpp: 191,890; xml: 39,908; ansic: 7,204; python: 2,190; sh: 1,187; makefile: 235; perl: 218; ruby: 97; java: 66
file content (216 lines) | stat: -rw-r--r-- 6,648 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
// SPDX-License-Identifier: LGPL-2.1-or-later
//
// SPDX-FileCopyrightText: 2011 Bernhard Beschow <bbeschow@cs.tu-berlin.de>
//

#include "MercatorProjection.h"
#include "TestUtils.h"
#include "ViewportParams.h"

namespace Marble
{

class MercatorProjectionTest : public QObject
{
    Q_OBJECT

private Q_SLOTS:
    void screenCoordinatesValidLat_data();
    void screenCoordinatesValidLat();

    void screenCoordinatesOfCenter_data();
    void screenCoordinatesOfCenter();

    void setInvalidRadius();
};

void MercatorProjectionTest::screenCoordinatesValidLat_data()
{
    ViewportParams mercator;
    mercator.setProjection(Mercator);

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

    addRow() << qreal(0.0) << qreal(0.0) << true;

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

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

    addRow() << qreal(0.0) << mercator.currentProjection()->minValidLat() * RAD2DEG - qreal(0.0001) << false;
    addRow() << qreal(0.0) << mercator.currentProjection()->maxValidLat() * RAD2DEG + qreal(0.0001) << false;

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

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

    addRow() << qreal(-180.0) << mercator.currentProjection()->minValidLat() * RAD2DEG - qreal(0.0001) << false;
    addRow() << qreal(180.0) << mercator.currentProjection()->minValidLat() * RAD2DEG - qreal(0.0001) << false;

    addRow() << qreal(-180.0) << mercator.currentProjection()->maxValidLat() * RAD2DEG + qreal(0.0001) << false;
    addRow() << qreal(180.0) << mercator.currentProjection()->maxValidLat() * RAD2DEG + qreal(0.0001) << false;
}

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);
    }
}

void MercatorProjectionTest::screenCoordinatesOfCenter_data()
{
    ViewportParams mercator;
    mercator.setProjection(Mercator);

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

    addRow() << qreal(0.0) << qreal(0.0);

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

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

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

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

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

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

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

    addRow() << qreal(-1000000.0) << qreal(0.0);
    addRow() <<  qreal(1000000.0) << qreal(0.0);
#endif
}

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);
    }
}

void MercatorProjectionTest::setInvalidRadius()
{
    ViewportParams viewport;
    viewport.setProjection(Mercator);
    viewport.setRadius(0);
    qreal lon, lat;
    viewport.geoCoordinates(23, 42, lon, lat);
}

}

QTEST_MAIN(Marble::MercatorProjectionTest)

#include "MercatorProjectionTest.moc"