@@ -34,36 +34,56 @@ class TestQgsClipper: public QObject
34
34
void init () {};// will be called before each testfunction is executed.
35
35
void cleanup () {};// will be called after every testfunction.
36
36
void basic ();
37
+ private:
38
+ bool TestQgsClipper::checkBoundingBox ( QPolygonF polygon, QgsRectangle clipRect );
37
39
};
38
40
39
41
void TestQgsClipper::initTestCase ()
40
42
{
41
- //
42
- // Runs once before any tests are run
43
- //
44
- // init QGIS's paths - true means that all path will be inited from prefix
45
- // QgsApplication::init();
46
- // QgsApplication::initQgis();
47
- // QgsApplication::showSettings();
43
+
48
44
}
49
45
50
46
void TestQgsClipper::basic ()
51
47
{
52
- // CQgsClipper is static only
53
- // QgsClipper snipsnip;
48
+ // QgsClipper is static only
54
49
55
50
QPolygonF polygon;
56
- polygon << QPointF (10.4 , 20.5 ) << QPointF (20.2 , 30.2 );
57
-
58
- QgsRectangle clipRect (10 , 10 , 25 , 30 );
59
-
51
+ polygon << QPointF ( 10.4 , 20.5 ) << QPointF ( 20.2 , 30.2 );
52
+
53
+ QgsRectangle clipRect ( 10 , 10 , 25 , 30 );
54
+
60
55
QgsClipper::trimPolygon ( polygon, clipRect );
61
-
62
- QRectF bBox ( polygon.boundingRect () );
63
- QgsRectangle boundingRect ( bBox.bottomLeft ().x (), bBox.bottomLeft ().y (), bBox.topRight ().x (), bBox.topRight ().y () );
64
56
65
- QVERIFY ( clipRect.contains ( boundingRect ) );
57
+ // Check nothing sticks out.
58
+ QVERIFY ( checkBoundingBox ( polygon , clipRect ) );
59
+ // Check that it didn't clip too much
60
+ QgsRectangle clipRectInner ( clipRect );
61
+ clipRectInner.scale ( 0.999 );
62
+ QVERIFY ( ! checkBoundingBox ( polygon , clipRectInner ) );
63
+
64
+ // A more complex example
65
+ polygon.clear ();
66
+ polygon << QPointF ( 1.0 , 9.0 ) << QPointF ( 11.0 , 11.0 ) << QPointF ( 9.0 , 1.0 );
67
+ clipRect.set ( 0.0 , 0.0 , 10.0 , 10.0 );
68
+
69
+ QgsClipper::trimPolygon ( polygon, clipRect );
70
+
71
+ // We should have 5 vertices now?
72
+ QCOMPARE ( polygon.size (), 5 );
73
+ // Check nothing sticks out.
74
+ QVERIFY ( checkBoundingBox ( polygon , clipRect ) );
75
+ // Check that it didn't clip too much
76
+ clipRectInner = clipRect;
77
+ clipRectInner.scale ( 0.999 );
78
+ QVERIFY ( ! checkBoundingBox ( polygon , clipRectInner ) );
66
79
};
67
80
81
+ bool TestQgsClipper::checkBoundingBox ( QPolygonF polygon, QgsRectangle clipRect )
82
+ {
83
+ QgsRectangle bBox ( polygon.boundingRect () );
84
+
85
+ return clipRect.contains ( bBox );
86
+ }
87
+
68
88
QTEST_MAIN ( TestQgsClipper )
69
89
#include " moc_testqgsclipper.cxx"
0 commit comments