Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Add unit test for QgsMapToPixel (legacy only for now)
- Loading branch information
Sandro Santilli
committed
Dec 9, 2014
1 parent
d65a6f7
commit ec085bf
Showing
2 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/*************************************************************************** | ||
testqgsmaptopixel.cpp | ||
-------------------------------------- | ||
Date : Tue 9 Dec 2014 | ||
Copyright : (C) 2014 by Sandro Santilli | ||
Email : strk@keybit.net | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
#include <QtTest/QtTest> | ||
#include <QObject> | ||
#include <QString> | ||
#include <QObject> | ||
//header for class being tested | ||
#include <qgsrectangle.h> | ||
#include <qgsmaptopixel.h> | ||
#include <qgspoint.h> | ||
#include "qgslogger.h" | ||
|
||
class TestQgsMapToPixel: public QObject | ||
{ | ||
Q_OBJECT | ||
private slots: | ||
void legacy(); | ||
}; | ||
|
||
void TestQgsMapToPixel::legacy() | ||
{ | ||
QgsMapToPixel m2p(2,10,-4,3); | ||
|
||
QgsPoint p(0,0); // in geographical units | ||
QgsPoint d = m2p.transform(p); // to device pixels | ||
QCOMPARE( d.x(), -1.5 ); | ||
QCOMPARE( d.y(), 8.0 ); | ||
|
||
QgsPoint b = m2p.toMapCoordinatesF( d.x(), d.y() ); // transform back | ||
QCOMPARE( p, b ); | ||
|
||
m2p.transform(&p); // in place transform | ||
QCOMPARE( p, d ); | ||
|
||
m2p.setParameters(0.2, -10, 7, 20); | ||
p = m2p.toMapCoordinates( -1, -1 ); | ||
QCOMPARE( p.x(), -10.2 ); | ||
QCOMPARE( p.y(), 11.2 ); | ||
d = m2p.transform(p); | ||
QCOMPARE( d, QgsPoint(-1, -1) ); | ||
|
||
p = m2p.toMapCoordinates( 20, 20 ); | ||
QCOMPARE( p.x(), -6.0 ); | ||
QCOMPARE( p.y(), 7.0 ); | ||
d = m2p.transform(p); | ||
QCOMPARE( d, QgsPoint(20, 20) ); | ||
|
||
}; | ||
|
||
QTEST_MAIN( TestQgsMapToPixel ) | ||
#include "testqgsmaptopixel.moc" | ||
|
||
|
||
|
||
|