|
| 1 | +/*************************************************************************** |
| 2 | + testqgs3dutils.cpp |
| 3 | + ---------------------- |
| 4 | + Date : November 2017 |
| 5 | + Copyright : (C) 2017 by Martin Dobias |
| 6 | + Email : wonder dot sk at gmail dot com |
| 7 | + *************************************************************************** |
| 8 | + * * |
| 9 | + * This program is free software; you can redistribute it and/or modify * |
| 10 | + * it under the terms of the GNU General Public License as published by * |
| 11 | + * the Free Software Foundation; either version 2 of the License, or * |
| 12 | + * (at your option) any later version. * |
| 13 | + * * |
| 14 | + ***************************************************************************/ |
| 15 | + |
| 16 | +#include "qgstest.h" |
| 17 | + |
| 18 | +#include "qgs3dutils.h" |
| 19 | + |
| 20 | + |
| 21 | +/** |
| 22 | + * \ingroup UnitTests |
| 23 | + * This is a unit test for the node tool |
| 24 | + */ |
| 25 | +class TestQgs3DUtils : public QObject |
| 26 | +{ |
| 27 | + Q_OBJECT |
| 28 | + public: |
| 29 | + TestQgs3DUtils() = default; |
| 30 | + |
| 31 | + private slots: |
| 32 | + void initTestCase();// will be called before the first testfunction is executed. |
| 33 | + void cleanupTestCase();// will be called after the last testfunction was executed. |
| 34 | + |
| 35 | + void testTransforms(); |
| 36 | + |
| 37 | + private: |
| 38 | +}; |
| 39 | + |
| 40 | +//runs before all tests |
| 41 | +void TestQgs3DUtils::initTestCase() |
| 42 | +{ |
| 43 | +} |
| 44 | + |
| 45 | +//runs after all tests |
| 46 | +void TestQgs3DUtils::cleanupTestCase() |
| 47 | +{ |
| 48 | +} |
| 49 | + |
| 50 | +void TestQgs3DUtils::testTransforms() |
| 51 | +{ |
| 52 | + QgsVector3D map123( 1, 2, 3 ); |
| 53 | + |
| 54 | + QgsVector3D world123 = Qgs3DUtils::mapToWorldCoordinates( map123, QgsVector3D() ); |
| 55 | + QCOMPARE( world123, QgsVector3D( 1, 3, -2 ) ); |
| 56 | + |
| 57 | + QgsVector3D world123map = Qgs3DUtils::worldToMapCoordinates( world123, QgsVector3D() ); |
| 58 | + QCOMPARE( world123map, map123 ); |
| 59 | + |
| 60 | + // now with non-zero origin |
| 61 | + |
| 62 | + QgsVector3D origin( -10, -20, -30 ); |
| 63 | + |
| 64 | + QgsVector3D world123x = Qgs3DUtils::mapToWorldCoordinates( map123, origin ); |
| 65 | + QCOMPARE( world123x, QgsVector3D( 11, 33, -22 ) ); |
| 66 | + |
| 67 | + QgsVector3D world123xmap = Qgs3DUtils::worldToMapCoordinates( world123x, origin ); |
| 68 | + QCOMPARE( world123xmap, map123 ); |
| 69 | + |
| 70 | + // |
| 71 | + // transform world point from one system to another |
| 72 | + // |
| 73 | + |
| 74 | + QgsVector3D worldPoint1( 5, 7, -6 ); |
| 75 | + QgsVector3D origin1( 10, 20, 30 ); |
| 76 | + QgsVector3D origin2( 1, 2, 3 ); |
| 77 | + QgsVector3D worldPoint2 = Qgs3DUtils::transformWorldCoordinates( worldPoint1, origin1, QgsCoordinateReferenceSystem(), origin2, QgsCoordinateReferenceSystem() ); |
| 78 | + QCOMPARE( worldPoint2, QgsVector3D( 14, 34, -24 ) ); |
| 79 | + // verify that both are the same map point |
| 80 | + QgsVector3D mapPoint1 = Qgs3DUtils::worldToMapCoordinates( worldPoint1, origin1 ); |
| 81 | + QgsVector3D mapPoint2 = Qgs3DUtils::worldToMapCoordinates( worldPoint2, origin2 ); |
| 82 | + QCOMPARE( mapPoint1, mapPoint2 ); |
| 83 | +} |
| 84 | + |
| 85 | +QGSTEST_MAIN( TestQgs3DUtils ) |
| 86 | +#include "testqgs3dutils.moc" |
0 commit comments